Ada-KV: Optimizing KV Cache Eviction by Adaptive Budget Allocation for Efficient LLM Inference

Yuan Feng, Junlin Lv, Yukun Cao, Xike Xie, S Kevin Zhou

TL;DR

Large Language Models (LLMs) struggle with long sequences because their "working memory"—the Key-Value (KV) cache—becomes massive and slow. Ada-KV introduces a head-wise adaptive budget allocation strategy that intelligently distributes memory to the attention heads that need it most. This significantly improves accuracy on long-context tasks without increasing computational overhead.

The Bottleneck of Long-Context LLMs

When interacting with an LLM like Llama-3 or GPT-4, the model stores "Key-Value (KV) pairs" for every token in the conversation to avoid redundant computations. For a 2-million-token sequence, an 8B parameter model might require a staggering 256GB of cache. This creates two primary bottlenecks:

  1. Memory Capacity: The cache quickly exceeds standard GPU memory limits.
  2. Latency: Moving this massive cache in and out of the processor (I/O) drastically slows down token generation.

Existing solutions use "eviction" methods, discarding less important tokens to keep the cache small. However, these methods typically enforce a uniform budget: if a layer has 32 attention heads, each head receives exactly the same amount of memory. The authors of Ada-KV argue this is fundamentally wasteful. Different heads exhibit vastly different "attention patterns"—some focus intensely on a few specific tokens, while others need to scan the entire history to contextualize the text.

The Ada-KV Approach: Adaptive Budget Allocation

The core innovation of Ada-KV is the shift from uniform to adaptive budget allocation, treating the entire layer as a shared pool of resources.

Comparison of uniform and adaptive budget allocation
  1. Theoretical Foundation: The authors establish a mathematical upper bound for "eviction loss" (the difference in output between a full cache and a compressed one). They prove that minimizing this loss requires abandoning equal treatment of heads.
  2. The Algorithm: Instead of pre-assigning a fixed size to each head, Ada-KV evaluates the attention weights across all heads in a layer simultaneously. It identifies the top most important weights globally. If Head A has many high-importance weights and Head B has few, Head A is dynamically granted a larger share of the memory budget.
  3. The Safeguard ($\alpha$): To prevent "starving" heads that might seem unimportant but are vital for model stability, Ada-KV includes a safeguard parameter (e.g., $\alpha=0.2$) ensuring every head maintains a minimum baseline of memory.
  4. System Optimization: Handling variable cache sizes for different heads is computationally complex. The authors implemented a flattened cache storage layout and custom CUDA kernels to ensure this adaptive logic does not degrade actual inference speed.

Evaluation and Datasets

The authors performed an exhaustive evaluation across 29 different datasets:

  • Ruler (13 tasks): Includes complex variations of the "Needle-in-a-Haystack" test, designed to evaluate if a model can retrieve specific facts buried in massive contexts.
  • LongBench (16 tasks): Covers real-world scenarios like multi-document QA, summarization, few-shot learning, and code generation.

Crucially, they tested both question-aware scenarios (where the model knows the prompt before compressing the cache) and the much harder question-agnostic scenarios (compressing the cache before the question is asked, essential for production "prompt caching").

Key Insights and Results

  • Heads are Diverse: Visualizations confirm that attention concentration varies wildly. Some heads are "sparse" (highly focused), while others are "dispersed" (broad). Uniformly cutting dispersed heads causes massive accuracy drops. Ada-KV's global optimization preserves these dispersed heads effectively.
  • The "Question-Agnostic" Advantage: Ada-KV shines brightest when the model doesn't know the question in advance. In these realistic scenarios, standard methods like SnapKV often fail because they cannot predict which tokens will be relevant. Ada-KV’s ability to retain a broader understanding of the context proves critical here.
  • Accuracy Boost: On the Ruler benchmark (Llama-3.1-8B, question-agnostic), integrating Ada-KV with SnapKV improved the average score from 87.59 to 92.67 at an 80% budget. More impressively, it jumped from 44.02 to 53.29 at a highly constrained 20% budget.
  • Efficiency and Compatibility: Despite variable cache sizes, custom CUDA kernels allow Ada-KV to match the decoding latency and memory footprint of uniform eviction methods. Furthermore, it is a "plug-and-play" upgrade, improving not just SnapKV but also other state-of-the-art methods like Pyramid, CriticalKV, and DefensiveKV.

Limitations and Future Work

Currently, Ada-KV reallocates budgets between heads within the same layer (intra-layer). It does not yet shift budgets between different layers (e.g., allocating more memory to early layers and less to later ones). Future work will aim to extend the theoretical framework to support cross-layer adaptive allocation and explore combining Ada-KV with KV quantization for even more extreme compression ratios.

Summary updated

BibTeX
@inproceedings{feng2025ada,
  author = {Yuan Feng and Junlin Lv and Yukun Cao and Xike Xie and S Kevin Zhou},
  title = {{Ada-KV: Optimizing KV Cache Eviction by Adaptive Budget Allocation for Efficient LLM Inference}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=tcisuhGsQZ},
}
Figure