From First Principles: DeepSeek-V4.1-Flash Inference
How DeepSeek redesigned inference for million-token contexts: what an inference engine holds per token, where it holds it, and the moves V4.1 makes on both.
From First Principles: DeepSeek-V4.1-Flash Inference
We, as engineers, all know that the coding agents has become an important part of our lives and we use it everyday. Have you ever paid attention to the fact that an agentic coding session, at some point, is mostly re-reading? The chat log already holds the system prompt, the repository, and a few dozen tool outputs. A short message arrives (which is essentially the user's prompt), the model reads all of it, writes a few hundred tokens, calls a tool, and the tool's output comes back as the next short message. And just repeat. Contexts well past a hundred thousand tokens are routine in this loop, and a million is the ceiling this model is built to.
Two things cost money in that loop. Reading the new tokens is compute. Remembering the old tokens between reads is storage. Both grow with the length of the conversation, and for an open-weight model, whoever runs the inference pays both bills directly. That is why the inference infrastructure half of the DeepSeek report deserves the same attention as the architecture half.
The chart below is the storage bill, per token, across four generations of DeepSeek models. Read it at a million tokens: on DeepSeek-V4.1-Flash, the conversation's global KV cache occupies about 0.89 GB of GPU memory, excluding local-window state, model weights and other runtime overhead. On DeepSeek's first model, from November 2023, the same conversation would have needed about 390 GB. That is a 437× reduction in under three years, about 4× of it in this release, and it came with a model that scores higher than its predecessor rather than lower.
To see how, it helps to have a picture of what a server holds per token and where it holds it.
What an inference engine holds
Let's start with a standard GPT-style transformer. The transformer generates one token at a time (i.e. autoregressive), and to produce each new token, every layer's attention looks back at every earlier token. What it looks at is not the earlier tokens themselves but two vectors the layer computed for each of them, a key and a value. Without the cache, generating each new token would mean rerunning the prefix through the network, so the inference engine keeps them. Caching avoids that redundant prefix computation, though attention still reads the previous keys and values. That store is the KV cache: for each layer, for each token, one key and one value.
