Each token leaves reusable attention state.
In a standard autoregressive transformer, every attention layer projects a token’s representation into a key and a value. When the model generates the next token, its query is compared with earlier keys; the resulting attention weights combine the corresponding values. The model appends the new token’s keys and values to the cache as generation continues.
Without a cache, a straightforward decoder could recompute key and value projections for the whole preceding sequence at every step. Reusing them avoids that repeated work. The cache does not contain a second copy of the prompt as readable text: it is numerical state, stored across attention layers for the active sequence.
Short version: the model weights describe what was learned; the KV cache holds intermediate attention state for tokens processed in this run.
For the larger sequence of prompt processing and token generation, see how AI inference works ↗.
