KV Cache

A KV cache stores attention keys and values from previous tokens so autoregressive generation does not recompute them every step.
Also known as
key-value cache

Intuition

When a model generates one token at a time, it can remember earlier attention data instead of rebuilding it from scratch.

Technical definition

KV cache is the stored set of key and value tensors for prior sequence positions used during transformer decoding.

Example

A chat model uses a KV cache to speed up each next-token generation step.

Common misunderstandings

  • KV cache improves decoding speed but consumes memory.
  • It does not make the model remember information outside its context window.

Need this inside a product?

The studio builds the systems these terms describe. Tell us what you are working on.