R300 · Infrastructure for agents at scale › Inference providers and serving reliability

How the memory for a million tokens shrank 150,000 times

Read the original

Authors Ximo Guanter

kv-cacheattentioninferencelong-contextteaching

Source: Ximo Guanter (three.dev), "How the memory for a million tokens shrank 150,000 times" (2026-11-24). Found via TLDR Dev 2026-11-25. A good teaching piece: one running number, seven steps.

The chain

GPU memory to hold one million tokens of context, excluding model weights:

StepModelMemoryWhat changed
1Llama 1 65B, standard attention130.5 TB128 TB of attention scores plus 2.5 TB of KV cache, about 1,700 H100s
2+ FlashAttention2.5 TBNever materialise the score table; exact same output. The only free step
3Llama 2 70B, grouped-query attention320 GB8 KV head groups share keys and values
4DeepSeek-V3, multi-head latent attention68.6 GBCache a 512-number latent plus 64 position numbers per token; fits one H100
5DeepSeek-V3.2, 8-bit cache + sparse attention indexer46.9 GBQuantisation gives ~39 GB; the indexer that picks 2,048 tokens adds ~8 GB back
6DeepSeek-V4-Flash, merged tokens3.4 GBAlternate layers merge every 4 tokens or every 128 tokens into one entry
7DeepSeek-V4.1-Flash, cross-layer sharing + 4-bit cache890 MB40 layers read 4 caches; trained with the 4-bit cache in place

The headline 150,000x is 130.5 TB over 890 MB; the cache alone shrank about 2,900x.

What each step costs

Other families (GLM-5, Kimi K2 and Mistral Large 4 with MLA; Gemma's sliding-window hybrids; linear attention in Qwen3-Next and Kimi Linear) are out of scope.

Why it matters for a staff engineer

Long context is now a memory-design choice, not a fixed cost. At 890 MB per million tokens, one GPU can hold many long-context sessions at once, which is what makes cheap million-token agents and large prompt caches viable. But most of the savings from step 4 on are lossy and trained into the model, so the KV layout is tied to the model and the serving kernels, and old context is held less precisely than new. Two practical consequences: check that your serving stack has kernels for the model's cache format (see R283 on Hy4 and R271 on decode tuning), and do not assume a model recalls exact text from deep in a long context as well as it recalls recent text.

Connections

See R300 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.