5.4 Collapsing & Load Balancing
A router can make every local choice look reasonable while leaving the distributed system badly imbalanced. Some experts receive many tokens, others get little learning signal, and the busiest rank determines step time. Expert collapse is one possible feedback failure, not an inevitable fate of every MoE or proof that all traffic must end up at one expert.
The engineering target is useful specialization within a capacity and communication budget. Uniform traffic is a proxy for utilization, not a guarantee of optimal quality. Measure load skew, token drops, quality, and straggler time together.
1. Auxiliary Load-Balancing Loss
A common balancing term couples assignment frequency with mean router probability [1]:
is expert count, the coefficient, the observed assignment fraction, and the mean routing probability. Define the normalization: top-1 fractions count tokens, while a top- variant can count all assignments for valid tokens. These conventions change scale and must be documented. Padding must not contribute; distributed statistics must match the intended balancing domain.
The auxiliary gradient can compete with task gradients when its weight is excessive. It can also improve learning by preventing severe underutilization. Calling this an unavoidable “alignment tax” confuses routing regularization with the alignment trade-offs in Chapter 10. Sweep the coefficient and evaluate task loss, domain slices, load skew, and throughput rather than assume a universal winner.
2. Capacity, Dropping, and Dropless Execution
For a top- router, a simplified average-load capacity model is
where is the capacity factor and the assignment slots per expert. Actual implementations may use different rounding, capacity scopes, dispatch layouts, or dynamic allocation. A top-1 formula without the factor must not be reused for top- traffic.
A capacity-limited implementation may drop overflow assignments, reroute them, or skip an expert contribution while retaining the residual path. With top- routing, one dropped assignment does not necessarily remove every expert contribution for that token. Dropping neither deletes the token from the sequence nor proves a particular long-context failure. Measure drop rate by domain, token position, layer, and expert.
Dropless systems such as MegaBlocks use block-sparse computation to avoid fixed per-expert padding and assignment dropping [4]. They still require enough memory for actual routed traffic and can suffer load skew or communication bottlenecks. “Dropless” is not “unlimited capacity.”
3. Router Z-Loss
ST-MoE studies router z-loss for numerical stability [2]:
is a routing logit and the coefficient. Compute log-sum-exp stably, typically in FP32. This regularizes the log normalizer; it does not bound every logit independently or guarantee that training cannot diverge.
4. Auxiliary-Loss-Free Balancing
The loss-free balancing study introduces dynamically updated expert biases [5]. DeepSeek-V3 uses a related selection controller while retaining a small sequence-wise auxiliary term [3]. “Loss-free” therefore does not mean its complete training objective contains no balancing regularizer.
For affinity scores and controller biases , select
The chosen experts’ mixture weights use the unmodified affinity scores in the documented V3 design. Update the non-gradient biases from measured load: lower an overloaded expert’s bias and raise an underloaded one’s. Distinguish selection scores from mixture weights. The biases are not trained through the task gradient, but changing selections still changes which experts receive tokens and gradients. This does not prove “pure affinity” learning or universal superiority over auxiliary losses.
5. Educational Loss Calculation
Deliberately simplified PyTorch example. This computes a normalized top- assignment variant for an already filtered batch of valid tokens. It omits dispatch, capacity/drop policy, expert-parallel global reductions, bias updates, mixed-precision optimization, and the full training loop. It is not a smoke-tested production implementation.
import torch
import torch.nn.functional as F
def compute_moe_losses(router_logits, top_k_indices, alpha=1e-2, beta=1e-4):
# logits: [T, E]; indices: [T, k]; padding already excluded
tokens, experts = router_logits.shape
if tokens == 0 or top_k_indices.size(0) != tokens:
raise ValueError("require a non-empty matching token batch")
logits = router_logits.float() # stable probability/normalizer arithmetic
assignment_fraction = F.one_hot(
top_k_indices, num_classes=experts
).float().mean(dim=(0, 1)) # includes every selected assignment
mean_probability = logits.softmax(dim=-1).mean(dim=0)
aux = alpha * experts * (assignment_fraction * mean_probability).sum()
z_loss = beta * logits.logsumexp(dim=-1).square().mean()
return aux, z_loss
The example’s assignment fractions sum to one. If an implementation instead normalizes by token count, their sum is , and the coefficient has a different meaning. Distributed implementations must define whether balancing is local to a device/group or global, with consistent gradients and valid-token counts.
6. Training and Recovery Contract
Pin model/router configuration, tokenizer and data manifest, filter/mixture versions, sample/shard hashes, grouped splits, and evaluation quarantine. Specify top-, expert count, capacity factor, drop policy, affinity/weight normalization, auxiliary and z-loss coefficients, bias update rate, optimizer schedule, token batch, precision, sharding, and seeds.
Account separately for all expert parameters, gradients/optimizer state, activations, dispatch buffers, collectives, checkpoints, and evaluation. Active experts reduce per-token arithmetic; they do not remove inactive weights from storage. Record per-expert assignment counts, drop rate, router entropy/log-normalizer, token-normalized training/validation loss and domain slices, nonfinite/overflow counts, gradient/activation norms, throughput, MFU, data wait, collective/straggler time, and reconstructable batch IDs.
Abort on persistent numerical errors, predeclared drop/skew limits, reward-free validation regressions, or lost throughput outside the observation window. Checkpoint sharded model/optimizer, scheduler, scaler/FP8 state, global step/tokens, RNG, sampler/data cursor, controller biases, and dataset/tokenizer/config hashes. Publish atomically with checksums and a completion marker; define retention, remote replication, world-size limits, and continuation-equivalence restore drills.
Release the immutable bundle only after domain quality, base retention, safety, format/tool, latency, cost, and error-rate gates pass with paired uncertainty or justified sample sizes. Assign an owner, last-known-good configuration, and a rollback rehearsal. A good load histogram alone is not a release gate.
Quizzes
Quiz 1: Why does equal expert traffic not prove optimal routing?
Uniform traffic can improve utilization but may conflict with useful specialization. Quality, load skew, dropping, and step time must be evaluated together.
Quiz 2: Why must a capacity estimate include top-k?
Each valid token creates k expert assignments. Reusing a top-1 estimate can undercount average dispatched load by a factor of k.
Quiz 3: Does loss-free selection eliminate every balancing loss in DeepSeek-V3?
No. The report retains a small sequence-wise auxiliary term. Dynamic selection biases and differentiable regularizers are separate mechanisms.
Quiz 4: Why include controller biases in a checkpoint?
They influence future expert selection. Restoring weights without the controller state can change dispatch, utilization, and training continuation.
References
- Lepikhin, D., et al. (2020). GShard. arXiv:2006.16668.
- Zoph, B., et al. (2022). ST-MoE: Designing Stable and Transferable Sparse Expert Models. arXiv:2202.08906.
- DeepSeek-AI. (2024). DeepSeek-V3 Technical Report. arXiv:2412.19437.
- Gale, T., et al. (2022). MegaBlocks: Efficient Sparse Training with Mixture-of-Experts. arXiv:2211.15841.
- Wang, L., et al. (2024). Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts. arXiv:2408.15664.