DeepSeek's Papers and Playbook (AI Engg #18)
In January 2025 an unknown Chinese lab released an open model that matched frontier closed models — trained, it claimed, for a fraction of the cost. By April 2026 the same lab was shipping a 1.6T-parameter model with million-token context as the default. DeepSeek did not get there with one trick but with a stack of them, each published: fine-grained MoE, latent attention, multi-token prediction, FP8 training, pure-RL reasoning, distillation, and sparse attention — all open weights.
This chapter is the eighteenth part of the AI Engineering course. It walks the paper trail from DeepSeekMoE to V4, explains each innovation tightly enough to use, and extracts the playbook: efficiency as strategy, openness as distribution. Sources: the DeepSeek technical reports (V2, V3, R1, V4, V4.1-Flash), the VectifyAI/PageIndex-era community analyses, Epoch AI, Sebastian Raschka’s tours, and 2026 coverage of the V4/R2 releases.
The thesis: efficiency compounds
Every DeepSeek paper asks the same question: where is the waste, and what structure removes it? KV cache, idle experts, one-token-at-a-time prediction, RLHF’s learned reward model, dense attention over a million tokens — each got a paper and a mechanism. Stacked, they turn a small lab (reportedly export-restricted GPUs, later Huawei Ascend 910B for R2 training) into a frontier contender.
\[ \text{frontier quality} \approx \text{dense model} \times \prod \text{efficiency structures} \]
\begin{tikzpicture}[font=\rmfamily, >=stealth,
b/.style={draw, thick, rounded corners=4pt, minimum width=2.1cm, minimum height=0.66cm, font=\rmfamily\small, align=center},
a/.style={->, thick}]
\node[b, fill=blue!10] (m) at (-4.4,0) {MoE};
\node[b, fill=blue!10] (a) at (-2.2,0) {MLA};
\node[b, fill=orange!15] (p) at (0,0) {MTP + FP8};
\node[b, fill=orange!15] (r) at (2.2,0) {GRPO reasoning};
\node[b, fill=green!12] (s) at (4.4,0) {sparse attn};
\draw[a] (m) -- (a); \draw[a] (a) -- (p); \draw[a] (p) -- (r); \draw[a] (r) -- (s);
\end{tikzpicture}
1. DeepSeekMoE: many small experts, some shared
A Mixture-of-Experts layer replaces one big FFN with \(N\) small ones plus a router that picks \(k\) per token. DeepSeek’s version (early 2024, into V2/V3) adds two twists:
- Fine-grained experts. Many more, much smaller experts (V3: 256 total, 8 active per token) with a shared expert that always runs and absorbs common knowledge — routed experts specialise instead of duplicating basics.
- Auxiliary-loss-free load balancing. Instead of a balancing loss that fights the language objective, a per-expert bias nudges routing and is updated from observed load — the main loss stays clean. R1-era write-ups credit this with removing a whole class of training instability.
\[ y = E_{\text{shared}}(x) + \sum_{i \in \mathrm{top}_k} g_i\, E_i(x), \qquad k \ll N \]
V3’s headline numbers fall out directly: 671B total, 37B active per token — frontier capacity at a fraction of the FLOPs.
2. MLA: compress the KV cache into a latent
Autoregressive inference is memory-bound: every token attends to a growing KV cache. Multi-head Latent Attention (V2, 2024) compresses keys and values into one low-rank latent vector cached instead of full heads, then reconstructs per-head K/V on the fly with learned projections.
\[ \mathbf{c}_t = W_c\, \mathbf{h}_t \;\;(\text{tiny}), \qquad K_h, V_h = W^K_h \mathbf{c}_t,\; W^V_h \mathbf{c}_t \]
Cache one small \(\mathbf{c}_t\) per token instead of \(H\) key/value pairs: reports cite order-of-magnitude KV savings (the V4.1-Flash line pushes this to extremes — roughly 390 KB → under 1 KB per token in community retellings), which is what makes long context deployable, not just trainable. V4-Pro at 1M tokens needs only ~10% of V3.2’s KV cache and ~27% of its per-token FLOPs.
# the idea in one sketch: cache the latent, expand per head at use
c = compress(hidden) # [d_latent], cached across steps
K = [Wk[h] @ c for h in heads]
V = [Wv[h] @ c for h in heads]
out = attention(Q, K, V) # standard attention over reconstructions
3. V3 engineering: MTP, FP8, and cheap training
DeepSeek-V3 (Dec 2024) paired MLA + DeepSeekMoE with three training/inference wins:
- Multi-Token Prediction (MTP). Extra heads predict 2+ tokens ahead during training (denser signal per sequence) and double as a speculative decoder at inference — draft with MTP, verify with the main model.
- FP8 mixed precision. Nearly the whole training run in 8-bit floats with careful scaling — less memory, faster matmuls, no accuracy cliff. The report reads as a cookbook for low-budget frontier training.
- DualPipe + compute-communication overlap. Engineering, not architecture — but it is why the claimed training bill (single-digit millions of dollars) was even plausible.
4. R1: reasoning from pure RL and the “aha moment”
DeepSeek-R1-Zero (Jan 2025) skipped supervised fine-tuning entirely: start from V3-Base, apply large-scale RL with verifiable rewards (math/code checkers, not a learned reward model), and watch reasoning emerge — including the famous aha moment, where the model learns to re-check, backtrack, and allocate more thinking time mid-solution.
The algorithm is GRPO (Group Relative Policy Optimization): sample a group of completions per prompt, reward the verifiable ones, and update toward the group’s best — no critic network, no human preferences to overfit:
\[ \mathcal{L}_{\text{GRPO}} \;\propto\; -\mathbb{E}\left[ \hat{A}_{\text{group}}\, \log \pi_\theta \right], \qquad \hat{A} = \frac{r - \bar{r}_{\text{group}}}{\sigma_{\text{group}}} \]
R1 proper adds a four-stage pipeline (cold-start SFT → reasoning RL → rejection-sampled SFT → all-scenario RL) to make Zero’s raw reasoning readable and helpful — then distills it into small dense models (1.5B–70B), giving the community reasoning models that run on one GPU. That distillation step is arguably the largest knowledge transfer in open source.
5. V4 (2026): sparse attention meets million-token default
The V4 series (April 2026 reports; Pro 1.6T total / 49B active, Flash 284B total) keeps MLA + MoE and attacks the last quadratic wall — attention itself — with hybrid sparse attention (compressed + heavily-compressed attention paths), so 1M-token context ships as the default rather than a max-effort mode. Active parameters per token reportedly fall versus V3 (~32B) even as total parameters grow ~50%: capacity up, cost per token down.
The January 2026 training-methods paper (manifold-constrained communication) and the Ascend-910B R2 training reports point the same way: DeepSeek’s moat is now infrastructure that scales under constraint — share richer signals between workers, stay stable, and train through hardware you were not supposed to win on.
\begin{tikzpicture}[font=\rmfamily, >=stealth,
b/.style={draw, thick, rounded corners=3pt, minimum width=2.3cm, minimum height=0.66cm, font=\rmfamily\small, align=center},
a/.style={->, thick}]
\node[b, fill=blue!10] (d) at (0,0) {1M-token doc};
\node[b, fill=orange!15] (c) at (0,-1.2) {sparse shortlist};
\node[b, fill=green!12] (f) at (0,-2.4) {full read: shortlist};
\draw[a] (d) -- (c); \draw[a] (c) -- (f);
\node[font=\rmfamily\small, text=black!60, anchor=west] at (1.4,-1.2) {cheap pass picks};
\node[font=\rmfamily\small, text=black!60, anchor=west] at (1.4,-2.4) {heavy pass reasons};
\end{tikzpicture}
Beyond text: Janus, DeepSeek-OCR, and agents
The same efficiency instinct spread sideways: Janus-family vision-language models, DeepSeek-OCR (compress a page into visual tokens for document agents), and a V4 generation explicitly tuned for coding agents and long-horizon software work — the segment where million-token context plus cheap reasoning actually changes what an agent can hold in its head.
The playbook for an AI engineer
What transfers, even if you never train a model:
- Route capacity, don’t average it. MoE’s lesson generalises: shared base + specialised heads, in models and in systems (Chapter 5’s routers, Chapter 17’s hybrid retrieval).
- Cache the latent, not the surface. MLA is an instance of a universal move — store the compressed state, expand at use (KV caches, session state, retrieval summaries).
- Reward what you can verify. GRPO works because math and tests are checkable. Wherever your pipeline has verifiable signals (tests, citations resolving, tool success), prefer them over learned judges.
- Distill the expensive into the deployable. Frontier reasoning → small dense student is the highest-ROI pattern in open source right now; your agent’s router (Chapter 5) plus a distilled reasoner beats one giant call.
- Treat openness as distribution. Publishing weights + papers did not cost DeepSeek its lead — it bought the ecosystem, the benchmarks, and the hiring pipeline. Default to open artefacts inside your org for the same reason.
Pitfalls
- Reading the cost claims naively. The famous training bill excludes prior research, data pipelines, and personnel — replicate the methods, not the budget line.
- Deploying MoE on the wrong hardware. Sparse experts punish naive serving; you need expert parallelism and high-bandwidth interconnect or latency spikes.
- RL without verifiable rewards. GRPO needs ground truth to compare against; pure RL on vibes is how models learn to game the metric.
- Chasing the model instead of the mechanism. V3 → V3.2 → V4 → V4.1-Flash is a treadmill; MLA, MoE balancing, MTP, and GRPO are durable.
- Ignoring the geopolitics. Export controls, Ascend hardware, and licensing (MIT vs custom) shape what you can run where — check before standardising.
Name DeepSeek’s four core efficiency mechanisms and what waste each removes. Why did R1’s training produce an “aha moment”?
ASolution
DeepSeekMoE (idle capacity — activate 8⁄256 experts plus a shared one), MLA (KV cache — cache a low-rank latent, not full heads), MTP + FP8 (weak training signal and memory — predict ahead, compute in 8-bit), and sparse attention in V4 (quadratic attention over 1M tokens). R1-Zero used pure RL with verifiable rewards and GRPO, so longer chains that self-correct scored higher — the model discovered re-checking and backtracking (“aha”) because the reward selected for it, with no SFT imitating reasoning style.