FFN & MoE · January 2024
DeepSeekMoE
advanced
routing
Get sharper expert specialization than vanilla MoE by combining fine-grained expert segmentation with isolated shared experts that absorb the common-knowledge load.
§ 1 · Premise
Parameter scaling without FLOP scaling
A dense transformer with hidden size and FFN intermediate size spends FLOPs per token on the FFN. Doubling doubles both the parameter count and the per-token FLOPs — capacity and compute are welded together. Mixture-of-Experts (MoE) breaks that coupling. A Switch Transformer layer with expert FFNs of width and top- routing has times the FFN parameters but only times the per-token FFN FLOPs (Fedus et al., 2022, arXiv:2101.03961, §2). Holding or fixed, one can scale total parameters by an order of magnitude while keeping the FLOP budget of a much smaller dense model. This is the lever every modern frontier open-weights release pulls: Mixtral 8×7B at 47B total / 13B active (arXiv:2401.04088 §2.1), DeepSeek-V3 at 671B total / 37B active (arXiv:2412.19437 §2), Qwen3-Next 80B at 80B total / 3B active.
Two failure modes plague the vanilla recipe. First, coarse granularity: GShard (arXiv:2006.16668 §3.2) and Switch use a small expert count ( to ) with each expert sized to a full FFN. With of , the gate chooses among only expert combinations per token — coarse, and each expert must absorb a broad slice of input space. A single Mixtral expert is forced to cover Python syntax, German morphology, and basic arithmetic in the same parameters (arXiv:2401.04088 §3.4 reports per-domain routing distributions that are nearly uniform rather than peaked — consistent with experts that have not specialized). Second, redundant common knowledge: tokens that need basic linguistic competence (almost every token) route through different experts depending on minor surface features, so every expert ends up re-learning the same common weights. The auxiliary load-balancing loss compounds the problem by actively pushing the gate toward uniform routing even when uniformity is not what the task wants (arXiv:2101.03961 §2.2).
The lineage so far: Shazeer et al. (arXiv:1701.06538) introduced sparsely-gated MoE for LSTMs; GShard scaled it to transformers with the standard top-2 routing recipe; Switch Transformer pushed to top-1 to simplify dispatch and balance; Mixtral demonstrated the recipe at frontier open-weights quality with , top-2. All four share the same coarse granularity, leaving the specialization-vs-redundancy tension unresolved.
DeepSeekMoE (arXiv:2401.06066) makes two coupled changes to the layer — finer experts at higher top-, plus a small number of always-on shared experts — and shows in 2B / 16B / 145B ablations that the resulting layer reaches the loss of a vanilla MoE with roughly the activated compute.
DeepSeekMoE (arXiv:2401.06066) makes two coupled changes to the layer — finer experts at higher top-, plus a small number of always-on shared experts — and shows in 2B / 16B / 145B ablations that the resulting layer reaches the loss of a vanilla MoE with roughly the activated compute.
§ 2 · Derivation
From top-K MoE to fine-grained + shared
Start: vanilla top- MoE. Let be the input to the MoE layer for token (the post-attention residual stream), the number of routed experts, and the number activated per token. Each expert is a full-width FFN with intermediate size . The gate produces affinity scores over expert centroids , and the layer output is
Only of the are non-zero per token, so the per-token FFN FLOP cost is regardless of . Total FFN parameters are (two matrices per FFN, ignoring biases and the gate variant; SwiGLU adds a third). Activated parameters per token are . This is the form Switch Transformer (), GShard, and Mixtral () all instantiate.
Move 1: fine-grained expert segmentation. Replace each of the experts with slimmer copies whose intermediate size is . The new expert count is , and the top- is raised to . The layer becomes (DeepSeekMoE §3.1, Eq. 6–8):
The key invariant: activated parameters per token are unchanged. Each fine expert has intermediate size and so contributes parameters; of them fire; total activated , identical to (1). Total parameters are likewise unchanged at . What changes is the combinatorial flexibility of routing. Switch Transformer / GShard with of offers possible expert subsets; raising to of (i.e., ) offers subsets (arXiv:2401.06066 §3.1). The gate now has the addressing resolution to assign each narrow concept (Python syntax, German noun gender, basic arithmetic) to its own small expert.
Why not just raise without segmentation? Because that costs FLOPs linearly: top- of activates the FFN compute of top-. Segmentation buys finer routing at no FLOP increase.
Why not just raise without raising ? Adding more large experts at fixed shrinks the chance each expert gets enough tokens to train on, and does not give the gate more per-token addressing resolution (still picks of ). Segmentation gives finer per-token resolution.
Move 2: shared expert isolation. Reserve of the fine experts as shared: they bypass the gate and fire on every token. The remaining are routed, and the gate picks of them. The layer becomes (DeepSeekMoE §3.2, Eq. 9–11):
with as in (2) but with over the routed pool only. The activated parameter budget stays — same as vanilla — because we shifted of the activations from “routed and learned” to “always-on and shared.” Setting or is what production configurations use; the DeepSeek-V2 layer has (arXiv:2405.04434 §2.1), DeepSeek-V3 has (arXiv:2412.19437 §2).
Why a shared expert and not “just train the gate harder”? The argument is information-theoretic. Common-knowledge weights are needed by every token; any routing decision that sometimes sends a token away from those weights forces the gate to spend capacity re-learning them in multiple experts. Reserving experts that always fire removes the routing decision entirely for that fraction of the layer, freeing the routed experts to specialize on input-specific features. The probing study in §4 shows this matters: disabling the single shared expert in DeepSeekMoE 2B and replacing it with one extra routed slot raises Pile loss from to (arXiv:2401.06066 §4.5).
Load balance. Without intervention, the gate can collapse to a few favored experts. The paper adds two auxiliary losses (§3.3): an expert-level balance loss (Eq. 12) where is the fraction of tokens routed to expert and is the mean gate probability assigned to it, and a device-level balance loss (Eq. 15) that balances load across device groups rather than individual experts. Successor work (aux-loss-free MoE, DeepSeek-V3 §3.4) replaces both with a per-expert bias that floats up when an expert is under-loaded and down when over-loaded — gradient-free balancing at no expressivity cost.
Final budget. With routed experts and activated: total FFN params ; activated FFN params per token . The total/activated ratio is — the same lever as before — but the routing decision now happens at a finer grain over a larger pool.
§ 3 · Reference implementation
A DeepSeekMoE layer in sketch form
def deepseek_moe_layer(u, routed_experts, shared_experts, gate, K_r):
# u: [B, T, d]
# routed_experts: list of (mN - K_s) fine-grained FFNs, each d_ff/m wide
# shared_experts: list of K_s always-on fine-grained FFNs
# gate: linear d -> (mN - K_s); K_r = mK - K_s
# --- shared lane: every token sees every shared expert ---
h_shared = sum(f(u) for f in shared_experts) # [B, T, d]
# --- routed lane: top-K_r selection over the routed pool ---
scores = softmax(gate(u), dim=-1) # [B, T, mN - K_s]
topk_w, topk_idx = scores.topk(K_r, dim=-1) # [B, T, K_r], [B, T, K_r]
# the paper keeps raw softmax weights (no re-normalization); some variants renormalize
# dispatch: gather each token's K_r expert outputs and combine
h_routed = dispatch_and_combine(u, routed_experts, topk_idx, topk_w) # [B, T, d]
return u + h_shared + h_routed # residual add
dispatch_and_combine is the all-to-all permutation that groups tokens by chosen expert,
runs each expert on its assigned slice, and scatters the outputs back, weighted by topk_w.
The mechanics of that permutation are the engineering bulk of any MoE implementation but are
orthogonal to the algorithmic claim being illustrated here.
§ 4 · Empirical evidence
How much the two changes buy
2B-scale validation (Table 1). The introducing paper trains a B-total / B-active DeepSeekMoE configuration ( shared expert, routed at FFN width, top- routed) against a same-budget GShard 2B with standard-width experts at top-. On Pile validation loss DeepSeekMoE reaches versus GShard’s , and on downstream zero-shot benchmarks: HellaSwag vs , PIQA vs , ARC-challenge vs , TriviaQA vs (arXiv:2401.06066 Table 1, §4.1). Table 2 compares against a “GShard” baseline at B total / B activated — DeepSeekMoE 2B matches it roughly, meaning the recipe gets the loss of a 1.5-larger vanilla MoE at the same activated compute.
Expert specialization probes (§4.5). Two ablations isolate where the gain comes from. (a) Disable top routed experts at inference. The Pile loss curve when knocking out the highest- ranked routed experts rises faster for DeepSeekMoE than for GShard, indicating each routed expert in DeepSeekMoE is less replaceable by its peers — lower parameter redundancy. (b) Disable the shared expert. Setting while activating one extra routed slot raises Pile loss from to , a much larger jump than knocking out a routed expert. The shared expert holds high-value common-knowledge weights that routed experts cannot reproduce on demand (arXiv:2401.06066 §4.5).
16B-scale follow-through (Tables 3–4). The B-total / B-active DeepSeekMoE model, trained on 2T tokens, matches a fully dense DeepSeek 7B on Pile (BPB vs ) at of training FLOPs, and out-performs LLaMA-2 7B on majority of benchmarks at of LLaMA’s training compute, including HumanEval vs and GSM8K vs (arXiv:2401.06066 §5, Tables 3–4).
145B-scale extension (Table 6). A B-total / B-active DeepSeekMoE 145B trained on only B tokens reaches Pile loss versus DeepSeek 67B dense at , at of the dense FLOP budget; a half-activated variant at B active matches DeepSeek 67B at of compute (arXiv:2401.06066 §7, Table 6). MMLU lags ( vs ) — the paper attributes this to the smaller attention parameter count rather than the MoE recipe.
Production adoption. DeepSeek-V2 (236B total / 21B active) keeps the recipe with routed, shared, top- routing (arXiv:2405.04434 §2.1). DeepSeek-V3 (671B total / 37B active) scales to routed, shared, top- routing, and switches the balance mechanism to the aux-loss-free bias scheme; it reports a near-monotone improvement on downstream loss versus a same-FLOP V2 baseline (arXiv:2412.19437 §2, §3.4). DeepSeek-V2 §2.1 also runs an internal Mixtral-style baseline (8 large experts, top-2, same total parameters and same training tokens) and reports the DeepSeekMoE variant winning on validation loss by a non-trivial margin — the cleanest like-for-like Mixtral-vs-DeepSeekMoE comparison currently in the public literature. The recipe has since been adopted by GLM-4.5 (arXiv:2508.06471), MiniMax-01 (arXiv:2501.08313), Hunyuan-Large (arXiv:2411.02265 §3) and Qwen3-Next — independent adoptions but not independent ablations. No external peer-reviewed reproduction of the 2B-scale ablation has been published; the strongest external evidence remains the production scaling results above.
Adopted by
- DeepSeek V2 · DeepSeek-AI — 162 routed + 2 shared experts; top-6 routing; standard aux balance loss. [source]
- DeepSeek V3 · DeepSeek-AI — 256 routed experts + 1 shared expert per MoE layer; top-8 routing; aux-loss-free balancing on top. [source]
- MiniMax-Text-01 · MiniMax — 32 routed experts + 1 shared expert; top-2 routing. [source]
- MiniMax-M1 · MiniMax — Same shared + routed expert layout as MiniMax-Text-01 (32 routed + 1 shared, top-2). [source]
- Hunyuan-Large 389B · Tencent — 1 shared expert + 16 specialized experts with top-1 routing; specialists train at ~0.31× the shared expert's learning rate (technical report §3). [source]
- GLM-4.5 · Zhipu AI — 160 routed experts + 1 shared expert per MoE layer; top-8 routing; the shared-expert pattern carried over from the DeepSeek-MoE line. [source]
- Kimi Linear 48B-A3B · Moonshot AI — 256 routed experts + 1 shared expert per MoE layer; top-8 routing with a sigmoid gate and grouped top-K. [source]
- Qwen3-Next 80B-A3B · Alibaba (Qwen Team) — 512 routed experts + 1 shared expert; top-10 routing — the widest expert pool in any open-weights release at entry's verified date. [source]
Lineage
- Predecessors
- Mixtral-Style Coarse MoEMixtral MoE
Cite
BibTeX entry for the original paper
@article{arxiv2401_06066,
title = {DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models},
author = {Damai Dai and others (DeepSeek-AI)},
year = {2024},
eprint = {2401.06066},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2401.06066}
} Or cite the paper directly: arXiv:2401.06066.
Export
BibTeX
@article{arxiv_2401_06066,
title = {DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models},
author = {Damai Dai et al. (DeepSeek-AI)},
year = {2024},
eprint = {2401.06066},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2401.06066}
} CSL JSON
{
"id": "arxiv_2401_06066",
"type": "article-journal",
"title": "DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models",
"author": [
{
"literal": "Damai Dai et al. (DeepSeek-AI)"
}
],
"issued": {
"date-parts": [
[
2024
]
]
},
"URL": "https://arxiv.org/abs/2401.06066",
"number": "2401.06066",
"source": "arXiv"
} RIS
TY - JOUR
TI - DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models
AU - Damai Dai et al. (DeepSeek-AI)
PY - 2024
JO - arXiv
AN - arXiv:2401.06066
UR - https://arxiv.org/abs/2401.06066
ER -