firehose> #llmops

KV Cache

In autoregressive generation the model emits one token at a time, but attention at every step must run over all previous tokens. Naively, generating a thousand-token response means the thousandth token recomputes the key and value matrices for all 999 tokens before it — work that is identical every time, because those tokens haven't changed. The KV cache stores the key and value matrices produced at each step so they are never recomputed: each new token computes only its own K, V, and Q, then attends over the cached history. This is the single technique that makes long-sequence generation practical.

It is not a free win, and the honest framing matters: the KV cache is a memory-for-compute trade. You stop paying quadratic recomputation and start paying VRAM that grows linearly with sequence length, per concurrent request. The trade is overwhelmingly worth it for long sequences — and it is exactly why serving is memory-bound rather than compute-bound at the decode step. Every downstream problem in LLM serving — fragmentation, OOM under burst, the concurrency ceiling — is the bill for this trade arriving. The cache is the solution that creates the next problem, which is what makes Paged Attention necessary and Prompt Caching valuable.

Claims


Linked from