The risk of KV cache compression

Lukas Haverbeck, Carmen Amo Alonso, Andres Felipe Posada Moreno, Sebastian Trimpe, Marco PavoneNeurIPS 2026

TL;DR

Compressing a Transformer’s working memory—its KV cache—without knowing what questions the model will ask next is fundamentally no better than rolling dice and keeping random tokens. By framing KV cache compression as a geometric "center-of-mass" balancing problem, the authors prove exact mathematical limits on compression accuracy and turn those limits into an efficient algorithm that shrinks memory during both prompt reading and text generation.

What Problem Does This Paper Address?

Imagine reading a thousand-page novel, except before reading every single new word, you have to re-read every word that came before it. That is essentially what a Transformer does during long-context inference. Its working memory of past tokens—the key–value (KV) cache—balloons as sequences grow, creating a massive bottleneck in memory and speed.

Practitioners usually tackle this by evicting "unimportant" tokens using clever rules of thumb, like keeping recent words or tokens that got lots of attention earlier. Meanwhile, theorists have mostly proven bleak worst-case results: if attention is sharp enough to pluck a single needle from a haystack, lossless compression is impossible.

What has been missing is a middle ground: a precise theory explaining what makes a specific cache compressible in practice, how close we can get to optimal accuracy, and how to design principled algorithms when compression actually is possible.

Methods

Instead of viewing the KV cache as a static list of tokens to keep or toss, the authors recast it as a discrete probability distribution over key–value pairs. This generalizes standard token eviction: rather than just deleting tokens, you are allowed to keep $K$ tokens and reweight them so they stand in for the missing ones.

To measure how tossing and reweighting tokens distorts softmax attention, each token is mapped to a response profile in a Hilbert space—a mathematical vector capturing how that token nudges both the numerator and denominator of the softmax fraction across future queries.

Figure 1: Illustration of our approach. Left: We view the token sequence as a measure P over key– value pairs (k, v) ∈X, which we map to their response profiles ΓP (k, v) ∈Hν. Right: Compressing P amounts to a sparse reweighting of tokens, which moves the barycenter of the response profiles. The size of this displacement depends on the retained tokens and their assigned weights, and controls the attention error incurred by compression. KV compression therefore reduces to a balancing problem in Hilbert space: find a K-atomic reweighting that keeps the barycenter in Hν nearly fixed.

As illustrated above, the attention error caused by compression turns out to be governed by how far the barycenter (center of mass) of these response profiles shifts. KV compression thus becomes a sparse balancing game: pick $K$ tokens and assign them weights so the center of mass barely moves.

To make this practical for autoregressive models with causal masking, the authors introduce two streaming algorithms based on a local REDUCE subroutine (which shrinks $2K$ tokens down to $K$):

  • Parallel prefix scan (Prefill): Uses a tree-like Blelloch scan over token chunks so even the initial prompt reading only ever attends to compressed summaries plus the local chunk.
  • Streaming merge-reduce (Decoding): Maintains logarithmic buckets of past summaries online as new tokens arrive.

Because future queries aren't known in advance, the REDUCE step lets practitioners plug in a finite-dimensional feature map $\Phi$—a heuristic guess at what token features will matter later—and uses balanced clustering to preserve those features while randomly sampling the rest.

Datasets

The authors evaluate their algorithms (using the Qwen3-32B model) on the "long" subset of LongBench-v2, an existing multiple-choice benchmark featuring contexts ranging from 128,000 to 2 million words. No new datasets are introduced.

Key Insights and Ideas

  • Blind compression can't beat random sampling: Once an attention head is expressive enough to sharply retrieve individual tokens, no query-agnostic algorithm can uniformly beat the error rate of simple Monte Carlo random sampling—no matter how redundant the cache looks on its own. Redundancy only exists relative to future queries.
  • Query awareness unlocks spectral decay: Looking at the covariance of token response profiles ($\Sigma_{P,\nu}$), a query-agnostic method pays an error proportional to the full trace (total variance across all directions). A query-aware method can lock down the dominant directions and only pay for the spectral tail—the leftover variance outside the top eigenspace.
  • Safe bets with upside: By designing local reducers that are unbiased in expectation, you can guarantee the worst-case safety net of random sampling unconditionally, while smoothly approaching oracle-level accuracy to the exact extent your chosen feature map $\Phi$ aligns with future queries.

Key Results

Testing on LongBench-v2 at roughly a 95% compression rate (shrinking the KV budget from 130,944 tokens down to 6,152 per head):

  • Matching uncompressed accuracy: Their balanced clustering reducer ($d = 128$ features) achieved 37.04% ($\pm 4.65$) accuracy—matching the full, uncompressed KV cache baseline (37.04%) down to the decimal.
  • Outperforming while doing more with less: Literature baselines—ScissorHands (35.19%), SnapKV (34.26%), and StreamingLLM (32.41%) —all required the full 130,944-token cache during prefill and only compressed during decoding. The authors' methods compressed both prefill and decoding to 6,152 tokens while matching or beating them.
  • Random sampling is shockingly strong: Consistent with their minimax theory, plain random sampling scored 34.26%, tying SnapKV and beating StreamingLLM despite using 95% fewer tokens during prefill.
  • Efficiency: Prefill runs in $\mathcal{O}(\log(n/K))$ parallel depth, while decoding uses $\mathcal{O}(K \log(t/K))$ memory and $\mathcal{O}(\log(t/K)/K)$ amortized REDUCE calls per token.

Limitations and Future Work

The authors candidly note that in their empirical evaluation, the standard errors (~4.6%) overlap across all tested methods—including simple random sampling and full KV attention—meaning larger-scale empirical validation is warranted to separate the methods definitively. Additionally, the theoretical analysis models a single attention head in isolation rather than multi-layer error propagation, and achieving improvements over random sampling in practice still relies on choosing or learning a good proxy feature map $\Phi$ for future queries.

Summary updated

Abstract

Transformer inference on long sequences is expensive because softmax attention repeatedly reads from a large KV cache. The prevalent approach to this bottleneck is KV cache compression, which replaces the full cache with a compact summary. Despite its practical importance, the design of such summaries is largely driven by empirical experimentation. On the theoretical side, existing results show that KV cache compression can be impossible in the worst case, but offer little systematic guidance for designing algorithms in regimes where accurate compression is possible. We bridge this gap by characterizing the minimax risk of KV cache compression in terms of the intrinsic compressibility of a cache, revealing when and how accurate compression is possible. In particular, we show that, once attention can sharply retrieve individual tokens, compression can only uniformly outperform random sampling by exploiting information about future queries, regardless how redundant the cache is inherently. Additionally, our results yield novel design principles for KV cache compression under causal masking that map efficiently to prefill and autoregressive decoding while achieving minimax-optimal risk. We instantiate these principles in a practical algorithm and illustrate how our theoretical findings can be put to practical use. Overall, our results provide a principled avenue for KV cache compression with theoretical guarantees.
BibTeX
@inproceedings{haverbeck2026risk,
  author = {Lukas Haverbeck and Carmen Amo Alonso and Andres Felipe Posada Moreno and Sebastian Trimpe and Marco Pavone},
  title = {{The risk of KV cache compression}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=IxNf37GZip},
}
Figure