The wall on long context was never quality. It was the cost of attention.
A modern Transformer's attention (the step where each token looks back at every earlier token) costs work that grows with the square of the context length, and it must keep a KV cache (the stored key/value vectors of every past token) that grows linearly. Push to a million tokens and both blow up — so ultra-long context stayed a stunt, not a daily mode.
DeepSeek-V4 attacks the cost side head-on. Before attention ever
looks at the past, it compresses the KV cache along the sequence —
squashing many tokens into one cache entry — using two complementary
schemes (CSA and HCA). At a one-million-token
context, V4-Pro then spends only 27% of the per-token FLOPs and
10% of the KV cache of its predecessor V3.2, while still matching
or beating it on quality.
Don't make attention cheaper by attending to less detail. Shrink what attention has to hold, before it ever looks.
The wall
Why a million-token context was a stunt, not a setting.
Step 1 · The black box & the prize
A model you can feed a million tokens — and it answers cheaply.
Here's the whole story in one picture. You hand the model a giant input — say an entire codebase plus a stack of design docs, about a million tokens (the word-pieces a model reads) — and ask a question. A label, a patch, an answer comes out. The box is DeepSeek-V4, a Mixture-of-Experts (MoE) model: only a small slice of its parameters fires per token. This box, and this million-token prompt, follow us through all ten steps.
The series ships in two sizes. V4-Pro is 1.6T total parameters with 49B active per token; V4-Flash is 284B total / 13B active. Both are pre-trained on more than 32T tokens (Pro on 33T) and natively support a 1M-token context. At that length, even the larger V4-Pro costs only a sliver of V3.2 — and V4-Flash drops further, to 10% of the FLOPs and 7% of the cache.
From the abstract: “In the one-million-token context setting, DeepSeek-V4-Pro requires only 27% of single-token inference FLOPs and 10% of KV cache compared with DeepSeek-V3.2.”
Step 2 · Why long context is so expensive
Each new token must look at — and store — every token before it.
You've seen the box win on cost. Before we open it, sit with the problem it solves: where does the bill for long context actually come from?
In standard attention, generating one new token requires comparing its query against the key of every earlier token. Read 1,000 tokens, that's ~1,000 comparisons per new token; read a million, that's a million. The compute per generated token grows linearly with the context already seen — and over a whole sequence that's the famous quadratic cost (work proportional to length squared).
There's a second, sneakier bill: the KV cache. To avoid recomputing the past on every step, the model stores each earlier token's key and value vectors. That store grows one entry per token — so at a million tokens it can swell to tens of gigabytes of fast memory per request, which is what really caps how long a context you can afford to serve.
You can't just attend to fewer tokens — the model would go blind to most of its own context. The trick has to keep the information reachable while shrinking what attention physically holds and scans.
Two compressions
Squash the cache first — then attend. This is the heart of V4.
Step 3 · The one move
Merge a run of tokens into a single cache entry — before attention looks.
We just saw both bills are driven by the number of cache entries. So the move is simple to state: have fewer entries.
Instead of keeping one KV entry per token, V4 takes every m
consecutive tokens and compresses them into one summary entry,
using a small learned, softmax-weighted blend of those tokens. A
sequence of length n becomes roughly n / m
cache entries. Attention then runs over the compressed entries, not the
raw tokens — so both the comparisons and the stored cache shrink by the
same factor m.
That's the whole idea. The next two steps are just the two recipes V4 uses to do this compression — one gentle and selective (CSA), one aggressive but complete (HCA) — and why it interleaves both.
Step 4 · CSA — compress, then select
Compress gently (m = 4), then attend to only the top-k summaries that matter.
Step 3 gave us summary entries. Compressed Sparse Attention (CSA) uses a light compression and then adds a second saving on top: sparsity.
CSA first compresses gently — every m = 4 tokens into one
summary (so 1M tokens → 250K summaries). Then a tiny, fast scorer called
the lightning indexer ranks those summaries for the current query
and a top-k selector keeps only the best
k (V4-Pro uses k = 1024; Flash uses 512). Core attention
runs over just those k — the rest are skipped entirely.
A small sliding window of the most recent raw
tokens is added back so nearby detail isn't lost.
Drag the context length and watch how few entries attention actually scans.
What to notice: as the context grows, the raw count explodes and the compressed count grows with it — but the number attention scans stops at k. Beyond ~4K tokens, CSA's cost is essentially flat. Counts are illustrative; k and m are V4-Pro's real settings.
Interactive disabled — defaults shown: 1M tokens → 250K summaries → 1,024 attended.
Compression alone shrinks cost by the factor m. Top-k selection caps the
comparisons at a fixed k no matter how long the context
gets — so attention work stops growing once the context is long enough.
Step 5 · HCA — compress hard, keep dense
Crush every 128 tokens into one — then look at all of them.
CSA compressed lightly and skipped most entries. Heavily Compressed Attention (HCA) takes the opposite trade: compress brutally, but attend to everything that's left.
HCA consolidates every m′ = 128 tokens into a single
summary entry — 32× harder than CSA's m = 4. After that crush, so few
entries remain that V4 can just run dense attention over all of
them, with no top-k selector at all. The win comes entirely from the
heavy compression; the simplicity (no sparse selection) keeps it cheap
and stable. Like CSA, it keeps a small sliding window of recent raw
tokens for local detail.
Step 6 · The hybrid
Interleave CSA and HCA layers — the model gets both kinds of memory.
Now we have two attention recipes. V4 doesn't choose one — it alternates them layer by layer.
After the first couple of layers (pure sliding-window attention to lock in local structure), V4 stacks CSA and HCA layers in an interleaved pattern. CSA layers give fine, selectable detail; HCA layers give a cheap, complete bird's-eye view of the whole context. Together with the per-token RoPE (rotary position encoding, telling tokens how far apart they are) and an attention sink (a learned slot that lets a head choose to attend to almost nothing), the hybrid keeps attention cost bounded as the context grows.
Against a common BF16 GQA8 baseline (head dimension 128), the hybrid cuts the KV cache to about 2% of baseline at a 1M-token context — and even versus the already-efficient V3.2, to 10%.
Step 7 · mHC — keeping the signal stable
Constrain the residual mix so a 61-layer stack never blows up.
With attention efficient, the second upgrade is on the residual path you saw threading the stack — the lane that carries each block's input straight across.
Hyper-Connections (HC) widen that residual
lane into several parallel streams and learn how to mix them. It helps —
but stacking many such layers tends to blow up numerically.
V4's fix, Manifold-Constrained Hyper-Connections (mHC), forces the
mixing matrix B to be doubly
stochastic (every row and column sums to 1, all entries ≥ 0),
projected there by the Sinkhorn–Knopp algorithm. That guarantees its
spectral norm (the most it can stretch any
vector) is ≤ 1, so the residual transform is non-expansive: it
can never amplify the signal, only redistribute it. Multiply many such
matrices and the result stays well-behaved — stable to any depth.
Step 8 · Training it cheaply
A faster optimizer (Muon) and 4-bit expert weights (FP4).
Architecture done. Two training-side choices let a 1.6T-parameter model train and serve at this scale.
First, the Muon optimizer replaces most of Adam. Where Adam rescales each weight individually, Muon orthogonalizes the whole update matrix (via fast Newton–Schulz iterations) so all directions get a balanced step — giving faster convergence and steadier training. (Embeddings, norms and a few other modules still use AdamW.)
Second, the routed MoE expert weights — the bulk of the parameters — are trained and stored in FP4 (4-bit floating point) via quantization-aware training, slashing memory and, on future hardware, compute. The training itself was not painless: trillion-parameter MoE runs hit loss spikes traced to routing outliers, which the team tamed with two tricks (Anticipatory Routing and SwiGLU Clamping) that they note work empirically but aren't yet fully understood.
The authors are upfront: to minimize risk they kept many preliminarily-validated components, leaving the architecture “relatively complex” — and flag that some stabilizing tricks are effective but not yet principled. A preview report, not a final word.
The payoff
Does the cheap long context actually hold up? The numbers.
Step 9 · The efficiency curves
As context grows, V4's cost barely moves — V3.2's keeps climbing.
We've built the machine. Now compare its bill to V3.2's across context length — this is the chart from the paper's Figure 1, made draggable.
At short contexts the savings are modest; the further you push, the wider the gap. At a million tokens V4-Pro lands at 27% of V3.2's per-token FLOPs and 10% of its KV cache; V4-Flash, with fewer active parameters, reaches 10% of FLOPs and 7% of cache.
Drag the context length to see the relative cost of V4 against V3.2.
What to notice: the advantage widens with length — the mechanisms from Part B only pay off once the context is long. Percentages are the paper's reported endpoints at each length (V4-Pro vs V3.2); intermediate points are interpolated for the demo.
Interactive disabled — at 1M tokens, V4-Pro uses 27% of FLOPs and 10% of the KV cache of V3.2.
And it doesn't trade away quality — selected results
world knowledge · Pass@1
coding · Pass@1 (CoT)
science reasoning · Pass@1
1M-token retrieval · MMR
agentic coding · Acc
Scores are V4-Pro-Max (maximum reasoning-effort mode) from the report's evaluation tables. “Max” mode spends more reasoning tokens than the High / Non-Think modes.
Step 10 · How it was taught
Train domain specialists, then fold them into one model by imitation.
Efficiency and architecture explain the cost; one last piece explains the skills — V4's two-stage post-training.
First, specialist training: for each domain (math, code, agent, instruction-following) a separate expert is built — supervised fine-tuning to lay foundations, then reinforcement learning with GRPO (a reward-driven policy-optimization method) to sharpen it. Second, on-policy distillation: one unified model acts as a student, generating its own answers and learning to match the specialist teachers on them — folding many narrow experts into a single generalist. Notably, this replaced V3.2's mixed-RL stage entirely.
What is the single core trick of DeepSeek-V4?
Compress the KV cache along the sequence — merge runs of tokens into summary entries — before attention reads it. Fewer entries means both fewer comparisons and a smaller cache, so cost stops exploding with context length.
How do CSA and HCA differ?
CSA compresses gently (every m = 4 tokens → 1) then keeps only the top-k summaries (sparse). HCA compresses hard (every m′ = 128 → 1) but attends to all of them (dense). V4 interleaves both across layers.
Why does compression help more at long context?
The savings scale with how much there is to compress. At short lengths there's little to squash; at a million tokens, CSA's top-k caps the work at a fixed k and HCA's 128× crush shrinks the cache dramatically — so the gap to V3.2 widens with length.
What does mHC fix?
Plain Hyper-Connections become numerically unstable when stacked deep. mHC constrains the residual mixing matrix to be doubly stochastic, bounding its spectral norm at ≤ 1, so the residual transform is non-expansive and stable to any depth.
Is it strictly better than V3.2?
On efficiency, dramatically — 27%/10% of FLOPs/cache at 1M tokens. On quality, V4-Pro-Base beats V3.2-Base across most benchmarks. But it still trails frontier closed models on world knowledge by ~3–6 months, and the architecture is deliberately complex.
What is on-policy distillation here?
A single student model generates its own outputs and learns to match the domain-specialist teachers on those outputs (minimizing reverse-KL). It consolidates several narrow experts into one generalist, replacing V3.2's mixed-RL stage.
What it unlocks — a million-token context as a routine setting opens the door to longer test-time reasoning, large cross-document analysis, and long-horizon agentic workflows that previously couldn't fit, or couldn't be afforded, in a single context.
“This enables us to routinely support one-million-token contexts, thereby making long-horizon tasks and further test-time scaling more feasible.” — the abstract, DeepSeek-V4 technical report
Making the long context cheap, not just possible.
Plenty of models claimed a large context window. DeepSeek-V4's bet is different: not that a million tokens is possible, but that it can be routine — cheap enough to use every day. If that holds, the ceiling on what a model can reason over moves.
From MLA & DSA to compress-first
V4 extends DeepSeek's own line of attention efficiency — latent attention, then sparse attention — into compressing the cache along the sequence before attending. The pattern: shrink what attention holds, not what it can see.
Longer thinking, longer horizons
Cheap long context is the substrate for reasoning models that think for tens of thousands of tokens and agents that act over long horizons — both gated, until now, by attention's cost.
An open model near the frontier
V4-Pro-Max redefines the open-model state of the art and, internally, rivals closed leaders on agentic and long-context tasks — while staying open-weight, with the architecture published for the community to refine.
Compress the cache before you attend — and a million-token context stops being a stunt.