Why the cache exists

An autoregressive language model generates one token after another. Without caching, every step would recompute attention projections for the full conversation prefix even though earlier tokens have not changed. The KV cache retains those prior key and value tensors, so each step computes them only for the new token and attends over the stored history.

The cache improves decoding speed, but it is not the model's character memory. It is temporary numerical state for the current inference sequence, not a durable record of facts that can be recalled in a later chat.

Memory growth and context length

Cache size grows with sequence length, layer count, attention configuration, batch size, and numerical precision. A larger context window can therefore fit within the model's advertised token limit yet still exhaust VRAM. Architectures using grouped-query or multi-query attention can reduce cache requirements compared with storing independent key/value heads for every query head.

Cache implementations

Frameworks may allocate a dynamic cache as generation grows or reserve a fixed-size cache that works better with compilation. Quantized caches reduce memory precision, and offloaded caches move most layers to CPU memory while keeping the current layer on the GPU. Sliding-window or sink-style caches retain only the portion the architecture can use. Support and quality tradeoffs are model- and library-specific.

Where users encounter it

Local runners such as KoboldCpp and LM Studio may expose cache type, precision, or context settings. Users notice the result as prompt-processing time, token speed, and memory use rather than as generated content. Reusing a compatible prompt prefix can also reduce repeated prefill work in some serving systems.

Limitations and misconceptions

  • Clearing a KV cache does not erase saved chat logs or application-level memories.
  • A cache accelerates inference; it does not expand the model's trained context limit.
  • Quantizing or offloading the cache can save GPU memory but may reduce speed or, depending on precision, slightly affect output.
  • Cache memory estimates from one model do not transfer directly to another architecture.

Related terminology

Related database entities

Further reading