DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence
Read first: DeepSeek-V3 Technical Report · Muon: An optimizer for hidden layers in neural networks
TL;DR. DeepSeek-V4 is two MoE models: V4-Pro (1.6T total, 49B active) and V4-Flash (284B total, 13B active). Both handle 1M tokens of context. Most layers attend to a compressed KV cache instead of the raw one. CSA compresses every 4 tokens into one entry and picks the top-k entries with a lightning indexer. HCA compresses every 128 tokens and attends densely. At 1M tokens, V4-Pro needs 27% of V3.2’s per-token FLOPs and 10% of its KV cache. V4 also widens the residual stream (mHC), trains most weights with Muon, and replaces the mixed RL stage with on-policy distillation from more than ten specialist teachers.
Why it matters now. Deep-research agents read many documents and keep long tool histories, so KV cache memory is what limits them. V4 attacks that cost inside the model. Its paper also runs a direct agentic-search versus RAG comparison on a production system (§5.4.2), which is rare. For IR, the lightning indexer is effectively a learned first-stage retriever that runs inside every CSA layer.
Key idea
Section titled “Key idea”Compressed attention. CSA groups each run of tokens into one KV entry, using learned softmax weights over overlapping windows. A lightning indexer then scores each compressed entry for query :
and core attention uses only the top- entries ( for Flash, for Pro). Attention is shared-KV MQA with head dim 512: each entry serves as both key and value. HCA uses with no overlap and dense attention over all compressed entries. Both add a 128-token sliding-window branch for local detail, partial RoPE on 64 dims, RMSNorm on queries and KV entries, and learned attention-sink logits.
Manifold-constrained hyper-connections (mHC). The residual is widened to streams :
where is pushed onto the doubly stochastic matrices by 20 Sinkhorn–Knopp steps, so its spectral norm stays at most 1 however many layers are stacked.
Key results
Section titled “Key results”- Efficiency (§1, §2.3.4). At 1M context, Pro uses 27% of V3.2’s single-token FLOPs and 10% of its KV cache. Flash uses 10% and 7%. The KV cache is about 2% of a BF16 GQA8 baseline.
- Long context (Table 7). On MRCR at 1M, Pro scores 44.7 (non-think), 83.3 (High) and 83.5 (Max). Flash scores 37.5, 76.9 and 78.7. Retrieval is stable up to 128K and degrades beyond it.
- Frontier comparison (Table 6, Pro-Max). MRCR 1M: 83.5 (Gemini-3.1-Pro 76.3, Opus-4.6 92.9). CorpusQA 1M: 62.0 (53.8, 71.7). BrowseComp: 83.4, against Gemini 85.9, Opus 83.7, GPT-5.4 82.7 and Kimi-K2.6 83.2. MMLU-Pro: 87.5.
- Search agent. BrowseComp is 73.2 for Flash-Max and 83.4 for Pro-Max. The harness allows up to 500 steps and 512K context. In production (Tables 9–10), agentic search beats RAG in 61.7% of 869 pairwise judgments, against 18.3% for RAG. It costs 16.2 tool calls and about 30% more prefill tokens.
What transferred, and from where
Section titled “What transferred, and from where”V4 is a clear example of ideas moving between labs. Attention sinks come from StreamingLLM and gpt-oss. Muon at scale follows Moonshot’s work (Liu et al., 2025), which also trained Kimi K2, but V4 drops the QK-Clip that Kimi needed. SwiGLU clamping also appears in gpt-oss. The sparse-attention route of V3.2 (DSA) was picked up by Qwen3.8’s QSA. V4.1-Flash later builds on CSA and mHC, and MAI-Thinking-1 uses V4-Pro as a pretraining comparison point.
Limitations & open questions
Section titled “Limitations & open questions”- The authors call the architecture complex. They say the two stability fixes (Anticipatory Routing, SwiGLU clamping) work but are not well understood (§4.2.3, §6).
- MRCR accuracy falls beyond 128K, and Opus-4.6 still leads at 1M. Compression is not lossless for retrieval.
- Many evaluations are internal (search win rates, CorpusQA). Small differences on public leaderboards (BrowseComp ±1–2 points) are within harness variance.
- The data mix is described only qualitatively. Token-level sources are not released.
Connections
Section titled “Connections”- Builds on DeepSeek-V3, DeepSeekMoE, aux-loss-free balancing and multi-token prediction. It replaces MLA with compressed attention.
- Sparse attention lineage: Native Sparse Attention → V3.2 DSA → CSA → Qwen3.8-Flash-Next QSA and DeepSeek-V4.1-Flash CSA2.
- Optimizer: Muon, AdamW, FP8 training. Stability via MuonClip in Kimi K2; sinks and clamping in gpt-oss.
- Long-context evaluation: RULER, context rot, GQA as the KV baseline.
- Search agents: BrowseComp, BrowseComp-Plus. Post-training: PPO (GRPO is a diff of it), knowledge distillation.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
Estimate the per-layer KV cache at 1M tokens for (a) a BF16 GQA layer with 8 KV heads of dimension 128 and (b) a V4 CSA layer and a V4 HCA layer. Assume one shared 512-dim KV entry per compressed block, the 64 RoPE dims stored in BF16 and the other 448 dims in FP8. Is your answer consistent with the paper's claim of about 2% of the GQA8 baseline?
What a strong answer covers
- GQA8 baseline: K and V, 8 heads × 128 dims × 2 bytes = 4,096 bytes per token per layer, so about 4.1 GB per layer at 10^6 tokens.
- One V4 entry: 448 × 1 B + 64 × 2 B = 576 bytes. Shared-KV MQA stores the entry once; it serves as both key and value.
- CSA (m = 4): 250,000 entries × 576 B ≈ 144 MB, about 3.5% of the baseline. HCA (m′ = 128): about 7,800 entries × 576 B ≈ 4.5 MB, about 0.1%.
- With CSA and HCA interleaved, the average is roughly 1.8%, close to the reported figure of about 2% (§2.3.4). The 128-token sliding-window branch and the indexer keys add only a little on top.
- The compression comes from three places: sequence compression (m, m′), a single shared KV head instead of 8 K plus 8 V heads, and FP8 storage.
- Mechanism
mHC widens the residual stream to n = 4 copies and mixes them with a matrix B_l at every layer. Why do the authors project B_l onto doubly stochastic matrices with Sinkhorn–Knopp instead of leaving it free, as in the original Hyper-Connections? Reason about the product of B over 61 layers.
What a strong answer covers
- The residual signal after L layers is multiplied by the product B_L … B_1. If the B are unconstrained, their spectral norms can exceed 1 and the product can blow up or vanish with depth.
- A doubly stochastic matrix has spectral norm at most 1, and the set is closed under multiplication. Every partial product is therefore also doubly stochastic and bounded.
- Rows and columns summing to 1 means the mix only redistributes mass between the 4 streams. It keeps the identity-like path that makes pre-norm residual networks trainable.
- Sinkhorn–Knopp (20 iterations, starting from exp of the raw logits) is a cheap, differentiable way to approximate this projection.
- A and C are gated by sigmoids (C scaled by 2), so read and write stay bounded as well.
- Critique
Section 4.2.3 reports two fixes for loss spikes, Anticipatory Routing and SwiGLU clamping, and the authors say they do not fully understand why they work. Propose a hypothesis for each and an experiment that could falsify it at moderate scale.
What a strong answer covers
- Anticipatory Routing computes routing with slightly stale parameters θ at t − Δt. One hypothesis is that it breaks a feedback loop where routing and expert weights update together and amplify a load imbalance.
- Falsifier: in a smaller MoE at a raised learning rate, compare spike rates with routing from stale weights, from current weights with the router frozen for Δt steps, and with random routing delays. If only staleness helps, the feedback-loop story is supported.
- SwiGLU clamping (linear part in [−10, 10], gate capped at 10) bounds activation outliers. Hypothesis: spikes start from rare huge FFN activations, which FP8 or FP4 paths then amplify.
- Falsifier: log the maximum FFN activation before each spike. Then clamp at different thresholds and in BF16 against low precision. If spikes persist with bounded activations, the outlier explanation fails.
- Anticipatory Routing costs about 20% extra wall-clock when active and is only switched on after a spike, so its benefit should be measured per unit of compute.
- Design
You are building a deep-research agent for a BrowseComp-Plus-style corpus. You can (a) dump many retrieved documents into V4's 1M context, or (b) run an agentic search loop with a smaller per-step context. Use the paper's §5.4 search results and its MRCR curve to argue for a design. What would you measure?
What a strong answer covers
- Table 9 (869 queries): agentic search wins 61.7% of pairwise judgments against RAG, which wins 18.3%. The gap is larger on hard subjective questions.
- Table 10: agentic search averages 16.2 (mostly parallel) tool calls and 13,649 prefill tokens, against 10,453 for RAG. That is only about 30% more prefill.
- MRCR retrieval is stable up to 128K and degrades after it (Pro-Max still scores 83.5 at 1M), so a 1M dump is not free of position and distractor effects.
- Suggested design: agentic search with moderate context and V4's retained reasoning history. Use the long context for whole documents, not for a flat top-1000 list.
- Measure evidence recall against gold documents, answer accuracy, tokens and tool calls per query, and accuracy as a function of context length on the same queries.
- Connect
Place CSA's lightning indexer next to DSA in DeepSeek-V3.2, NSA and Qwen3.8's QSA. What does each score, at what granularity, and which one is closest to a learned first-stage retriever?
What a strong answer covers
- DSA (V3.2): a lightning indexer scores every previous token, I = Σ_h w_h · ReLU(q·k), and keeps the top-k tokens. Indexing cost is O(n²).
- CSA (V4): the same indexer scores compressed 4-token entries and keeps the top 512 (Flash) or 1024 (Pro), so the indexer runs over a sequence 4× shorter.
- QSA (Qwen3.8): average-pools keys into blocks of r = 4 before scoring, with 4 indexer query heads and a 2,048-token budget.
- NSA: combines compressed, selected and sliding branches with learned gates; selection is by blocks.
- All four act like a cheap first-stage scorer followed by exact attention over the shortlist, much like a sparse retriever followed by a reranker. Only the indexer's top-k decides what the model can see.
- Research idea
Propose a study that treats the CSA indexer as a retriever. How would you measure its recall of gold evidence inside a long context, and what would you change if recall is the bottleneck for long-context QA?
What a strong answer covers
- Build long contexts with gold passages at known positions, for example BrowseComp-Plus documents or RULER needles. Log which compressed entries the indexer keeps at each CSA layer.
- Metric: Recall@k of entries that overlap gold spans, per layer and against position. Relate it to answer accuracy and to the MRCR drop beyond 128K.
- Ablate top-k (512 against 1024), compression m, and FP4 against higher-precision indexer scores.
- If recall is low, try a larger k for late layers, a distillation loss that matches attention mass on gold spans, or retrieval-style hard-negative training of the indexer.