Glossary · Memory, precision and compute

KV cache

Also: key-value cachecontext memory

Read it at the depth you need: one sentence · a paragraph · the math · in the models here

1In one sentence

The keys and values of every earlier token, stored so each new token does not recompute them. It grows with context length and batch size, and often rivals the weights.

2In a paragraph

To generate a token, every attention layer compares it with the keys of all earlier tokens and mixes their values. Recomputing those each step would be wasteful, so they are kept: the KV cache. It grows by a fixed amount per token, per sequence. For long contexts or many users at once it can outgrow the weights, and it is the main thing GQA, MLA and sliding windows are designed to shrink.

3The math, shapes and parameters

KV bytes = 2 (key and value) × L × K × h × bytes per value × tokens × sequences

with K the KV heads and h the head size; for MLA, L × (rkv + hr) × bytes × tokens. Runtimes such as vLLM allocate it in pages and can store it in 8 bits (halving it). It does not depend on the FFN or the number of experts at all: a 30B mixture of experts can have a smaller cache than an 8B dense model.

4In the 96 models on this site

Where the cache weighs most and least against the weights (BF16, one 32K sequence, or the model's maximum if shorter):

ModelAttentionPer tokenAt 32KWeights, BF16Cache / weights
Qwen3 0.6BGQA114.7 KB3.8 GB1.2 GB3.15×
Phi-3.5 MiniMHA393.2 KB12.9 GB7.6 GB1.69×
OLMo 3 7BMHA524.3 KB17.2 GB14.6 GB1.18×
Gemma 3 270MMQA18.4 KB604 MB536 MB1.13×
Qwen3 1.7BGQA114.7 KB3.8 GB3.4 GB1.09×
SmolLM2 135MGQA23.0 KB189 MB269 MB0.70×
Qwen3 4BGQA147.5 KB4.8 GB8.0 GB0.60×
Gemma 3 4BGQA139.3 KB4.6 GB7.8 GB0.59×
Qwen3.5 397B-A17BGQA30.7 KB1.0 GB793 GB0.00×
Kimi K2MLA70.3 KB2.3 GB2.05 TB0.00×
Nemotron 3 Super 120B-A12BGQA8.2 KB268 MB241 GB0.00×
Nemotron 3 Ultra 550B-A55BGQA12.3 KB403 MB1.1 TB0.00×

Related

Grouped-query attention (GQA) · Multi-head latent attention (MLA) · Sliding-window attention · Quantization · every term