What is the KV cache, and why is it the reason generation gets faster after the first token?
Quick-fire answer from the Awesome Generative AI Guide (MIT)
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
During generation the model computes key and value tensors for every token it has processed and caches them, so each new token attends to the stored keys and values instead of recomputing them for the whole sequence. That splits a request into a compute-heavy prefill phase (process the whole prompt at once) and a memory-bound decode phase (generate one token at a time using the cache). It matters because time-to-first-token is dominated by prefill over your input length, while each later token is cheap, and because the KV cache consumes GPU memory that grows with context length and batch size. Understanding it explains prompt caching, why long prompts are slow to start, and why serving throughput is memory-limited.
Full worked answer
During generation the model computes key and value tensors for every token it has processed and caches them, so each new token attends to the stored keys and values instead of recomputing them for the whole sequence. That splits a request into a compute-heavy prefill phase (process the whole prompt at once) and a memory-bound decode phase (generate one token at a time using the cache). It matters because time-to-first-token is dominated by prefill over your input length, while each later token is cheap, and because the KV cache consumes GPU memory that grows with context length and batch size. Understanding it explains prompt caching, why long prompts are slow to start, and why serving throughput is memory-limited.
Learn more: Production topic
What a good answer covers
- During generation the model computes key and value tensors for every token it has processed and caches…
- That splits a request into a compute-heavy prefill phase (process the whole prompt at once) and a…
- It matters because time-to-first-token is dominated by prefill over your input length, while each later…
- Understanding it explains prompt caching, why long prompts are slow to start, and why serving throughput…
Key terms: Learn more
In the glossary: Prefill · Decode · KV cache · Prompt caching
Quick-fire answer from the Awesome Generative AI Guide (MIT) · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep