KV Cache Compression › The Compression Opportunity

Michael BrenndoerferJanuary 9, 20265 min read
Language AI HandbookAll chapters
Part 42 of 67Inference Optimization
Chapter 316KV Cache Compression › The Compression Opportunity
Reading section 2 of 13 · The Compression Opportunity · 5 minSection 2 of 13 · 5 min

Book contents

Section 2 of 13 · 5 min read

KV Cache Compression › The Compression OpportunityOne section · Sections in this chapter2 / 13 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Before diving into specific techniques, we need to understand why compression is feasible in the first place. The basic question is this: can we discard information from the KV cache without significantly harming generation quality? To answer this, consider the attention patterns in a typical language model generating the 500th token. The query for this new token computes attention scores against all 499 previous key vectors. In a perfectly uniform distribution, each previous token would receive 1/499≈0.2%1/499 \approx 0.2\% of the attention. In practice, attention is far from uniform, and this non-uniformity is precisely what makes compression possible.

The magnitude of this non-uniformity is striking. Empirical studies of transformer attention patterns consistently find that a small fraction of tokens, often 10-20%, account for 80-90% of the total attention weight. The remaining 80-90% of tokens share only 10-20% of the attention budget. This is reminiscent of the Pareto principle in economics: a small minority of inputs drives the majority of the output. For KV caches, this means that a compressed cache containing only the high-attention minority of tokens can approximate the full attention computation remarkably well, as long as we correctly identify which tokens belong to that necessary minority.

Studies of transformer attention patterns reveal several consistent phenomena that explain why some tokens matter far more than others:

  • Local focus: Recent tokens often receive disproportionate attention, especially in lower layers. This makes intuitive sense because language exhibits strong local coherence, with adjacent words being grammatically and semantically related.
  • Anchor tokens: Semantically important tokens such as subjects and verbs, along with tokens naming key entities, attract attention regardless of distance. These tokens carry the core meaning of a passage and remain relevant throughout generation.
  • Attention sinks: As we covered in Part XVIII, initial tokens accumulate attention even when semantically irrelevant. This curious phenomenon appears to serve a computational purpose rather than a semantic one.
  • Sparse activation: Many tokens receive near-zero attention and contribute minimally to the output. These tokens are prime candidates for removal without significant quality degradation.
Out[3]:
Visualization
Bar chart showing attention weights across token positions with high weights at beginning, end, and two intermediate positions.
Simulated attention distribution showing characteristic non-uniformity. Initial tokens act as attention sinks, recent tokens receive local focus, and specific semantic positions (15, 28) act as anchor tokens. Many intermediate tokens receive near-zero attention, showing the compression opportunity and the basis for selective eviction strategies.

This non-uniformity means that a cache storing only the high-attention tokens might preserve most of the information needed for accurate generation. The attention distribution is not merely slightly skewed; it is often dramatically concentrated on a small subset of tokens. The challenge lies in identifying these important tokens efficiently, without requiring expensive computation at each generation step. We need methods that can predict which tokens will be important for future generation steps, not just which tokens have been important in the past. As we will see, historical attention patterns turn out to be a surprisingly reliable predictor of future importance, at least for the tokens that truly matter.

The Key Insight

The feasibility of KV cache compression rests on a simple empirical observation: transformer attention is highly concentrated on a small subset of tokens, and this concentration is consistent across generation steps. A token that has received high attention in the past is very likely to receive high attention in the future. This temporal consistency of attention patterns is what makes eviction-based compression viable. If attention patterns were random, no eviction strategy could work reliably. The fact that they are structured and persistent is what turns compression from a theoretical possibility into a practical technique.