Unifying KV Cache Compression for Large Language Models with LeanKV

Yanqi Zhang, Yuwei Hu, Runyuan Zhao, John C. S. Lui, Haibo Chen

Abstract

As Large Language Models (LLMs) evolve toward longer context windows and complex reasoning chains, the Key-Value (KV) cache has emerged as a critical memory bottleneck, often consuming over 90% of GPU memory. This paper introduces DiffKV, a framework that achieves up to 5.7x memory compression by applying differentiated quantization and pruning. Unlike traditional "one-size-fits-all" methods, DiffKV leverages the varying sensitivity of keys versus values and the non-uniform importance of tokens across attention heads. Combined with a specialized on-GPU parallel memory manager, DiffKV improves end-to-end throughput by up to 5.4x while maintaining near-lossless accuracy.

The KV Cache Bottleneck

The KV cache is essential for efficient LLM inference, storing intermediate tensors to prevent redundant computations. However, its size grows linearly with sequence length and batch size. In modern "thinking" models like DeepSeek-R1 or OpenAI’s o1, which generate extensive chains of thought, the KV cache quickly exhausts available GPU memory. Existing compression techniques, such as uniform pruning or quantization, often face a trade-off: aggressive compression degrades model accuracy, while conservative compression fails to alleviate memory pressure. Furthermore, irregular compression patterns typically lead to memory fragmentation, hindering GPU performance.

Differentiated Compression Strategy

DiffKV addresses these challenges through a multi-level differentiated approach. It recognizes that not all components of the KV cache are equally vital for model performance.

Comparison of traditional pruning and quantization versus the differentiated approach of DiffKV.
  1. Differentiated Keys and Values: Keys are used to compute attention scores, making them highly sensitive to precision loss. Values, which are aggregated based on these scores, are more robust. DiffKV assigns higher precision (e.g., 8-bit) to keys and lower precision (e.g., 4-bit) to values.
  2. Token Importance Differentiation: DiffKV employs a hierarchical strategy where critical tokens are kept at high precision, moderately important tokens at low precision, and insignificant tokens are pruned.
  3. Dynamic Per-Head Sparsity: Since attention patterns vary across heads, DiffKV dynamically adjusts the number of tokens retained for each head, optimizing the "bit budget" where it matters most.

Theoretical Foundation: Key vs. Value Sensitivity

The decision to prioritize key precision is grounded in the numerical behavior of the attention mechanism. Analysis shows that attention scores (driven by keys) can span seven orders of magnitude, whereas value norms typically span only two. This disparity means that even small errors in key quantization can drastically alter the attention distribution, whereas values are more forgiving.

Cumulative Distribution Function (CDF) of attention scores and value norms across different layers of Llama3-8B, highlighting the higher sensitivity of attention scores.

Parallel KV Compaction

To handle the irregular memory layout resulting from fine-grained compression, DiffKV includes a Parallel KV Compaction system. This on-GPU memory manager utilizes a circular free page list and a bidirectional page table. By moving management logic—such as parallel prefix sums—directly onto the GPU, DiffKV avoids the latency overhead of CPU-based management, ensuring that memory savings translate directly into higher serving throughput.

Experimental Results

DiffKV was evaluated on mainstream LLMs (Llama3, Qwen2.5) and reasoning-heavy "thinking" models (QwQ, R1-Distill). Key findings include:

  • Compression and Throughput: DiffKV achieved 2.7x to 5.7x compression over FP16 baselines, leading to a 1.9x to 5.4x boost in end-to-end throughput.
  • Accuracy: The framework maintained near-lossless performance, with an average accuracy degradation of only 0.3% across benchmarks like MMLU, GSM8K, and LongBench.
  • Robustness: It is the first framework shown to effectively manage the long-generation requirements of "thinking" models without disrupting complex reasoning chains.

Conclusion

DiffKV demonstrates that unifying differentiated compression with efficient GPU-native memory management can significantly alleviate the KV cache bottleneck. By treating keys, values, and tokens according to their specific roles and importance, it enables the deployment of long-context LLMs at a fraction of the traditional memory cost.

Summary updated

BibTeX
@inproceedings{zhang2025unifying,
  author = {Yanqi Zhang and Yuwei Hu and Runyuan Zhao and John C. S. Lui and Haibo Chen},
  title = {{Unifying KV Cache Compression for Large Language Models with LeanKV}},
  booktitle = {SOSP},
  year = {2025},
  doi = {10.1145/3731569.3764810},
}
Figure