Abstract
KV Cache is essential for accelerating LLM inference in long-context scenarios, but its substantial memory footprint necessitates effective compression. Traditional heuristic-based eviction methods often lack a principled foundation and fail to adaptively allocate memory budgets. We present LAVa, a unified framework for KV cache compression that minimizes information loss within Transformer residual streams. By analyzing layer attention output loss, we derive a novel metric to compare cache entries across heads, enabling dynamic head budgets. Furthermore, by evaluating cross-layer information flow via normalized entropy, we achieve dynamic layer budgets. LAVa is a training-free, fully dynamic strategy that consistently outperforms existing methods across benchmarks like LongBench and InfiniteBench. Our findings reveal that dynamic layer budgets are vital for generation tasks, while dynamic head budgets are critical for extraction tasks.
What Problem Does This Paper Address?
As Large Language Models (LLMs) push toward context windows of 128K tokens and beyond, the memory required to store Key-Value (KV) caches—the "memory" of previous tokens used to speed up inference—explodes. This memory bottleneck often forces a trade-off between context length and hardware costs.
Existing solutions like SnapKV or H2O use "eviction" strategies to prune less important tokens from the cache. However, these methods are largely heuristic, relying on simple statistics like accumulated attention scores. Furthermore, most existing methods use a "fixed budget" approach, assigning the same amount of memory to every attention head or every layer, regardless of the actual information flow. This rigidity leads to performance degradation in complex tasks where some layers or heads are significantly more important than others.
Methods
The authors introduce a principled framework that treats KV cache compression as an optimization problem: minimizing information loss in the Transformer's residual streams.
Key components of the LAVa approach include:
- The LAVa Scoring Function: Unlike previous methods that only look at attention weights, LAVa incorporates the norm of the Value vectors. The score for a token is the product of its recent attention weights and the maximum norm of the value vectors in that head. This provides a more theoretically grounded measure of how much a token actually contributes to the layer's output.
- Dynamic Head Budgeting: Instead of giving every head in a layer the same number of cache slots, LAVa flattens the scores across all heads in a layer and keeps the top-N tokens globally for that layer. This allows "important" heads to claim more memory.
- Dynamic Layer Budgeting: LAVa uses normalized entropy to measure the "uncertainty" of a layer. If a layer’s attention is spread thin (high entropy), it is assigned a larger memory budget to preserve more information.
- Training-Free & Plug-and-Play: LAVa requires no fine-tuning or complex hyperparameter search, making it easy to drop into existing inference pipelines.
Key Results and Insights
Evaluation across LongBench, Ruler, and InfiniteBench demonstrates LAVa's superiority. It consistently maintains higher accuracy than baselines like SnapKV and PyramidKV across various cache budgets.
- Extraction vs. Generation: One of the most significant findings is that different tasks need different budget strategies. Extraction tasks (like finding a specific fact in a document) benefit most from dynamic head budgets, while generation tasks (like writing code or summarizing) rely heavily on dynamic layer budgets. By being fully dynamic in both dimensions, LAVa maintains top-tier performance regardless of the task type.
- Values Matter: Most prior work focused solely on Attention scores. LAVa proves that the magnitude of the Value vector is a critical component of "importance." A token might have high attention, but if its associated value vector is near zero, it contributes little to the final output.
- Massive Speedups: Compared to a full-cache implementation using FlashAttention-2, LAVa achieved a 9x speedup in decoding latency for 128K-token sequences. It effectively prevented Out-Of-Memory (OOM) errors at high context lengths while maintaining a negligible computational overhead.
Conclusion
LAVa represents a shift from heuristic-based KV cache pruning to a principled, information-theoretic approach. By dynamically allocating budgets across both heads and layers, it effectively manages the memory-performance trade-off for long-context LLMs. Future work will explore integrating LAVa into high-performance frameworks like vLLM and extending the framework to model pruning and online optimization.
Summary updated