No Token Left Behind: Reliable KV Cache Compression via Importance-Aware Mixed Precision Quantization

June Yong Yang, Byeongwook Kim, Jeongin Bae, Beomseok Kwon, Gunho Park, Eunho Yang, Se Jung Kwon, Dongsoo LeearXiv 2024

Abstract

Key-Value (KV) Caching has become an essential technique for accelerating the inference speed and throughput of generative Large Language Models (LLMs). However, the memory footprint of the KV cache poses a critical bottleneck in LLM deployment as the cache size grows with batch size and sequence length, often surpassing even the size of the model itself. Although recent methods were proposed to select and evict unimportant KV pairs from the cache to reduce memory consumption, the potential ramifications of eviction on the generative process are yet to be thoroughly examined. In this paper, we examine the detrimental impact of cache eviction and observe that unforeseen risks arise as the information contained in the KV pairs is exhaustively discarded, resulting in safety breaches, hallucinations, and context loss. Surprisingly, we find that preserving even a small amount of information contained in the evicted KV pairs via reduced precision quantization substantially recovers the incurred degradation. On the other hand, we observe that the important KV pairs must be kept at a relatively higher precision to safeguard the generation quality. Motivated by these observations, we propose Mixed-precision KV cache (MiKV), a reliable cache compression method that simultaneously preserves the context details by retaining the evicted KV pairs in low-precision and ensure generation quality by keeping the important KV pairs in high-precision. Experiments on diverse benchmarks and LLM backbones show that our proposed method offers a state-of-the-art trade-off between compression ratio and performance, compared to other baselines.

Introduction

Generative Large Language Models (LLMs) rely on Key-Value (KV) caching to maintain high inference speeds by storing representations of previous tokens. However, this cache scales linearly with sequence length, creating a "memory wall" that restricts long-context applications. Existing solutions like Heavy-Hitter Oracle (H2O) attempt to mitigate this by evicting "unimportant" tokens. This paper identifies critical side effects of such total information loss: safety breaches, contextual incoherency, and hallucinations.

The Risks of Cache Eviction

When tokens are completely removed from the cache, the model loses access to specific parts of the context. This is particularly dangerous when system prompts or safety instructions—often located at the beginning of a sequence—are evicted.

Comparison of safety performance between KV cache eviction and MiKV retention.

As illustrated above, an eviction-based strategy can inadvertently delete safety constraints, leading to a compromise in model behavior. In contrast, MiKV retains this information in low precision, keeping the safety guardrails intact. Furthermore, eviction can lead to factual hallucinations. If the model evicts specific details while retaining the general topic, it may generate plausible-sounding but incorrect information to fill the gaps.

Example of hallucination and context loss caused by cache eviction.

Methodology: Mixed-precision KV Cache (MiKV)

The proposed MiKV method operates on the principle of "No Token Left Behind." Instead of binary eviction, it employs a mixed-precision strategy:

  1. Heavy Hitters: A small subset of tokens with high attention scores are maintained in high precision (e.g., FP16 or INT8) to ensure generation quality.
  2. Retained Tokens: Tokens that would typically be evicted are instead compressed into ultra-low precision (INT2).

To maintain accuracy at 2-bit precision, MiKV addresses the challenge of numerical outliers by implementing a "channel balancer" during the prefill phase. This shifts the numerical burden of outliers from the Keys (which are being compressed) to the Queries (which remain in high precision).

Experimental Results

The researchers evaluated MiKV using Llama-2 and Mistral-7B models across several benchmarks, including MMLU, GSM8k, and HumanEval.

  • Compression Efficiency: MiKV achieves an 80% reduction in KV cache size with negligible performance degradation on general benchmarks like MMLU.
  • Context Retrieval: In "needle in a haystack" tasks (Line Retrieval), MiKV maintained 92.6% accuracy at 20% cache capacity, whereas eviction-based baselines like H2O dropped to 4%.
  • Memory Savings: For a Llama-2-70B model with a 4k context, memory usage was reduced from 17.18GB to 3.44GB.

Conclusion

MiKV demonstrates that preserving even minimal "residual" information from supposedly unimportant tokens is far superior to discarding them entirely. By combining importance-aware selection with mixed-precision quantization, MiKV provides a robust path for deploying LLMs in memory-constrained environments without sacrificing safety or contextual integrity.

Summary updated

BibTeX
@misc{yang2024no,
  author = {June Yong Yang and Byeongwook Kim and Jeongin Bae and Beomseok Kwon and Gunho Park and Eunho Yang and Se Jung Kwon and Dongsoo Lee},
  title = {{No Token Left Behind: Reliable KV Cache Compression via Importance-Aware Mixed Precision Quantization}},
  year = {2024},
  eprint = {2402.18096},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.18096},
}
Figure