Skip to content

DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models

Skip →MLA (DeepSeek-V2 latent attention)
main track #4corefundamentalpaperrubric 12/122024 · ~50 min

Damai Dai, Chengqi Deng, Chenggang Zhao, …, Wenfeng Liang

Status

TL;DR. DeepSeekMoE makes experts smaller and more numerous (fine-grained segmentation), so each token can mix many specialists. It also keeps a few experts always on (shared experts) to hold common knowledge. At the same parameters and compute, this beats GShard-style top-2 MoE. The 16B model matches 7B dense models with about 40% of the compute.

Why it matters now. This is the MoE layer inside DeepSeek-V2 and DeepSeek-V3, and the fine-grained-plus-shared pattern is now common in open frontier models. If you fine-tune one of these as an embedding model, reranker or RL-trained search agent, you are working with 64 or more small experts, a shared path that sees every token, and balance losses that small fine-tuning sets can easily disturb.

Fine-grained segmentation. Split each of NN experts into mm smaller experts with 1/m1/m of the FFN width, and activate mKmK of the mNmN. Parameters and FLOPs per token stay the same, but the number of possible expert combinations explodes. For token input utu_t, with ei\mathbf{e}_i the router vector of expert ii:

ht=∑i=1mNgi,t FFNi(ut)+ut,gi,t={si,tsi,t∈Topk({sj,t},mK)0otherwise,si,t=Softmaxi(ut⊤ei).h_t = \sum_{i=1}^{mN} g_{i,t}\,\mathrm{FFN}_i(u_t) + u_t, \qquad g_{i,t} = \begin{cases} s_{i,t} & s_{i,t} \in \mathrm{Topk}(\{s_{j,t}\}, mK) \\ 0 & \text{otherwise} \end{cases}, \qquad s_{i,t} = \mathrm{Softmax}_i(u_t^\top \mathbf{e}_i).

Shared-expert isolation. Make KsK_s experts always active and route only mK−KsmK - K_s of the remaining mN−KsmN - K_s. Total active compute is unchanged.

Two balance losses. With N′=mN−KsN' = mN - K_s routed experts and K′=mK−KsK' = mK - K_s routed choices:

LExpBal=α1∑i=1N′fiPi,fi=N′K′T∑t=1T1(token t selects i),Pi=1T∑t=1Tsi,t,\mathcal{L}_{\text{ExpBal}} = \alpha_1 \sum_{i=1}^{N'} f_i P_i, \quad f_i = \frac{N'}{K'T}\sum_{t=1}^{T} \mathbb{1}(\text{token } t \text{ selects } i), \quad P_i = \frac{1}{T}\sum_{t=1}^{T} s_{i,t},

A device-level loss LDevBal=α2∑d=1Dfd′Pd′\mathcal{L}_{\text{DevBal}} = \alpha_2 \sum_{d=1}^{D} f'_d P'_d does the same per GPU group. Here fd′f'_d is the mean of fif_i over the experts on device dd and Pd′P'_d is their sum. The paper sets α1\alpha_1 small (only to prevent collapse) and α2\alpha_2 larger (for throughput).

From top-2 MoE to fine-grained experts to shared plus routed experts Three panels with the same total expert parameters and the same active compute. Panel a: four large experts, two active. Panel b: each expert split into four, giving sixteen small experts with eight active, which allows far more combinations. Panel c: one small expert is made shared and always active, and the router picks seven of the remaining fifteen. Same parameters, same active FLOPs, different granularity (a) top-2 of 4 C(4,2) = 6 combinations (b) fine-grained: 8 of 16 C(16,8) = 12,870 combinations (c) 1 shared + 7 of 15 S shared expert skips the router routed, active routed, idle shared (always on) Paper example: 16 experts, top-2 gives 120 combinations; split by 4 into 64, top-8 gives 4,426,165,368.
Original sketch. All three layouts have the same expert parameters and active compute. Splitting experts multiplies the number of possible expert mixes, and a shared expert takes the common load off the router.
  • 2B validation (Table 1, 100B tokens, 0.3B active). Pile loss: Dense 2.060, Hash Layer 1.932, Switch 1.881, GShard 1.867, DeepSeekMoE 1.808. TriviaQA rises from 10.2 (GShard) to 16.6, and NQ from 3.2 to 5.7.
  • Same quality as a bigger GShard (§4.3). DeepSeekMoE 2B roughly matches GShard 2.9B, which has 1.5× the expert parameters and compute.
  • 16B model (§5). 28 layers, 2 shared + 64 routed quarter-size experts, top-6, 16.4B total and 2.8B active, trained on 2T tokens. It is comparable to DeepSeek 7B and LLaMA2 7B with about 40% of their compute.
  • 145B preview (§7). Comparable to DeepSeek 67B with 28.5% of its compute (“maybe even 18.2%”, per the authors).
  • Weak spot. MMLU is 45.0 against DeepSeek 7B’s 48.2. The authors attribute this to only about 0.5B attention parameters, against 2.5B in the dense 7B.
  • Granularity has hardware costs (small matmuls, more routing traffic) that the paper does not fully price in.
  • Specialisation evidence is indirect (loss changes when experts are removed). What each expert actually stores is not characterised.
  • Balance still relies on auxiliary losses that trade off against quality. Aux-loss-free balancing later removes the expert-level loss.
  • The attention budget seems to cap multiple-choice performance. MLA in DeepSeek-V2 revisits attention.

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.

  1. Derive / compute

    Start from a layer with 16 experts and top-2 routing. (a) Split each expert into 4 (FFN width divided by 4) and activate 8. Show that parameters and FLOPs per token do not change, and compute the number of expert combinations before and after. (b) Now make 1 of the 64 small experts shared and route 7 of the other 63. How many combinations remain? (c) DeepSeekMoE 16B uses 2 shared and 64 routed experts, each a quarter of a standard FFN, with top-6 routing. How many standard-FFN equivalents are active per token, and how many are stored?

    What a strong answer covers
    • (a) Total expert parameters: 16 × P = 64 × P/4. Active: 2 × P = 8 × P/4. Both unchanged. Combinations: C(16,2) = 120 before and C(64,8) = 4,426,165,368 after.
    • (b) The shared expert is not chosen, so only C(63,7) = 553,270,671 combinations remain. That is still millions of times more than 120, so the flexibility gain mostly survives.
    • (c) Active: (2 shared + 6 routed) × 0.25 = 2 standard FFNs, the same compute as a top-2 MoE of full-size experts. Stored: 66 × 0.25 = 16.5 FFN equivalents per MoE layer.
    • Caveat: more, smaller experts mean more router outputs, more scatter and gather work, and smaller matmuls, so wall-clock cost is not exactly constant.
  2. Mechanism

    Explain why isolating a shared expert should make routed experts more specialised. Then interpret the paper's test in which the shared expert is disabled and one extra routed expert is activated in its place, which raises Pile loss from 1.808 to 2.414.

    What a strong answer covers
    • Without a shared expert, common knowledge (frequent syntax and function words) must be learned by whichever routed experts receive it. That knowledge is duplicated across many experts, which is redundancy.
    • A shared expert sees every token, so it can absorb what all tokens need. Routed experts are then free to store narrower knowledge.
    • The test keeps active compute fixed and swaps the shared expert for a routed one. Loss jumps from 1.808 to 2.414, so the shared expert holds knowledge that the routed experts do not duplicate. It is not interchangeable with them.
    • This is the specialisation claim in one number: the experts have taken on different roles, not redundant copies.
  3. What if…

    Use the paper's ablations to argue which of the two ideas, fine-grained segmentation or shared-expert isolation, matters more, and how many shared experts to use. Draw on the 2B validation runs (Figure 3, the shared-count study, and the redundancy test that disables top routed experts).

    What a strong answer covers
    • Adding a shared expert to a GShard-style baseline improves results. Splitting further, to 32 experts (1 shared + 31 routed) and then 64 (1 + 63), keeps improving. Both ideas help, and the gains stack.
    • The number of shared experts barely matters: 1, 2 and 4 give Pile loss 1.808, 1.806 and 1.811. The authors keep a ratio of about 1 shared to 3 activated routed experts when scaling.
    • Redundancy test: disabling the top routed experts hurts DeepSeekMoE more than a GShard model with 1.5× the expert parameters. This is evidence of less redundancy among experts.
    • Efficiency: activating only 4 routed experts already matches GShard, and a half-activated model trained from scratch still beats GShard.
  4. Design

    You are pretraining a 2B-total, roughly 0.3B-active fine-grained MoE on one 8-GPU node with experts sharded across GPUs, for later use as an embedding and reranking backbone. Choose the expert count, top-k and shared count, and set the two balance losses. Say what you would monitor during training.

    What a strong answer covers
    • A reasonable start mirrors the paper's 2B setup: 64 small experts, 1 shared + 7 routed active, and a dense first layer if balance converges slowly there (the 16B model did this).
    • Expert-level loss: α₁ · Σ fᵢPᵢ with fᵢ scaled by N'/(K'T), where N' and K' count only routed experts. Keep α₁ small, because a large value hurts quality.
    • Device-level loss: group experts by GPU and penalise the product of the mean f and the summed P per device. Use a larger α₂, because only cross-device imbalance hurts throughput.
    • Monitor per-expert and per-device token counts, the max-to-mean load ratio, router entropy, and loss spikes.
    • For the IR use: check whether fine-tuning on small retrieval sets collapses routing, and consider freezing the router during fine-tuning.
  5. Critique

    DeepSeekMoE 16B beats or matches DeepSeek 7B on most tasks with about 40% of the compute, but trails it on MMLU (45.0 versus 48.2). The authors blame the small attention budget (about 0.5B attention parameters versus 2.5B). Critique this explanation and design an experiment that could falsify it.

    What a strong answer covers
    • The explanation fits their earlier finding that an MQA variant of DeepSeek 7B also struggled on MMLU-style tasks. But in the comparison, attention size is confounded with total FFN capacity, depth and width.
    • Alternative causes: the multiple-choice format (comparing option letters) may need different circuits, or routing may hurt exactly on short, format-heavy prompts.
    • Falsifying experiment: train MoE variants that differ only in attention parameters (more heads or wider attention), at matched FFN and data. If MMLU tracks attention size while Pile and TriviaQA do not, the claim holds. If not, it fails.
    • Also compare cloze-style and letter-choice scoring of MMLU, to separate knowledge from format handling.
  6. Research idea

    Fine-grained segmentation keeps helping from 16 to 64 experts at the 2B scale. Propose a study to find where granularity stops paying off, accounting for both model quality and hardware efficiency.

    What a strong answer covers
    • Sweep the split factor m (for example 1, 2, 4, 8, 16, 32) at fixed total and active parameters, with the shared ratio fixed.
    • Measure loss and downstream accuracy, and also tokens per second, all-to-all bytes, and matmul efficiency, since tiny experts give small, inefficient GEMMs.
    • Hypothesis: quality saturates as the number of combinations grows past what the data can use, while efficiency keeps falling. The optimum moves with batch size and interconnect.
    • Add a specialisation metric (for example per-expert domain or token-type mutual information) to test whether gains come from specialisation or just from more routing flexibility.

Done with this page?

Status