FFN & MoE · August 2024
Auxiliary-Loss-Free Load Balancing
intermediate
routing
Load-balance MoE experts without paying the auxiliary-loss quality tax — by adjusting a per-expert bias that enters at top-K selection but does not enter the final output computation.
§ 1 · Premise
The auxiliary-loss tax on MoE routing
A sparse top- MoE layer with experts faces a coordination problem the dense FFN does not have: the router has to decide which experts process which tokens, and the dispatch infrastructure runs at the speed of the most-loaded expert in each step. If the gate collapses onto a handful of “popular” experts, the rest of the experts sit idle, GPU memory is wasted on parameters that never see a gradient, and any token that exceeds the popular experts’ capacity gets dropped — its residual passes through unchanged (Switch Transformer §2.2).
The standard fix, established by GShard §2.2 and canonicalized by Switch, is an auxiliary load-balancing loss added to the language-modeling objective with a small coefficient :
where is the fraction of tokens in the batch routed to expert (a count, post-argmax) and is the mean softmax probability assigned to expert by the gate (Switch Transformer eq. 4). Switch uses ; DeepSeekMoE §2.3 uses the same form with a small for expert-level balance and a separate for device-level balance.
The auxiliary loss works — experts stay balanced — but it has a cost Wang et al. 2024 §2 names directly: the gradient pulls the gate parameters in a direction that has nothing to do with predicting the next token. The two gradients can disagree on the same parameter, and the optimizer averages them. Picking too small leaves load imbalanced (experts get dropped, throughput collapses); picking too large overwhelms the LM signal and hurts perplexity. Wang et al. quantify the trade-off on a 1B-parameter MoE in their Figure 2: at small enough to recover the LM-only perplexity, the maximum-violation metric on expert load is the target; at large enough to push maximum-violation near zero, perplexity degrades by ~0.04 nats.
The contribution preview. Replace the term with a per-expert scalar bias that is added to the routing score at top- time only, then updated after each step by a closed-form rule based on observed load — no gradient flows through . The LM gradient stays unmodified; load balance is enforced by book-keeping instead of by a competing loss.
§ 2 · Derivation
From standard top-K routing to a non-differentiable bias
Standard top-K routing. Let be the token’s residual-stream input. A standard sparse MoE layer with experts and top- gating computes a score for each expert from a learned gate and a non-linearity (softmax in Switch and GShard; sigmoid in DeepSeekMoE V3):
where is the set of expert indices chosen for token . The layer’s output is the gate-weighted combination of the selected experts:
where is the -th expert FFN and is the renormalized gate weight (DeepSeek-V3 §2.1.2, eq. 12–14). The gradient of flows back through to for the selected experts; unselected experts receive no gradient through this token.
Load-imbalance measurement. Let denote the fraction of tokens in a batch of size routed to expert , i.e., . The mean utilization is under top- routing (each token contributes selections distributed across experts). Wang et al. measure imbalance with the maximum violation,
(Wang et al. 2024, Definition 1). A perfectly balanced routing has ; the worst case is . The auxiliary-loss objective minimizes a smooth proxy of this quantity; the aux-loss-free scheme will attack directly via the bias.
The bias at top-K time. Introduce a per-expert scalar , initialized to zero. Modify the top- selection — and only the top- selection — to use the biased score :
The gate weights in the output combination are still computed from the unbiased scores , normalized over (Wang et al. 2024 eq. 4–5). The bias changes which set of experts processes the token; once the set is chosen, the model’s expressive output is the same as it would have been without the bias, given that selection.
Why the LM gradient is preserved. The TopK operator is already non-differentiable — gradient implementations of MoE treat the selection as a stop-gradient categorical and backpropagate only through the weights of the selected experts (Shazeer et al. 2017 §3). Adding inside the non-differentiable TopK therefore does not introduce a new backward path: there is no . Because does not appear in the gate weights either, the partial derivative of every other quantity in with respect to is exactly zero. The LM gradient for the gate parameters is identical to what an unbiased gate with the same realized selection would have produced — selection effects are absorbed into the data-distribution side, not into the gradient signal.
The closed-form update rule. Because the LM loss carries no gradient information about , the bias is updated by an external rule. Define the load gap measured per training step. Wang et al. propose the discrete-sign rule
with step size (Wang et al. report at 1B scale; DeepSeek-V3 §3.4 uses at 671B scale with the same form DeepSeek-V3 §3.4). The sign-only variant is preferred over the proportional because the magnitude of varies wildly with batch composition, while the sign is a stable per-step signal of “which direction to nudge.”
Stability and convergence argument. Treat as a control input acting on a load process . Two structural facts ensure the loop is stable.
- Monotonicity. For fixed gate scores , increasing weakly increases : the expert moves higher in more tokens’ TopK rankings, never lower. So .
- Bounded step. Because the update is , the bias trajectory has bounded one-step variation, so the load cannot oscillate by more than a per-step-bounded amount even under adversarial gate drift.
Together, monotonicity plus a small fixed step size make the update a contraction toward the fixed point in the deterministic limit. Wang et al. §3.3 verify empirically that decays roughly exponentially over the first ~5K steps and stays within 5% of zero for the rest of training. In practice the loop is robust to a range of (Wang et al. §3.3, Figure 4): too small and balancing is slow at startup; too large and the bias oscillates around zero without harming final quality.
One subtlety: the bias is not absorbed into . A reader might ask why the per-expert bias is not just folded into a bias row of and learned jointly with the rest of the gate. The answer is the gradient-conflict argument from § 1: if were learned via , it would drift toward whatever value maximizes next-token likelihood, which is generally not balanced load. The point of the closed-form rule is precisely to decouple from the LM gradient.
Complementary sequence-level penalty (V3). DeepSeek-V3 §3.4 reports that the bias alone prevents per-batch maximum violations but can still permit within-sequence imbalance — long sequences where the same expert is chosen repeatedly within a single example. V3 adds a sequence-wise balance loss with a very small coefficient () as a backstop:
evaluated per sequence rather than per batch (DeepSeek-V3 §3.4, eq. 17–19). The coefficient is small enough that V3’s authors describe it as “complementary to the bias-update mechanism” rather than a primary balancing signal.
§ 3 · Reference implementation
Sketch
# Shapes: B batch, T tokens, E experts, K top-K, d model dim.
# State: b is a per-expert bias buffer (not a Parameter — no autograd).
def aux_loss_free_moe(x, W_g, experts, b, K=2, u=1e-3):
# 1. Routing scores from the gate.
logits = x @ W_g.T # [B, T, E]
s = logits.sigmoid() # [B, T, E] <- DeepSeek-V3 uses sigmoid
# 2. Bias enters at top-K selection only. detach() makes the
# addition explicit-non-differentiable in case b ever becomes a Tensor.
biased = s + b.detach()[None, None, :] # [B, T, E]
topk_idx = biased.topk(K, dim=-1).indices # [B, T, K]
# 3. Gate weights come from the UNBIASED scores, renormalized over the K chosen experts.
s_sel = s.gather(-1, topk_idx) # [B, T, K]
g = s_sel / s_sel.sum(-1, keepdim=True) # [B, T, K] <- output combination weights
# 4. Standard dispatch & combine. The model's expressive output is independent of b
# given a fixed selection, because b never appears past the topk call.
y = dispatch_combine(x, experts, topk_idx, g) # [B, T, d]
# 5. Closed-form bias update — runs outside the autograd graph.
# f_i = fraction of token-slots that landed on expert i in this batch.
with torch.no_grad():
counts = scatter_count(topk_idx, num_experts=b.shape[0]) # [E]
f = counts / counts.sum() # [E] load distribution
f_bar = K / b.shape[0] # target = K/E
b.add_(u * (f_bar - f).sign()) # b_i += u * sign(e_i)
return y
§ 4 · Empirical evidence
Ablations, perplexity, and the unanswered downstream question
Introducing-paper ablations (Wang et al. 2024). The paper’s main experiments train a 1B total / ~150M activated MoE on 100B tokens and a 3B total / ~500M activated MoE on the same budget, comparing three regimes: no balancing (LM loss only), standard auxiliary loss with the Switch coefficient , and the bias-update scheme (Wang et al. 2024, Table 2 and Table 3). On the 1B model the aux-loss-free run reports validation perplexity 7.86 vs. 7.95 for the tuned aux-loss baseline and 7.83 for an LM-loss-only run that has in the hundreds (i.e., mostly dead experts). The aux-loss-free run reaches within the first ~5K steps and stays there; the aux-loss baseline holds at the that minimizes perplexity. The 3B-scale Table 3 reproduces the ordering with similar gaps.
Drop-rate. Wang et al. §4.2 also report token-drop rate when a fixed expert capacity is enforced (the Switch-style overflow policy). The aux-loss-free scheme drops 0.5–0.8% of tokens at steady state versus 1.4–2.0% for the tuned aux-loss baseline at the same capacity — consistent with the lower MaxVio.
DeepSeek-V3 confirmation at frontier scale. DeepSeek-V3 §3.4 is the only public reproduction at frontier-scale (671B total, 37B active, 14.8T training tokens, 256 routed experts × 61 layers). The V3 report’s Table 5 ablates the bias-update scheme against an aux-loss baseline on a smaller proxy run and reports the aux-loss-free configuration matching or slightly beating the baseline on Pile validation perplexity and on a panel of zero-shot evaluations including BBH, MMLU, and HumanEval (DeepSeek-V3 Table 5). The full 671B training uses for the first 14.3T tokens and then for the final 500B tokens (an annealing phase that freezes the bias). The V3 authors describe the bias-update scheme as one of two routing modifications — the other being a sigmoid replacing softmax in the gate — that they credit with V3’s MoE stability at this scale.
Carry-over to V3.1 and V3.2. DeepSeek-V3.1 model card and V3.2-Exp model card both retain the V3 routing configuration unchanged; V3.2 only modifies the attention stack (adding the DeepSeek Sparse Attention layer). No re-ablation against an aux-loss baseline is published at V3.1 or V3.2 scale; the lineage is “kept because V3 worked.”
Independent reproductions. Adopters outside DeepSeek are documented but limited as of 2026-05-12. Hunyuan-Large §3.1 (Tencent, 389B MoE, 52B active) adopts the aux-loss-free scheme citing Wang et al. directly and reports comparable load-balance behavior; no head-to-head ablation against an aux-loss baseline is provided in the Hunyuan report. Other open MoE families — Mixtral 8x22B, OLMoE, Qwen2-MoE — use the standard auxiliary-loss formulation, so no comparable scale-matched aux-loss-free vs. aux-loss comparison exists outside the DeepSeek line.
Does perplexity equivalence imply downstream-task equivalence? This is the open question the published evidence does not settle. Wang et al. measure validation perplexity and one benchmark panel at 3B scale; DeepSeek-V3 measures the same at 671B. Both report that the aux-loss-free scheme is at-worst a wash and modestly better. But the literature on perplexity as a predictor of downstream behavior is mixed (Liu et al. 2023, “Same Pre-training Loss, Better Downstream”) and small absolute perplexity gaps in MoE training do not always cash out in downstream ability the way they do in dense models. No public study isolates which downstream behaviors (reasoning chain quality, multilinguality, long-tail recall) are sensitive to the routing balance method at fixed capacity, and the routing imbalance distribution at long context is not analyzed in any of the cited reports. The honest answer to “should you switch your production MoE from aux-loss to aux-loss-free?” is: at DeepSeek’s scale the production evidence is positive; at other scales there is no public ablation to cite, and “I don’t know” is the correct response.
Adopted by
- DeepSeek V3 · DeepSeek-AI — Used across all MoE layers; replaces the standard balance loss. [source]
- DeepSeek V3.1 · DeepSeek-AI — Same aux-loss-free routing inherited from V3 across the MoE layers. [source]
- DeepSeek V3.2-Exp · DeepSeek-AI — Aux-loss-free routing carried over from V3 / V3.1; only attention layers change in V3.2. [source]
Lineage
- Predecessors
- Switch TransformerSwitch·DeepSeekMoEDeepSeekMoE
Cite
BibTeX entry for the original paper
@article{arxiv2408_15664,
title = {Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts},
author = {Lean Wang, Huazuo Gao, Chenggang Zhao, Xu Sun, Damai Dai (DeepSeek-AI)},
year = {2024},
eprint = {2408.15664},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2408.15664}
} Or cite the paper directly: arXiv:2408.15664.
Export
BibTeX
@article{arxiv_2408_15664,
title = {Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts},
author = {Lean Wang and Huazuo Gao and Chenggang Zhao and Xu Sun and Damai Dai (DeepSeek-AI)},
year = {2024},
eprint = {2408.15664},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2408.15664}
} CSL JSON
{
"id": "arxiv_2408_15664",
"type": "article-journal",
"title": "Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts",
"author": [
{
"literal": "Lean Wang"
},
{
"literal": "Huazuo Gao"
},
{
"literal": "Chenggang Zhao"
},
{
"literal": "Xu Sun"
},
{
"literal": "Damai Dai (DeepSeek-AI)"
}
],
"issued": {
"date-parts": [
[
2024
]
]
},
"URL": "https://arxiv.org/abs/2408.15664",
"number": "2408.15664",
"source": "arXiv"
} RIS
TY - JOUR
TI - Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts
AU - Lean Wang
AU - Huazuo Gao
AU - Chenggang Zhao
AU - Xu Sun
AU - Damai Dai (DeepSeek-AI)
PY - 2024
JO - arXiv
AN - arXiv:2408.15664
UR - https://arxiv.org/abs/2408.15664
ER -