Summary (Overview)
- CompKV is the first compensation-aware sparse attention framework for long-context LLM inference that explicitly optimizes KV block selection for the downstream compensation mechanism, rather than treating selection and compensation as separate stages.
- The paper provides a theoretical analysis showing that the post-compensation residual under block-mean compensation is jointly governed by a block's attention mass () and within-block logit variance (), leading to a selection score of .
- CompKV estimates these quantities from compact block statistics (mean keys, grouped variances, mean values), requiring only scalars per block, and uses an efficient asynchronous CPU-offload implementation.
- On RULER and LongBench-Pro benchmarks across Llama-3.1-8B-Instruct, Qwen3-8B, and Qwen3-32B, CompKV achieves the highest average scores among all evaluated sparse baselines, with accuracy drops as low as 2.7 points from full attention (vs. 18.1 points for the best baseline on Qwen3-32B).
- The asynchronous implementation delivers up to 6.85× self-attention speedup over full attention, with the lowest mean decoding-step latency across all nine combinations of context lengths (32K–128K) and token budgets (512–2,048).
Introduction and Theoretical Foundation
Background and Motivation
During autoregressive decoding, the KV cache grows with context length, and dense attention reads the entire cache at every step. This makes long-context inference increasingly bottlenecked by KV cache memory traffic. Query-aware sparse attention reduces this traffic by reading only a small set of tokens selected for the current query.
Recent methods divide tokens into blocks and compensate for omitted blocks' attention contributions using compact summaries (e.g., mean values). However, selection and reconstruction remain largely decoupled: blocks are ranked by predicted relevance or attention mass before reconstruction is considered.
Key Insight: A high-mass block may be easy to reconstruct, whereas a lower-mass block with greater within-block logit variation may leave a larger error. Therefore, selection should prioritize blocks that would leave the largest reconstruction error if omitted.
Theoretical Foundation
The paper defines Mean compensation as replacing every logit in an unselected block by its block mean. The compensated logit is:
where is the block-mean logit.
The selection objective minimizes the KL divergence between the compensated and full attention distributions:
Methodology
3.1 Deriving the Compensation-Aware Selection Criterion
For each query head , define the attention mass and logit variance of block :
The KL divergence expansion yields:
A second-order Taylor expansion around the block-mean logit gives:
This leads to the key result: the optimal selection criterion is to maximize
4.1 Block Scoring from Compact Statistics
CompKV estimates the score using:
- Grouped key-variance estimation — partition key coordinates into groups, storing average variance per group:
- Attention-mass estimation using the log-partition expansion:
- Compensation-aware block scoring:
4.2 Block Selection and Compensated Decoding
The selected set includes mandatory blocks (sink + local window) plus Top-K by score:
Output is computed via joint normalization:
4.3 Asynchronous Implementation
The implementation keeps KV cache in pinned CPU memory, using:
- Main CUDA stream: transfers selection region, runs block statistics + Top-K scoring
- Auxiliary stream: computes Mean compensation, overlapping with CPU gathering and exact attention
- The summary buffer stores — scalars per block
Empirical Validation / Results
RULER Accuracy (32K context, 512-token budget)
Table 1 highlights (best sparse result per model):
| Model | Full | Quest | InfLLM | Quest+RESA | CompKV |
|---|---|---|---|---|---|
| Llama-3.1-8B | 87.0 | 77.0 (↓10.0) | 73.1 (↓13.9) | 78.2 (↓8.8) | 83.2 (↓3.8) |
| Qwen3-8B | 91.5 | 76.5 (↓15.0) | 76.6 (↓14.9) | 75.8 (↓15.7) | 86.0 (↓5.5) |
| Qwen3-32B | 93.7 | 75.7 (↓18.0) | 82.5 (↓11.2) | 75.6 (↓18.1) | 91.0 (↓2.7) |
CompKV shows particularly large gains on MK3 (multi-key retrieval), outperforming baselines by 35–90 points on this difficult task.
LongBench-Pro Scores
| Model | Full | Quest | InfLLM | Quest+RESA | CompKV |
|---|---|---|---|---|---|
| Llama-3.1-8B | 25.26 | 24.28 (↓0.98) | 23.60 (↓1.66) | 24.30 (↓0.96) | 24.44 (↓0.82) |
| Qwen3-8B | 34.23 | 30.58 (↓3.65) | 31.75 (↓2.48) | 30.60 (↓3.63) | 32.74 (↓1.49) |
| Qwen3-32B | 42.00 | 37.62 (↓4.38) | 39.62 (↓2.38) | 36.16 (↓5.84) | 40.30 (↓1.70) |
Efficiency Results
- CompKV () achieves the lowest mean latency in all nine settings (3 context lengths × 3 budgets)
- Up to 6.85× speedup over full attention
- At 512-token budget: CompKV outperforms Quest and InfLLM across 32K, 64K, and 128K contexts
Ablation Studies
Table 3: Factor ablations on RULER (13-task AVG %)
| Variant | Llama 256 | Llama 512 | Qwen 256 | Qwen 512 |
|---|---|---|---|---|
| CompKV (full) | 78.6 | 83.2 | 80.9 | 86.0 |
| only (no Mean) | 75.6 | 81.8 | 79.2 | 83.5 |
| (no outer var) | 78.1 | 82.8 | 79.7 | 85.1 |
| (first-order mass) | 76.1 | 81.2 | 77.5 | 83.8 |
Key findings:
- Mean compensation adds 0.48–2.47 points
- Outer variance factor adds 0.35–1.19 points
- Second-order mass correction adds 1.96–3.39 points
- Finer variance groups () improve accuracy but at 32× metadata cost; is the practical default
Theoretical and Practical Implications
Theoretical Contributions
-
First formalization of compensation-aware selection: The paper identifies and formalizes the mismatch between block selection and downstream compensation, showing that optimal selection must consider reconstruction error, not just attention mass.
-
Analytically tractable residual analysis: By using Mean compensation, the KL divergence reduces to a log-partition gap, enabling closed-form analysis. The key theoretical result—that residual scales as —provides a principled, deployable selection criterion.
-
Unified framework: The paper shows that removing Mean compensation from the KL objective recovers standard Top-K attention-mass selection, demonstrating that CompKV is a strict generalization.
Practical Implications
- Training-free: CompKV requires no model fine-tuning, making it immediately deployable with existing LLMs.
- Compact metadata: Only scalars per block (e.g., ~1 KB per 16-token block for , ), enabling efficient CPU offloading.
- Generalizable: Works across model families (Llama, Qwen) and scales (8B–32B), with consistent improvements over baselines.
- Efficient: The asynchronous CPU-offload design overlaps compensation with KV retrieval, achieving sub-millisecond attention latencies at 128K context.
Conclusion
CompKV addresses a fundamental limitation of existing sparse attention methods by making block selection explicitly aware of the downstream compensation error. The paper's key contributions are:
-
Theoretical: Proves that post-compensation residual is jointly governed by attention mass and within-block logit variance, yielding the selection score .
-
Methodological: Introduces a practical, training-free framework using compact block statistics (mean keys, grouped variances) to estimate this score without reading all keys.
-
Empirical: Achieves state-of-the-art accuracy among sparse baselines on RULER and LongBench-Pro across three models, while delivering up to 6.85× speedup over full attention.
Future directions suggested by this work include:
- Extending compensation-aware selection to other compensation mechanisms beyond Mean (e.g., low-rank reconstructions)
- Exploring finer-grained variance statistics for accuracy-critical applications
- Investigating adaptive block sizes and variance group allocations based on observed attention patterns
Related papers
- Does Step Law Transfer to Small-Scale Language Models? An Empirical Recalibration Below 59M Parameters
Step Law's power-law form transfers to sub-59M-parameter language models, but its coefficients do not, overestimating optimal learning rate by roughly 4x.
- Amortizing Scaling Law Construction Costs · Pith Review
Bayesian optimization with compute slicing and surrogate fantasization recovers scaling law fits at 10-100x less compute, with extrapolation error under 1.6%.
- Data-DPO: Direct Preference Optimization for Target Model Data Selection in LLM Post-Training
Data-DPO treats data value as target-model-dependent, using activation probing and DPO-style preference learning to select SFT subsets that outperform full-data training with only 5-15% of data.