Skip to content

KV-Cache

Cache of intermediate computation of attention in Transformer. Stores already processed 'keys' and 'values' of previous tokens to avoid recalculating them at each step.

Why is it needed

When generating each next token, the model looks at the entire context anew. Without a cache, this would mean recalculating attention for all words each time — quadratically expensive.

KV-cache keeps ready key-value pairs and processes only the new token on the next step.

Cost

The cache lives in VRAM and grows with the length of the context. This is why long dialogues consume memory: model weights are fixed, but the cache is not.

Relation to vLLM

vLLM is famous for PagedAttention — managing KV-cache by pages, like virtual memory in an OS. This sharply increases throughput.

See also

← All terms