C.W.K.
Stream
Lesson 05 of 06 · published

Expert Load Balancing and Expert Collapse

~11 min · moe, training, balancing

Level 0Scout
0 XP0/41 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

The failure mode you must understand

Expert collapse is the single biggest failure mode in MoE training. If routing is left unconstrained, the network rapidly converges to sending most tokens to a small subset of experts, which then improve fastest, which makes the router send even more tokens to them, which... you see the loop. The end state: a few experts handle everything, the rest are dead weight occupying memory for no benefit.

Why it happens

Routers are trained alongside experts. Whichever expert is best at the start of training gets more tokens, gets better, gets more tokens. Without an explicit pressure to spread load, the optimizer has no reason to keep underused experts alive. This is a self-reinforcing failure that can ruin a multi-million-dollar training run if you don't catch it.

Solutions

  • Auxiliary load-balancing loss. Adds a penalty term that encourages roughly equal expert utilization across the batch. Standard since Switch Transformer; used by Mixtral and most early MoE.
  • Auxiliary-loss-free balancing. DeepSeek-V3 introduced a clever alternative: add learnable per-expert bias terms to the router logits, and adjust them based on observed expert utilization during training. No extra loss term, no interference with the main objective.
  • Expert capacity limits. Cap how many tokens any single expert can process per batch. Excess tokens get routed to second-choice experts or dropped. Common in production MoE training.
  • Noise injection. Add noise to router scores during training to prevent fully deterministic routing patterns from forming too early.

Why this matters even at inference

Even after training, expert utilization is not perfectly uniform — some experts genuinely fire more than others depending on the workload. This shows up as load skew across GPUs in production: the GPU holding popular experts gets hammered, others sit half-idle. Production MoE serving stacks (vLLM, TensorRT-LLM) have to handle this dynamically.

Reading model cards for balancing strategy

If a model card mentions "auxiliary loss" or specifies a balancing coefficient, that's the standard route. If it mentions "auxiliary-loss-free" or "bias-based balancing", you're reading a DeepSeek-style design. If it doesn't mention balancing at all, either the model is dense or someone forgot a critical detail.

Code

Auxiliary load-balancing loss (Switch Transformer style)·python
import torch

def load_balancing_loss(router_logits, expert_indices, num_experts):
    # router_logits: (B*T, num_experts)
    # expert_indices: (B*T, k) — top-k chosen experts
    fraction_per_expert = torch.zeros(num_experts, device=router_logits.device)
    for k in range(expert_indices.shape[-1]):
        fraction_per_expert.scatter_add_(
            0,
            expert_indices[..., k].view(-1),
            torch.ones_like(expert_indices[..., k].view(-1), dtype=torch.float),
        )
    fraction_per_expert /= expert_indices.shape[0]

    avg_router_prob = torch.softmax(router_logits, dim=-1).mean(dim=0)
    return num_experts * (fraction_per_expert * avg_router_prob).sum()
DeepSeek-V3 style bias adjustment (pseudocode)·python
# Each step: nudge expert_bias toward balancing observed load.
def adjust_expert_bias(expert_bias, observed_load, target_load, lr=1e-3):
    # observed_load: tokens routed to each expert this step
    # target_load:   ideal balanced load
    delta = (target_load - observed_load) * lr
    expert_bias += delta
    return expert_bias
# No backprop, no aux loss term, just a slow-feedback correction.

External links

Exercise

Read the DeepSeek-V3 technical report's section on auxiliary-loss-free balancing. In your own words, explain why adding a learned bias term works without an explicit loss. What is the implicit gradient, and where does it come from? This is one of the more elegant MoE design ideas of 2024 and worth fully understanding.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.