DL0130 MoE Router Collapse and Auxiliary Loss

What is Router Collapse in Sparse Mixture-of-Experts (MoE) LLMs? Derive the auxiliary load-balancing loss and Router Z-loss used to stabilize MoE training.

Answer

Router collapse is the failure mode in which the learned router of a sparse MoE layer stops using most of its experts and concentrates almost all token assignments on a small subset, so a layer you paid N experts’ worth of memory for behaves like a much smaller model. The cause is a positive feedback loop: an expert that happens to win slightly more tokens early in training receives more gradient signal, becomes genuinely better on those tokens, so the router raises its logit further, while starved experts never see enough tokens to become useful. Under token-choice top-k the visible symptoms are a skewed load histogram, a large dropped-token fraction once the hot experts hit their capacity buffer, and a validation loss that tracks a dense model of the active-parameter size rather than the total-parameter size. Production training stacks suppress it with two extra loss terms rather than with a new routing algorithm: an auxiliary load-balancing loss that pushes router probability mass away from overloaded experts, and a router z-loss that penalizes the squared log-sum-exp of the router logits so the logits cannot grow without bound and destabilize the softmax in low precision. Both are differentiable surrogates for quantities that are not: the actual assignment counts are piecewise constant, and the actual numerical blow-up is a hardware property, so each loss attacks a proxy the gradient can reach.

(1) Collapse Is Self-Reinforcing: a small early advantage in router logits compounds through the gradient the winning expert receives, which is why collapse typically happens in the first few thousand steps and is nearly irreversible afterwards.
(2) The Assignment Is Non-Differentiable: the load fraction f_i comes from a top-k selection and has zero gradient almost everywhere, so the balance loss must pair it with the differentiable mean gate probability P_i.
(3) Balance Loss Is A Normalized Dot Product: N \sum_i f_i P_i equals 1 under a uniform assignment and grows toward N under total collapse, giving a scale-free objective independent of expert count.
(4) Its Gradient Is Load-Proportional: the derivative with respect to P_i is exactly \alpha N f_i, so probability mass is pushed down in proportion to how overloaded each expert already is.
(5) Z-Loss Bounds The Logits: penalizing the squared log-partition function caps \max_j h_j, which matters because the relative round-off in e^{h} grows linearly with |h| in bfloat16 and can flip top-k selection.
(6) Coefficients Are A Quality Trade: \alpha \approx 10^{-2} and \beta \approx 10^{-3} are the common settings, because a large \alpha buys perfect balance by actively fighting the language-modeling objective.

Cycle diagram of router collapse: router logits for one expert edge above the others, top-k dispatches more tokens to it, that expert receives most of the expert gradient, the starved experts stay undertrained and score lower, which feeds back into the logit gap; two green intervention boxes on the right show the router z-loss acting on the logits node and the auxiliary balance loss acting on the dispatch node

Figure 1: Router collapse is a closed loop, not a single bad step: the logit gap, the dispatch skew, and the gradient imbalance each amplify the next. The two stabilizers cut the loop at different points, with the z-loss constraining the logit magnitudes and the balance loss constraining the dispatch distribution.

The derivation of the balance loss starts from what you actually want to penalize, namely the variance of the per-expert token counts, and then asks which part of that quantity carries a gradient. The counts themselves come from a top-k over the router logits, so they are a step function of the parameters and give nothing to backpropagation. The fix used by GShard and simplified by Switch Transformers is to pair the non-differentiable load vector f with the differentiable importance vector P, the mean softmax probability per expert, and minimize their inner product. Treating f as a constant, the objective is linear in P with coefficient N f_i, so each step lowers the router’s probability for exactly the experts that were overloaded in the current batch, and because f is recomputed every step this becomes a self-correcting controller whose fixed point is the uniform assignment. The factor N is a normalization choice: it makes the minimum value 1 regardless of how many experts you have, so the same \alpha transfers from an 8-expert layer to a 256-expert layer. The z-loss has an entirely different motivation: it is a numerical guard, derived from the observation that a logit stored with relative precision \epsilon produces an absolute error of about |h|\epsilon, and exponentiation converts that absolute error into a relative error of the same size, so large logits make the softmax and therefore the selected expert set unreliable.

Mathematical Formulation:
h_t = W_r x_t, \quad p_t = \mathrm{softmax}(h_t)
f_i = \frac{1}{T}\sum_{t=1}^{T} \mathbb{1}[i \in \mathcal{T}_t]
P_i = \frac{1}{T}\sum_{t=1}^{T} p_{t,i}
\mathcal{L}_{\mathrm{bal}} = N \sum_{i=1}^{N} f_i P_i
\frac{\partial \mathcal{L}_{\mathrm{bal}}}{\partial P_i} = N f_i
1 \leq \mathcal{L}_{\mathrm{bal}} \leq N
\mathcal{L}_{z} = \frac{1}{T}\sum_{t=1}^{T}\left(\log \sum_{j=1}^{N} e^{h_{t,j}}\right)^{2}
\max_j h_{t,j} \leq \mathrm{lse}(h_t) \leq \max_j h_{t,j} + \log N
\mathcal{L} = \mathcal{L}_{\mathrm{LM}} + \alpha \mathcal{L}_{\mathrm{bal}} + \beta \mathcal{L}_{z}

Where:

  • x_t \in \mathbb{R}^{d} is the hidden state of token t, W_r \in \mathbb{R}^{N \times d} the router matrix, and h_t the router logits before any selection.
  • T is the number of tokens the statistics are aggregated over (micro-batch, device batch, or global batch), N the expert count, and \mathcal{T}_t the set of k experts selected for token t.
  • f_i is the load, the fraction of tokens dispatched to expert i; it is piecewise constant in the parameters and therefore contributes no gradient.
  • P_i is the importance, the mean router probability assigned to expert i; it is smooth, so all of the balance-loss gradient flows through it and into W_r.
  • \mathcal{L}_{\mathrm{bal}} = 1 exactly when f_i = P_i = 1/N for all i, and approaches N when one expert takes every token, so the value is directly readable as an imbalance factor.
  • \mathrm{lse}(h_t) = \log\sum_j e^{h_{t,j}} is the log-partition function; squaring it penalizes large logits in either direction and, by the sandwich bound, keeps \max_j h_{t,j} within \log N of a small target.
  • \alpha and \beta are the balance and z-loss coefficients, commonly \alpha = 10^{-2} and \beta = 10^{-3}; \mathcal{L}_{\mathrm{LM}} is the ordinary next-token cross-entropy.
Two-panel chart: left panel plots the maximum expert load fraction against training step for an eight-expert layer with balance-loss coefficients zero, one thousandth, and one hundredth, showing full collapse toward one expert without the loss and a curve close to the uniform 0.125 line with alpha one hundredth; right panel plots relative round-off error in exp of a router logit against logit magnitude on a log scale for bfloat16 and float32 storage, with bfloat16 crossing one percent error at a logit magnitude near 2.6

Figure 2: The two losses guard different quantities. Left: without a balance term the maximum load fraction runs from the uniform 1/N = 0.125 to near 1.0 within a few thousand steps, while \alpha = 10^{-2} holds it close to uniform. Right: the relative round-off in e^{h} grows linearly with |h|, which is why bfloat16 routers become unreliable at moderate logits and the z-loss keeps \mathrm{lse}(h) near O(1).

PropertyAuxiliary balance lossRouter z-lossBias-based loss-free balancing
Quantity penalizedThe dot product of load and importance, scaled by the expert countThe squared log-sum-exp of the router logits, averaged over tokensNothing; a per-expert bias is added to the selection logits only
Failure it preventsExpert collapse, wasted parameters, and dropped tokens at the capacity bufferLogit blow-up, low-precision softmax round-off, and loss spikesExpert collapse, without perturbing the gate weights used in the output
Typical settingCoefficient 1e-2, aggregated per device batch or per global batchCoefficient 1e-3, with the router itself computed in float32Bias update rate around 1e-3, driven by observed per-expert load error
Effect on the LM objectiveAdds an interference gradient that trades some quality for balanceMild regularizer, usually neutral or slightly positive for qualityNo interference term at all, since the bias is not part of the output gate
Where it is usedGShard, Switch, Mixtral, OLMoEST-MoE and most later open MoE training stacks, including OLMoEDeepSeek-V3 and its loss-free-balancing follow-ups

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *