What exactly does the KV cache store and what computational redundancy does it eliminate?
Explain what the KV cache stores during autoregressive decoding and what work it lets you skip on each new token step. Be specific about which tensors are cached and which are recomputed.
The KV cache stores past tokens' K and V projections per layer and head, so each decode step computes K, V only for the new token instead of recomputing the whole prefix.
Imagine writing a story where every new sentence has to stay consistent with everything you wrote before. Without notes, you would reread the entire story before writing each sentence. The KV cache is a notebook: for each sentence you finish, you jot a short label (the key) and a copy of its meaning (the value). To write the next sentence, you just scan your labels and pull the matching meanings, instead of rereading the whole story. You only add one new note per sentence. The fresh thought you have right now (the query) gets used immediately and never stored, because no future sentence ever looks back at it. So the notebook holds only labels and meanings, never your in the moment questions.
Detailed answer & concept explanation~8 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: name what is cached (K and V, per layer per head per position) and what is not (Q, weights), then the O(N^2) to O(N) per-step argument, then the HBM cost and the levers that manage it.
Real products, models, and research that use this idea.
- vLLM (UC Berkeley) implements paged attention over the KV cache and is the basis of most open-source LLM serving in 2026.
- DeepSeek V4 ships Multi-head Latent Attention, which compresses cached K and V to a low-rank latent to shrink the per-request cache.
- Llama 4 and Mistral Large 3 use Grouped-Query Attention to cut the number of cached KV heads versus full multi-head attention.
- TensorRT-LLM (NVIDIA) provides paged KV cache and fp8 KV as the production reference on H100 and B200 hardware.
- Anthropic and OpenAI expose prompt caching, which keeps the KV state of a repeated prompt prefix warm to cut input cost on reuse.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is Q not cached when K and V both are?
QWhat dominates the KV cache memory footprint at scale?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Saying the cache stores Q or attention weights. Past queries are never re-read and weights are recomputed each step; only the K and V of prior tokens persist.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.