NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Model Tells You What to Discard: Adaptive KV Cache Compression for LLMs

Suyu Ge, Yunan Zhang, Liyuan Liu, Minjia Zhang, Jiawei Han, Jianfeng Gao

TL;DR

FastGen is a plug-and-play method that slashes the memory footprint of Large Language Models (LLMs) by adaptively compressing the KV cache. By profiling individual attention heads to identify their unique structural roles—such as focusing on local context or special tokens—FastGen achieves up to 55% speedup and significant memory reduction with virtually no loss in generation quality, all without requiring any retraining.

What Problem Does This Paper Address?

As Large Language Models (LLMs) scale, so does the memory required for their KV (Key-Value) cache. This cache is essential for fast, autoregressive generation because it stores previously computed vectors to avoid redundant calculations. However, for long sequences or large models, the KV cache can quickly exceed GPU memory capacity.

When this happens, systems often resort to "offloading" the cache to slower CPU memory or NVMe storage, which creates a massive bottleneck due to limited PCIe bandwidth. Existing solutions to compress this cache often apply a "one-size-fits-all" strategy across all attention heads or require expensive fine-tuning. The authors of this paper sought a way to compress the KV cache efficiently and adaptively, respecting the diverse roles that different parts of the model play.

Methods

The authors introduce FastGen, a dual-phase approach to KV cache management:

  1. Model Profiling (Prompt Encoding Phase): During the initial processing of a prompt, FastGen runs a lightweight profiling algorithm. It analyzes the attention maps of every single head to determine its "intrinsic structure."
  2. Adaptive Compression (Token Generation Phase): Based on the profile, FastGen assigns one of five specialized compression policies to each head:
  3. Special Tokens: Retains only critical markers like <s> or [INST].
  4. Punctuation: Keeps only punctuation marks (e.g., ., ?), which often act as structural anchors.
  5. Locality: Evicts old tokens, keeping only a sliding window of recent context.
  6. Frequency (Heavy Hitter): Keeps tokens that are most frequently attended to across the sequence.
  7. Full Cache: Used for heads that broadly attend to all tokens, preserving their original behavior.

FastGen also uses Hybrid Policies, greedily combining these strategies to maximize compression while meeting a target "recovery ratio" (how much of the original attention map is preserved). Crucially, this is a plug-and-play method; it works on pre-trained models without any additional training or fine-tuning.

Figure 1: Different attention heads usually have different structures. Left: Four common attention structures (more details are elaborated in Section 3 and Section 4). Right: Attention map composi- tions of three attention heads that are in the same layer.

Datasets

The researchers evaluated FastGen using the Llama 1 family (7B to 65B parameters) across several standard benchmarks:

  • GSM8k: Math word problems.
  • HumanEval: Python code generation.
  • NQ (Natural Questions) & TQA (TriviaQA): General knowledge and reading comprehension.
  • AlpacaEval: A benchmark for instruction-following, where GPT-4 is used to judge the quality of model outputs.

For instruction-following tests, they fine-tuned Llama 1 on the LIMA and OpenAssistant (oasst1) datasets.

Key Insights and Ideas

  • Attention Heterogeneity: Not all attention heads are created equal. Some are "local experts," while others act as "global aggregators." Applying the same eviction policy to all of them is fundamentally suboptimal.
  • Structural Stability: A key "aha moment" was discovering that the attention structure of a head remains remarkably stable throughout the decoding process for a given sequence. This allows for efficient, one-shot profiling during the prompt encoding phase.
  • The Power of Special Tokens: Special tokens often capture a disproportionately large amount of attention. Keeping just a handful of these tokens in the cache provides massive benefits for very little memory cost.
  • Layer-wise Specialization: Profiling revealed that initial and final layers of the model typically require a full KV cache, while middle layers are much more amenable to aggressive compression focusing on special tokens or local context.

Key Results

FastGen demonstrates a superior trade-off between memory savings and model performance compared to fixed-policy baselines.

  • Memory Efficiency: FastGen achieved ~40% memory reduction in Llama-65B and ~30% in Llama-30B with negligible quality loss (maintaining a win-rate >45% against the uncompressed model).
  • Superiority over Fixed Baselines: In AlpacaEval tests, a 50% compressed FastGen 30B model outperformed all fixed compression methods even when they were only compressed by 15%.
  • Latency Speedup: The method provides significant end-to-end speedups, reaching up to 55% reduction in latency for long sequences (16k tokens) compared to standard Hugging Face implementations.
  • Minimal Overhead: The profiling step is extremely lightweight, typically accounting for less than 0.35% of the total generation time.
Figure 2: Performance of Adaptive KV Cache (FastGen) and Fixed KV Cache (Frequency, Local, and Frequency+Local; Zhang et al., 2023 and Liu et al., 2023a) on AlpacaEval.

Limitations and Future Work

While highly effective, the authors note a few areas for further exploration:

  • Grouped-Query Attention (GQA): This study focused on standard Multi-Head Attention. Adapting FastGen for GQA (used in Llama 2 and newer models) is a planned next step.
  • Kernel Optimization: While they developed a custom CUDA kernel, further low-level optimization could yield even greater speedups, potentially matching the performance of highly specialized systems like DeepSpeed.
  • Synergy with Other Methods: The authors suggest that FastGen could be combined with other compression techniques like quantization or distillation for even more extreme efficiency gains.

Summary updated

BibTeX
@inproceedings{ge2024model,
  author = {Suyu Ge and Yunan Zhang and Liyuan Liu and Minjia Zhang and Jiawei Han and Jianfeng Gao},
  title = {{Model Tells You What to Discard: Adaptive KV Cache Compression for LLMs}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=uNrFpDPMyo},
}
Figure