TL;DR
CompKV is a training-free, compensation-aware KV cache selection framework designed to accelerate long-context LLM inference. By prioritizing sparse attention blocks based on their estimated post-compensation reconstruction error rather than just their raw attention mass, CompKV maintains high model accuracy while delivering up to a 6.85× self-attention speedup over full attention.
What Problem Does This Paper Address?
As Large Language Models (LLMs) scale to handle massive context windows (e.g., hundreds of thousands of tokens), they run into a severe hardware bottleneck: KV cache memory traffic. During autoregressive decoding, the model must load the entire history of Key-Value states from memory at every single step, making long-context inference heavily memory-bound.
To alleviate this, query-aware sparse attention methods read only a small, selected subset of tokens or blocks for the current query, often using compact summaries to "compensate" for the omitted tokens. However, existing approaches decouple selection and compensation. They rank and select blocks based solely on predicted relevance or attention mass before considering how well the omitted blocks can be reconstructed.
This decoupled design overlooks a crucial interaction: a high-mass block with low internal variance is actually very easy for a compensator to approximate, whereas a lower-mass block with high internal logit variation will leave a massive reconstruction error if omitted.
Methods
CompKV bridges this gap by explicitly optimizing block selection for the downstream compensation mechanism.
- Mean Compensation Model: The framework adopts a block-mean compensation approach, where every logit in an unselected block is replaced by its block mean. This choice provides an exact log-partition identity, making the selection-compensation interaction analytically tractable.
- Mathematical Formulation: Through a second-order Taylor expansion of the KL divergence between full and compensated attention distributions, the authors prove that the residual error of an omitted block depends jointly on two factors: block attention mass and within-block logit variance.
- Compact Block Statistics: To avoid reading the full keys of every candidate block (which would defeat the purpose of sparse attention), CompKV stores compact, block-level metadata: the mean key and grouped key-variances. At each decoding step, the query head uses these statistics to compute a query-dependent score on the fly.
- Asynchronous Pipeline: The authors implement an efficient CPU-offload pipeline. While the main GPU stream calculates exact attention on the selected blocks, an auxiliary stream handles the mean compensation for unselected blocks, overlapping memory transfers and computation efficiently.
Datasets
The authors evaluated CompKV across three prominent models—Llama-3.1-8B-Instruct, Qwen3-8B, and Qwen3-32B—using two long-context benchmarks:
- RULER: A synthetic benchmark testing long-context capabilities across 13 tasks including retrieval, multi-hop tracing, and aggregation at a 32K context length.
- LongBench-Pro: A realistic long-document benchmark consisting of natural documents across 11 primary tasks (e.g., summarization, QA, code analysis) with context lengths scaling up to 128K.
Key Insights and Ideas
- "Hard-to-Reconstruct" beats "High-Mass": Traditional sparse attention spends its exact-read budget on the heaviest hitters. CompKV shifts the paradigm: if a block's logits are nearly uniform (low variance), its mean summary is already an excellent proxy. The exact-read budget is better spent on blocks that are highly variable and thus hard to reconstruct.
- The Dual Role of Variance: Within-block logit variance serves a dual purpose in CompKV. It acts as a correction factor when estimating the block's attention mass, and it functions as the primary driver of the post-compensation residual error.
Key Results
- Accuracy: CompKV consistently achieved the highest average scores among all evaluated sparse baselines (such as Quest and InfLLM) across all three models on both RULER and LongBench-Pro. It proved particularly effective at difficult retrieval tasks (like the Needle-in-a-Haystack variant MK3).
- Efficiency: Benchmarked on an NVIDIA H100 GPU, CompKV achieved the lowest mean decoding-step latency across all nine combinations of context lengths (32K–128K) and token budgets (512–2,048), delivering up to a 6.85× speedup over full attention.
Limitations and Future Work
While CompKV demonstrates strong performance, it is currently optimized around Mean Compensation. The authors note that more sophisticated tail-reconstruction methods (such as low-rank approximations or tracking higher-order moments) could be integrated into the framework. Furthermore, exploring how compensation-aware selection interacts with orthogonal KV cache reduction techniques like quantization or eviction remains an open and promising direction for future research.
Summary updated