TL;DR
CompressKV is a novel key-value (KV) cache compression framework that prevents large language models (LLMs) from accidentally discarding crucial mid-context information during long-context inference. By identifying and prioritizing "Semantic Retrieval Heads" over biased "Streaming Heads" and utilizing an offline, error-aware layer budget allocation, CompressKV retains up to 97% of full-cache performance while using as little as 3% of the original cache size.
What Problem Does This Paper Address?
As large language models (LLMs) scale up to handle massive context windows, their Key-Value (KV) cache grows linearly, creating a massive memory bottleneck and slowing down decoding speed. To mitigate this, state-of-the-art methods evict "unimportant" tokens from the cache based on attention scores.
However, existing eviction strategies suffer from a major flaw: they pool attention scores uniformly across all heads within a Grouped Query Attention (GQA) group. This ignores the fact that different attention heads have different functions. Specifically, "Streaming Heads" focus heavily on the very beginning and end of a prompt, and their massive attention scores tend to dominate the average. As a result, critical "Retrieval Heads"—which focus on semantically rich evidence hidden in the middle of the text—get drowned out, causing the model to evict the exact tokens it needs to answer a prompt accurately.
Methods
CompressKV introduces a resource-efficient, two-pronged framework to solve this problem:
- Semantic Retrieval Head (SRH) Identification & Token Selection: Instead of using strict, peak-driven metrics that only credit a head if its top-1 attention score lands exactly on a ground-truth answer token, CompressKV introduces a span-aggregation standard. It evaluates heads using a calibration dataset, summing attention weights over the entire answer span and its semantic neighborhood. Once the top-$k$ SRHs are identified per layer, only these heads are used to determine token importance, completely bypassing the biased influence of Streaming Heads.
- Error-Aware Layer-Adaptive Cache Allocation: Not all transformer layers react to cache compression the same way. CompressKV quantifies the compression impact of each layer offline by measuring the Frobenius norm of the difference between attention block outputs with a full cache versus an extremely compressed cache. Cache budgets are then proportionally distributed, giving more memory to layers that exhibit higher eviction errors. Because this profiling is done offline, it introduces zero online computational overhead during inference.
Datasets
The authors evaluated CompressKV across multiple open-source LLMs (including Llama-3.1-8B, Mistral-7B, and Qwen2.5-14B/32B) using two primary long-context benchmarks:
- LongBench: A comprehensive suite of 16 long-context subtasks spanning single/multi-document QA, summarization, few-shot learning, synthetic tasks, and code completion.
- Needle-in-a-Haystack (NIAH): A targeted retrieval benchmark that tests a model's ability to locate a specific, isolated piece of information hidden at various depths within an elongated text.
Key Insights and Ideas
- Head Heterogeneity is Critical: Treating all attention heads equally during cache eviction is a fundamental mistake in GQA architectures. Streaming heads naturally mask the subtle but vital signals from retrieval heads.
- Look at the Span, Not Just the Peak: Traditional retrieval head identification misses crucial heads because attention in long contexts is often sparse and distributed across a semantic neighborhood (e.g., words like "eat" or "a thing" surrounding the target answer "sandwich"). Aggregating over the entire answer span uncovers these hidden, meaningful heads.
- Smart Offline Profiling Beats Expensive Online Compute: While other adaptive layer allocation methods rely on calculating attention entropy or variance dynamically during generation, CompressKV proves that static, offline error estimation generalizes well and saves precious runtime compute.
Key Results
- Extreme Compression with High Fidelity: On LongBench question-answering tasks, CompressKV preserves over 97% of full-cache performance while utilizing a mere 3% of the KV cache budget.
- Superb Retrieval Accuracy: On the Needle-in-a-Haystack benchmark, it achieves 90% of baseline accuracy with just 0.7% of the original KV storage capacity.
- Highly Complementary to Existing Systems: CompressKV is fully orthogonal to other efficiency techniques. When combined with 2-bit KIVI quantization, it successfully shrinks the KV memory footprint down to roughly 1.6% of the 16-bit full-cache baseline while maintaining robust accuracy.
Limitations and Future Work
The primary limitation of CompressKV is its reliance on an offline calibration dataset to identify the Semantic Retrieval Heads and determine layer-wise budgets. While this ensures zero runtime overhead, the precomputed head sets and layer budgets remain static during inference. This means the framework might not dynamically adapt as perfectly to highly anomalous or out-of-distribution prompts that deviate significantly from the calibration data. The authors suggest that exploring hybrid or semi-dynamic allocation strategies could be a promising direction for future work.
Summary updated