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):
| Model | Attention | Per token | At 32K | Weights, BF16 | Cache / weights |
|---|---|---|---|---|---|
| Qwen3 0.6B | GQA | 114.7 KB | 3.8 GB | 1.2 GB | 3.15× |
| Phi-3.5 Mini | MHA | 393.2 KB | 12.9 GB | 7.6 GB | 1.69× |
| OLMo 3 7B | MHA | 524.3 KB | 17.2 GB | 14.6 GB | 1.18× |
| Gemma 3 270M | MQA | 18.4 KB | 604 MB | 536 MB | 1.13× |
| Qwen3 1.7B | GQA | 114.7 KB | 3.8 GB | 3.4 GB | 1.09× |
| SmolLM2 135M | GQA | 23.0 KB | 189 MB | 269 MB | 0.70× |
| Qwen3 4B | GQA | 147.5 KB | 4.8 GB | 8.0 GB | 0.60× |
| Gemma 3 4B | GQA | 139.3 KB | 4.6 GB | 7.8 GB | 0.59× |
| Qwen3.5 397B-A17B | GQA | 30.7 KB | 1.0 GB | 793 GB | 0.00× |
| Kimi K2 | MLA | 70.3 KB | 2.3 GB | 2.05 TB | 0.00× |
| Nemotron 3 Super 120B-A12B | GQA | 8.2 KB | 268 MB | 241 GB | 0.00× |
| Nemotron 3 Ultra 550B-A55B | GQA | 12.3 KB | 403 MB | 1.1 TB | 0.00× |
Related
Grouped-query attention (GQA) · Multi-head latent attention (MLA) · Sliding-window attention · Quantization · every term