KV cache explained
Llama 3.1 8B needs 16.0 GB of KV cache for a 128K-token context in FP16 (128 KB per token), more than its 4.52 GB of Q4_K_M weights. While it writes, a model keeps the keys and values of every earlier token so it does not recompute them, and that cache grows with the conversation.
The formula
For a model with plain grouped-query attention:
KV cache = 2 × layers × KV heads × head size × bytes per value × tokens × requests The 2 counts keys and values. Llama 3.1 70B has 80 layers with 8 KV heads of 128 values, so each token costs 2 × 80 × 8 × 128 × 2 bytes = 320 KB in FP16, and a 128K-token conversation 40.0 GB. Several requests at once multiply it: an engine serving 8 chats of 32K tokens holds 8 × 10.0 GB.
Why some models need far less
- Latent attention (MLA) caches one compressed vector per token and layer instead of full keys and values. DeepSeek V3 stores 576 values per layer, 69 KB per token for a 671B model.
- Sliding windows keep only the most recent tokens in most layers, from 128 in gpt-oss to a few thousand in others. Gemma 4 31B: 10 of its 60 layers use full attention and 50 keep a sliding window of 1,024 tokens, so it needs 80 KB per token once the windows are full.
- Linear attention and state-space layers keep a fixed-size state instead of a cache. Qwen3.6 35B-A3B: 10 of its 40 layers use full attention and 30 are linear-attention layers with no growing cache, so only a quarter of it grows: 20 KB per token.
- A lower-precision cache halves or quarters the size: FP8 or Q8_0 cache in vLLM and llama.cpp takes half of FP16, Q4_0 a bit over a quarter, with a small loss of quality: KV cache quantization, sizes and quality.
KV cache of popular models
FP16 cache for one request, for every tracked model with a context window of at least 128K tokens. Cheapest first.
| Model | Per token | 32K tokens | 128K tokens |
|---|---|---|---|
| Nemotron 3 Nano 30B-A3B | 6 KB | 192 MB | 0.8 GB |
| Ling 3.0 Tiny 7.9B-A1.3B | 7 KB | 216 MB | 0.8 GB |
| Nemotron 3.5 Super VL 120B-A12B | 8 KB | 256 MB | 1.0 GB |
| Nemotron 3 Super 120B-A12B | 8 KB | 256 MB | 1.0 GB |
| Ling 3.1 Flash 560B-A25B | 10 KB | 324 MB | 1.3 GB |
| Limite 1B Violetto | 12 KB | 447 MB | 1.6 GB |
| Muse Glimmer 30B | 13 KB | 514 MB | 1.7 GB |
| Nemotron 3 Nano 4B | 16 KB | 512 MB | 2.0 GB |
| Gemma 4 E4B | 16 KB | 552 MB | 2.0 GB |
| GLM-5.3 Flash | 19 KB | 616 MB | 2.4 GB |
| Gemma 4 12B | 16 KB | 992 MB | 2.5 GB |
| Ornith 1.0 35B | 20 KB | 640 MB | 2.5 GB |
| Ornith 1.5 35B-A3B | 20 KB | 640 MB | 2.5 GB |
| Qwen3.6 35B-A3B | 20 KB | 640 MB | 2.5 GB |
| Kolibri-1 | 20 KB | 740 MB | 2.6 GB |
| Gemma 4 26B-A4B | 20 KB | 940 MB | 2.8 GB |
| MiMo V2.6 Flash | 23 KB | 866 MB | 3.0 GB |
| AliceAI Foundation 80B-A3B | 24 KB | 768 MB | 3.0 GB |
| Qwen3.8 Flash Next | 24 KB | 768 MB | 3.0 GB |
| Qwen3.5 122B-A10B | 24 KB | 768 MB | 3.0 GB |
| Qwen3-Coder-Next | 24 KB | 768 MB | 3.0 GB |
| gpt-oss-20b | 24 KB | 786 MB | 3.0 GB |
| Kimi K3 | 27 KB | 864 MB | 3.4 GB |
| LightOnOCR-3 4B | 32 KB | 1.00 GB | 4.0 GB |
| LensVLM 9B | 32 KB | 1.00 GB | 4.0 GB |
| Ornith 1.0 9B | 32 KB | 1.00 GB | 4.0 GB |
| ZDTaichu 5.0 9B | 32 KB | 1.00 GB | 4.0 GB |
| MiMo V2.6 Distill Qwen 9B | 32 KB | 1.00 GB | 4.0 GB |
| Ornith 1.5 9B | 32 KB | 1.00 GB | 4.0 GB |
| Qwen3.5 9B | 32 KB | 1.00 GB | 4.0 GB |
| gpt-oss-120b | 36 KB | 1.15 GB | 4.5 GB |
| Spark-X2.5 4B | 36 KB | 1.23 GB | 4.6 GB |
| MiniCPM5 2B | 42 KB | 1.31 GB | 5.3 GB |
| Xing 4.0 29B-A4B | 45 KB | 1.41 GB | 5.6 GB |
| Step 3.7 Flash 196B-A11B | 48 KB | 1.63 GB | 6.1 GB |
| MiMo V2.6 Pro | 50 KB | 1.78 GB | 6.5 GB |
| GLM-4.7 Flash | 53 KB | 1.65 GB | 6.6 GB |
| ThinkingCap Qwen3.8 27B | 64 KB | 2.00 GB | 8.0 GB |
| Hemmingway-1 27B | 64 KB | 2.00 GB | 8.0 GB |
| Qwen3.6 27B | 64 KB | 2.00 GB | 8.0 GB |
| Qwen3.8 27B | 64 KB | 2.00 GB | 8.0 GB |
| DeepSeek V3 / R1 | 69 KB | 2.14 GB | 8.6 GB |
| DeepSeek V3.2 | 76 KB | 2.38 GB | 9.5 GB |
| DeepSeek V4.1 Flash 1017 | 80 KB | 2.50 GB | 10 GB |
| Granite 4.2 3B | 80 KB | 2.50 GB | 10 GB |
| DeepSeek V4.1 Flash | 80 KB | 2.50 GB | 10 GB |
| DeepSeek V4 Flash 0731 | 86 KB | 2.69 GB | 11 GB |
| DeepSeek V4 Flash | 86 KB | 2.69 GB | 11 GB |
| Gemma 4 31B | 80 KB | 3.67 GB | 11 GB |
| Hy4 Preview 770B-A49B | 90 KB | 2.82 GB | 11 GB |
| GLM-5.3 | 90 KB | 2.82 GB | 11 GB |
| GLM-5.2 | 90 KB | 2.82 GB | 11 GB |
| Qwen3.8 2.4T-A95B | 92 KB | 2.88 GB | 12 GB |
| Qwen3-Coder 30B-A3B | 96 KB | 3.00 GB | 12 GB |
| IQuest-Q1 320B-A15B | 100 KB | 4.23 GB | 14 GB |
| MiniMax M3 | 120 KB | 3.75 GB | 15 GB |
| DeepSeek V4 Pro | 122 KB | 3.81 GB | 15 GB |
| Llama 3.1 8B | 128 KB | 4.00 GB | 16 GB |
| Granite 4.2 8B | 160 KB | 5.00 GB | 20 GB |
| K2-Horizon MoVA 36B-A4B | 192 KB | 6.00 GB | 24 GB |
| MiniMax M2.7 | 248 KB | 7.75 GB | 31 GB |
| Granite 4.2 30B | 256 KB | 8.00 GB | 32 GB |
| Llama 3.1 70B | 320 KB | 10.0 GB | 40 GB |
| Mistral Medium 3.5 128B | 352 KB | 11.0 GB | 44 GB |
DeepSeek V4 also shares and compresses its cache across layers, which is not modelled here, so its figures are upper
bounds. Engines add their own margins: llama.cpp reserves the cache for the full context when it starts, and vLLM
fills whatever memory the weights leave. When you leave out -c, llama-server's --fit chooses that context for you:
how it does, and why some September 2026 builds picked 828,160 tokens.
To add the cache to the weights for a model, precision and context of your own, use the LLM VRAM Calculator. The 32K cache of every tracked model, ranked smallest first, is in the 2026 Local LLM VRAM Report (with a CSV).
Model numbers read from Hugging Face on .