KV cache explained

While it writes, a model keeps the keys and values of every earlier token so it does not recompute them. That KV cache grows with the conversation: Llama 3.1 8B needs 128 KB per token in FP16, which is 16.0 GB at 128K tokens, more than its 4.52 GB of Q4_K_M weights.

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

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
Nemotron 3 Super 120B-A12B 8 KB 256 MB 1.0 GB
Gemma 4 12B 8 KB 576 MB 1.3 GB
Gemma 4 26B-A4B 10 KB 520 MB 1.4 GB
GLM-5.3 Flash 12 KB 396 MB 1.5 GB
Muse Glimmer 30B 13 KB 494 MB 1.7 GB
Nemotron 3 Nano 4B 16 KB 512 MB 2.0 GB
Gemma 4 E4B 16 KB 532 MB 2.0 GB
Qwen3.6 35B-A3B 20 KB 640 MB 2.5 GB
MiMo V2.6 Flash 23 KB 744 MB 2.8 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 771 MB 3.0 GB
Kimi K3 27 KB 864 MB 3.4 GB
Qwen3.5 9B 32 KB 1.00 GB 4.0 GB
gpt-oss-120b 36 KB 1.13 GB 4.5 GB
MiniCPM5 2B 42 KB 1.31 GB 5.3 GB
Xing 4.0 29B-A4B 45 KB 1.41 GB 5.6 GB
Gemma 4 31B 40 KB 2.03 GB 5.8 GB
MiMo V2.6 Pro 50 KB 1.60 GB 6.3 GB
GLM-4.7 Flash 53 KB 1.65 GB 6.6 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 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
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
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
MiniMax M2.7 248 KB 7.75 GB 31 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.

To add the cache to the weights for a model, precision and context of your own, use the LLM VRAM Calculator.

Model numbers read from Hugging Face on .