Million-token context memory used to be out of reach for almost everyone. Before 2022, one conversation of a million tokens needed over 130 TB of GPU memory on top of the model weights, roughly 1,700 H100s. DeepSeek-V4.1-Flash, released in September 2026, handles the same load in 890 MB. That is 150,000 times less, and it fits on nearly any GPU from the past decade.
That drop helps explain why long context windows are cheap to rent now, and why providers can hold a chat’s memory in storage and discount repeated text.
Where the memory goes
Most of the memory sits in attention. A new token builds a query, checks it against the key of every token before it, and gets a relevance score for each. Those scores then weight the earlier tokens’ values. Layers run many heads side by side, each trained to pick up something different.
The baseline is Meta’s Llama 1 65B: 80 layers, 64 heads per layer, and keys and values of 128 numbers at 2 bytes each. Cache size is four factors multiplied: caching layers, entries per token, numbers per entry, and bytes per number. For Llama 1 that works out to 2.5 MB a token, or 2.5 TB for a million.
The free cut: FlashAttention
Back then the cache was the smaller issue. The bigger one was the full score table. A million tokens squared gives about 1.1 trillion scores, 2 TB per head and 128 TB across 64 heads. With the cache, that totals 130.5 TB.
FlashAttention, by Tri Dao and colleagues in 2022, avoids storing the table in main GPU memory by working on small tiles in fast on-chip memory. The math is unchanged, so outputs match and no model needed retraining. Memory dropped 52 times to 2.5 TB, still about 32 H100s for one chat.
Sharing and compressing keys and values
Every later cut alters the model itself. Noam Shazeer’s 2019 multi-query attention had every head share a single key and value, which hurt quality. Google’s 2023 grouped-query attention found a middle path with several groups. Llama 2 70B uses 8, so an entry falls from 16,384 numbers to 2,048 and a million tokens fit in 320 GB.
DeepSeek’s 2024 V2 paper introduced multi-head latent attention. Every head’s keys and values derive from the same token vector, so the model stores a compressed version and rebuilds per-head keys and values on demand. DeepSeek-V3 squeezes 7,168 numbers into 512 and adds 64 for position, so an entry has 576 numbers. A million tokens then take 68.6 GB, small enough for one H100.
Fewer bits and fewer tokens
Attention doesn’t need full precision, so DeepSeek-V3.2 (late 2025) saves latents in 8 bits, shrinking an entry from 1,152 to 656 bytes. It also brought in DeepSeek Sparse Attention, where each token consults only the 2,048 most relevant earlier ones. The indexer choosing them needs a small key per token, adding back 8 GB. The total came to 46.9 GB.
DeepSeek-V4 (April 2026, 1M-token context) stores fewer entries than it has tokens. In some layers, four neighboring tokens are averaged into one entry, and in others 128 are. Recent text keeps its detail: each layer also reads the last 128 tokens unmerged. All 64 heads share a single 512-number vector as both key and value. V4-Flash needs 3.4 GB for a million tokens, almost 14 times less than V3.2.
Fewer layers that cache
V4-Flash builds a cache in 41 layers. V4.1-Flash does so in four, and the remaining layers reuse them: each of three lower-half caches serves six layers, and one cache serves the entire upper half.
With so few caches to pay for, V4.1 can afford more detail. Lower-half caches merge just 2 tokens per entry rather than 4, and the upper-half cache keeps one entry per token. Precision goes down from 8 bits to 4, and the model is trained with that 4-bit cache so its weights adjust. The total is 890 MB, around 1% of an H100.
What it changes and what comes next
The cache alone shrank 2,900 times. Including the score table that FlashAttention eliminated, the overall reduction is 150,000 times. Other labs use some of the same ideas. GLM-5, Kimi K2 and Mistral Large 4 use multi-head latent attention. Google’s Gemma models mix sliding-window layers with a few full ones, and Qwen3-Next and Kimi Linear replace most attention layers with linear attention, whose memory doesn’t grow with the conversation.
The size also changes provider behavior. At 2.5 TB, a provider had to free a cache as soon as a chat went quiet. At 890 MB it is a file that can be written to an SSD or streamed across a data center network. No standard set of techniques exists yet, and ideas that failed in 2019 for hurting quality are back in 2026.
Source: three.dev