Knowledge note

KV Cache

The stored key and value tensors from earlier tokens that autoregressive attention reuses instead of recomputing the whole prefix.

Updated September 16, 2026Confidence: High

KV Cache

KV Cache is the per-layer store of attention keys and values produced by earlier tokens, reused during autoregressive decoding so the model does not recompute the entire prefix.

Why It Exists

Without caching, generating token $i$ repeats key and value projections for tokens $1$ through $i-1$. Caching makes those projections persistent and reduces the repeated work, which is essential for practical Transformer decoding.

How It Works

Each new token appends one key vector and one value vector per relevant layer and KV head. Its query attends over the cached keys and combines the corresponding values. Projection work per step becomes constant, but cache memory and the attention read still grow linearly with context length.

Tradeoffs

Long contexts can make the cache the dominant memory consumer and constrain batch size. MQA, GQA, MLA, quantization, paging, sparse attention, and linear attention reduce different parts of this cost; only recurrent-state approaches make stored state independent of sequence length.

Common Confusions

  • KV cache vs. model weights: Weights are fixed learned parameters; the KV cache is request-specific runtime state.
  • KV cache vs. linear-attention state: A KV cache preserves token-level keys and values; a linear-attention state merges them into a fixed-size summary.

Where It Appears

  • Linear Attention — Replaces explicit token history with accumulated key–value statistics.
  • Kimi Delta Attention — A Kimi-family fixed-state attention mechanism used to reduce cache pressure.
  • Continuous Batching — Uses iteration-level admission to keep available KV capacity productive.
  • PagedAttention — The algorithm that stores KV cache in fixed-size non-contiguous blocks.
  • Block Table — The logical-to-physical mapping used to address paged KV cache.