Full text not available for this paper
Summary
- KV-SURGEON introduces a compensation-aware offline KV-cache compaction method that jointly optimizes which cache entries to delete and how the remaining entries should be adjusted, rather than treating selection and refitting as separate sequential steps.
- The method derives a quadratic surrogate of the attention-output error that admits closed-form expressions for greedy deletion saliencies and compensating updates, inspired by Optimal Brain Surgeon (OBS) pruning techniques.
- KV-SURGEON substantially advances the cost–accuracy Pareto frontier across QuALITY, LongHealth, and Long Code Arena benchmarks, with models from 4B to 30B parameters and compaction ratios from 5× to 100×.
- At 50× compaction, KV-SURGEON improves mean question-answering accuracy by 3.0 percentage points over the prior state of the art (attention matching), while its fast variant (KV-SURGEON-fast) exceeds all prior methods at only two-fifths of the cost.
- A controlled ablation demonstrates that the performance gain comes specifically from compensation during selection (updating surviving entries after each deletion), not merely from the surrogate objective.
Introduction and Theoretical Foundation
Background and Motivation
Large language model (LLM) applications frequently query a fixed context (documents, patient records, codebases). The key-value cache (KV-cache) grows linearly with context length and dominates memory usage during long-context inference. Offline compaction processes a context once, compresses its cache, and reuses the compacted cache for all subsequent requests—amortizing a one-time cost over many queries.
The Core Problem: Softmax Coupling
The central challenge is deciding which cache entries to delete. For one attention head with cache entries, each containing a key and value , a query produces:
The key insight is that softmax renormalization couples deletion decisions nonlinearly: removing one entry changes the attention weights of all remaining entries. This makes selection a combinatorial problem rather than a simple ranking problem.
Limitations of Existing Approaches
Existing methods suffer from a critical restriction: they evaluate each candidate deletion with the rest of the cache held fixed. Specifically:
- Attention matching (Zweiger et al., 2026) refits the retained cache after selection, but selection itself ignores compensation potential.
- Output-aware methods (CAOTE, OBCache, ReST-KV) estimate single-deletion error but evaluate deletions in isolation.
- Eviction-by-proxy methods (H2O, StreamingLLM) rank entries by scores that ignore the rest of the cache entirely.
What is missing is compensation-aware selection: each candidate deletion should be scored by the error remaining after surviving entries have been adjusted to compensate for it.
Methodology
Problem Formulation
For one attention head with cache entries and calibration queries , the attention weights and outputs are:
where .
Given a budget , the goal is to retain a support set with , assigning each retained entry an adapted value and a positive attention multiplier . The compacted cache produces:
where is the ratio between compacted and original normalization terms.
The Quadratic Surrogate
The key technical contribution is deriving a tractable surrogate. By introducing the variable , the output can be written as a ratio of two linear terms:
Instead of matching the ratio directly, the method asks the compacted cache to reproduce numerator and denominator separately. The resulting quadratic surrogate is:
The right-hand side forms a single linear least-squares problem with target columns. With and a ridge penalty , the support score is:
Greedy Elimination with Closed-Form Compensation
For a fixed support , the optimal coefficients and shared inverse are:
The saliency of entry (the increase in optimal surrogate objective when removed) is:
After removing entry , the updates are:
These give the exact minimizer of the surrogate on without solving another regression. The algorithm repeatedly removes the entry with smallest saliency, updating and until .
Implementation Details
Key practical additions include:
- Candidate pool: Pre-filter to entries using a leave-one-out score ()
- Block deletion: Delete entries per step using block-update formulas
- Final refit: Optimize multipliers (box-constrained) then values (least-squares)
- Mild-compaction fallback: For heads retaining of entries, skip greedy elimination
Empirical Validation / Results
Main Results at 50× Compaction
Table 1: Accuracy (%) at 50× compaction across model–benchmark pairs
| Method | Time (s) | Qwen3-4B QuAL. | Qwen3-4B LongH. | Llama-3.1-8B QuAL. | Llama-3.1-8B LongH. | Gemma-3-12B QuAL. | Gemma-3-12B LongH. | Qwen3-30B QuAL. | Qwen3-30B LongH. | Mean |
|---|---|---|---|---|---|---|---|---|---|---|
| KV-SURGEON-fast | 54 | 65.9 | 66.9 | 61.0 | 61.5 | 68.1 | 52.1 | 71.4 | 64.1 | 63.9 |
| OBCache (adapted) | 58 | 62.4 | 62.8 | 59.8 | 52.4 | 66.6 | 50.2 | 67.3 | 62.8 | 60.5 |
| AM-HAK-fast | 54 | 58.1 | 53.5 | 58.7 | 53.5 | 62.2 | 45.6 | 65.8 | 59.8 | 57.1 |
| KV-SURGEON | 145 | 66.8 | 67.8 | 62.3 | 62.1 | 67.5 | 56.4 | 72.5 | 65.2 | 65.1 |
| LOO | 139 | 65.6 | 64.2 | 61.2 | 59.1 | 65.1 | 49.6 | 69.6 | 62.3 | 62.1 |
| AM-HAK | 138 | 64.1 | 65.0 | 60.4 | 58.2 | 65.1 | 52.7 | 69.5 | 61.4 | 62.0 |
| AM-OMP-CS | 266 | 65.7 | 65.9 | 60.6 | 55.8 | 67.2 | 50.9 | 69.7 | 63.1 | 62.4 |
| AM-OMP | 763 | 66.4 | 65.5 | 61.3 | 57.3 | 67.7 | 54.5 | 69.2 | 63.9 | 63.2 |
Key findings:
- KV-SURGEON reaches 65.1% mean accuracy in 145 seconds, 3.0 points above AM-HAK at comparable cost
- KV-SURGEON-fast reaches 63.9% in 54 seconds, exceeding AM-OMP (63.2% in 763 s) with a 14.1× reduction in pipeline time
- Gains are consistent across all 8 model–benchmark pairs and all compaction ratios (5× to 100×)
Source of Performance Gain
Table 2: Impact of compensation during selection (Qwen3-4B, QuALITY, 50×)
| Method | Selection rule | Compensation | Accuracy (%) |
|---|---|---|---|
| KV-SURGEON | Equation (11) | ✓ | 66.9 |
| KV-SURGEON w/o compensation | Equation (11) | ✗ | 63.9 |
| LOO | Equation (13) | ✗ | 64.7 |
Disabling only the compensating update (keeping the surrogate, pool, and refit fixed) reduces accuracy by 3.0 points, demonstrating that compensation during selection—not the surrogate itself—drives the improvement.
Robustness to Calibration
Replacing expensive self-study calibration with a single repeat pass costs KV-SURGEON only 1.2 points of mean accuracy (from 65.1% to 63.9%), while the same change costs AM-HAK 4.9 points. This robustness persists across all compaction ratios.
Theoretical and Practical Implications
Theoretical Contributions
-
Quadratic surrogate derivation: The surrogate in Equation (8) is shown to be the second-order Taylor expansion of the exact loss around the original cache (Appendix A.1), providing a principled approximation.
-
Closed-form compensation: The saliency formula has a natural interpretation: it equals the squared coefficient magnitude of entry times the ridge-regularized residual of regressing its attention column on the other retained columns. An entry with a large coefficient is cheap to delete when its attention column lies close to the span of others.
-
Block deletion exactness: The block updates in Equation (14) give the exact minimizer on for any selected block ; only the block selection (by individual saliencies) is approximate.
Practical Implications
- Cost–accuracy frontier: KV-SURGEON establishes a new Pareto frontier for offline KV-cache compaction, making aggressive compaction (50×–100×) practical for production long-context applications.
- Calibration flexibility: The method's insensitivity to calibration quality means practitioners can use cheap repeat-pass calibration without significant accuracy loss.
- Model generality: Gains hold across dense and mixture-of-experts architectures from 4B to 30B parameters, suggesting broad applicability.
- Compute efficiency: The O() complexity (bounded by the pool size , not cache size ) makes the method scalable to very long contexts.
Conclusion
KV-SURGEON demonstrates that deletion and adaptation can be coupled efficiently in offline KV-cache compaction, contrary to prior methods that treated them sequentially. The key insight is that a quadratic surrogate of the attention-output error enables closed-form compensation-aware selection, where each candidate deletion is scored after surviving entries have been adjusted to compensate.
The method improves the cost–accuracy frontier at every evaluated compaction ratio (5×–100×) across three benchmarks and five models, with the largest gains at aggressive compaction levels (50× and 100×). Its fast variant exceeds all prior methods at two-fifths of the cost of the strongest baseline.
Future directions suggested by this work include:
- Exploring whether compensation-aware selection extends to other attention variants (e.g., sliding-window, linear attention)
- Investigating joint optimization across heads rather than independent per-head compaction
- Applying the OBS-inspired framework to other cache-compression axes (quantization, low-rank projection)
Related papers
- AgenticEvolve: Evolutionary Program Search with Persistent Language Model Agents that Design and Run Experiments
AgenticEvolve, where persistent LLM agents run self-designed experiments between evaluations, consistently outperforms baselines in heuristic design and symbolic regression while keeping costs under a few dollars per run.
- What Does a Harness Repair? A Preregistered Study of Visibility, Baseline Adequacy and Evaluation Defects
Preregistered harness-search studies show most accuracy gains are visibility artifacts, and searched harnesses failed to beat trivial constant-label baselines despite large nominal improvements.
- Looped Transformers under the Jacobian Lens: Does the Global Workspace Survive Recurrence?
Looped transformers retain a global workspace, but recurrence reshapes its interfaces: reads and writes follow iteration boundaries, not absolute depth, yet neither model preserves injected content beyond roughly two recurrences.