The KV cache stores the keys and values of every prior token so each new decode step only needs one new K and V, turning O(n^2) attention into O(n) per step.
Imagine writing a long essay where every sentence has to reference all previous sentences. Without notes, you would reread the whole essay before writing each new sentence. The KV cache is your scratchpad, you jot down a short note for every sentence you have already written (the key) and a copy of its content (the value). When writing the next sentence, you just glance at the notes instead of rereading. Each new sentence only adds one row to the scratchpad. Reading gets faster as the essay grows, because the work per new word stays small even though the essay gets long.
Detailed answer & concept explanation~6 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: prefill versus decode + what's cached (K, V) + cache size formula with num_layers + GQA and MLA + paged attention serving.
Real products, models, and research that use this idea.
- vLLM (UC Berkeley) introduced paged attention as the default KV cache manager and is the basis of most open-source serving in 2026.
- SGLang serves Llama 4 and Qwen 3 with native KV cache prefix sharing across batched requests for common system prompts.
- DeepSeek V4 ships Multi-head Latent Attention specifically to shrink the per-request cache by 10x compared to MHA.
- Anthropic's Claude Opus 4.7 serving stack uses cache-aware routing to colocate requests sharing long system prompts on the same replica.
- TensorRT-LLM (NVIDIA) implements paged KV cache and chunked prefill as the production reference on H100 and B200 hardware.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does GQA change the cache memory math compared to MHA?
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 KV cache stores Q (queries) or attention weights. Past Qs are never reused, and weights are recomputed every step; only K and V from 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.