What exactly does the KV cache store and what computational redundancy does it eliminate?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
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.