Skip to content
DeepForgeby svx
EfficiencyPaperAdvanced2024~13 min theory

Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts

Balance expert load with a nudge to the router, not a gradient to the loss.

arXiv:2408.15664

Where this sits

DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language ModelsAuxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts

A methods paper from the same lineage, sitting between the architecture work and the 671B scale-up. Its backbone is DeepSeekMoE, whose fine-grained experts are exactly what needs balancing; the strategy it proposes is then adopted by DeepSeek-V3.

  • Replaces the auxiliary balance loss with a per-expert bias used only in the top-K selection, so no interference gradient is added to the training objective.
  • Updates the bias by a fixed step in the sign of the load error, b_i <- b_i + u * sign(e_i), with u = 0.001 the best setting in the sweep.
  • Improves both sides of the trade-off at once: on a 1B model, validation perplexity 9.50 versus 9.56 and MaxVio (the worst-case expert-load deviation from even, lower is better) 0.04 versus 0.72; on 3B, 7.92 versus 7.97 and 0.04 versus 0.52.
  • Scales with expert parallelism: imbalance keeps shrinking as the computation batch grows, while auxiliary-loss training plateaus.
  • Stays causal, unlike Expert Choice routing, because the bias update uses only the previous batch's loads and never lets future tokens influence earlier assignments.

What it is

This paper introduces Loss-Free Balancing, a way to keep MoE expert loads even without an auxiliary loss. Each expert carries a scalar bias that is added to its routing score only when choosing the top-K experts; after every training step the bias is nudged up or down by a fixed amount depending on whether the expert was under- or overloaded. Because the bias never appears in the backward pass, balancing stops fighting the language-modeling gradient. On 1B and 3B MoE models it improves both validation perplexity and load balance over auxiliary-loss training.

1Theory from first principles

The router's failure mode

A sparse MoE layer is only efficient if tokens spread across experts. Left alone, routers drift: a few experts win early, collect more tokens, get more gradient, improve faster, and win even more tokens. This is routing collapse, and it wastes exactly the capacity the model paid for. Imbalance also has a systems cost. Under expert parallelism each expert lives on a fixed device, so a hot expert becomes a straggler while its neighbors sit idle, and every step waits for the busiest device.

The auxiliary loss and its dilemma

The standard fix adds a differentiable penalty to the training objective: L_bal = alpha * sum_i f_i * P_i, where f_i is the fraction of tokens routed to expert i and P_i is its average gate score. Minimizing it pushes traffic off the popular experts. But its gradient has nothing to do with predicting the next token. It is an interference gradient whose strength is set by alpha, and the two objectives disagree: small alpha leaves the model imbalanced, large alpha balances it but degrades language modeling. Figure 2 of the paper draws this trade-off directly, and it is the dilemma the paper sets out to break.

Auxiliary balance loss (the thing to replace)

L_bal = alpha * sum_i f_i * P_i
f_i = (N / (K * T)) * count(tokens routed to expert i)
P_i = mean gate score of expert i

This term is differentiable on purpose, and that is the problem. Every gradient step now moves experts toward equal load as well as toward better predictions, and the balancing force grows with alpha. Removing the term and controlling load some other way removes the conflict.

Replace the loss with a bias

Loss-Free Balancing keeps the routing decision but takes it out of the objective. Each expert i carries a bias b_i, initialized to zero. Routing ranks experts by s_i + b_i, but the gate value that weights an expert's output is still the unbiased s_i, so the bias decides who gets picked and nothing else. After each training step the trainer reads the token counts from the previous batch and moves each bias one fixed step in the opposite direction of its load: overloaded experts go down, underloaded experts go up. No term in the loss changes, so no interference gradient exists.

Biased top-K routing: rank experts by s_i + b_i, weight their outputs by s_i. The bias steers traffic; the gate remains an honest affinity score.

Bias update (sign rule)

e_i = c_bar - c_i
b_i <- b_i + u * sign(e_i)

c_i is expert i's token count on the previous batch and c_bar is the mean count. An overloaded expert gets e_i < 0 and a smaller bias; an underloaded expert gets e_i > 0 and a larger bias. The update is a sign, not a learned function, so nothing flows backward, and using the previous batch keeps routing causal. u = 0.001 was best: larger values oscillate late in training, smaller values converge too slowly.

Load balance over training: the loss-free router tracks a low violation ratio, while the auxiliary-loss baseline is stuck at whatever balance its alpha coefficient can buy.
Bias-only routing and its update loop
python
def top_k_by_bias(scores, bias, k):
    order = sorted(range(len(scores)), key=lambda i: scores[i] + bias[i], reverse=True)
    return order[:k]

def update_bias(bias, counts, u=0.001):
    mean = sum(counts) / len(counts)
    for i, count in enumerate(counts):
        bias[i] += u * (1 if mean > count else -1 if mean < count else 0)
    return bias

bias = [0.0, 0.0, 0.0, 0.0]
print(update_bias(bias, [40, 10, 10, 10]))  # expert 0 is nudged down
  • The bias only matters at the margin of the top-K comparison; magnitudes stay tiny.
  • The gates returned with the chosen experts are the original scores, so gradients never see the bias.

What the experiments show

The authors train MoE models from scratch (1B parameters on 100B tokens, 3B on 200B) with a sigmoid gate and compare against the auxiliary-loss baseline tuned to alpha = 0.001. Loss-Free wins on both axes: 1B validation perplexity 9.50 versus 9.56 and MaxVio 0.04 versus 0.72; 3B 7.92 versus 7.97 and 0.04 versus 0.52. Two boundaries are handled explicitly. The bias update must use historical batches, because using the current sequence would break causality; and the rival Expert Choice approach achieves perfect balance but leaks information about future tokens (more than 50 bits per token in their 9-layer, 16-expert example), so it is rejected as unsafe.

2Inside the paper

Problem

MoE load imbalance causes routing collapse and wasted device time, and the standard cure, an auxiliary loss, fights the language-modeling objective through gradients whose strength has to be tuned.

Key idea

Keep balancing out of the loss. Add a per-expert bias to the routing score for top-K selection only, and update that bias after each step by a fixed step in the sign of the previous batch's load error. No gradient, no alpha trade-off.

Evidence

1B/100B-token and 3B/200B-token runs beat the auxiliary-loss baseline on perplexity and on MaxVio (0.04 versus 0.72 and 0.04 versus 0.52). The advantage grows with computation-batch size, which is what expert parallelism produces. Sweeps over update rate and update rule show the sign rule at u = 0.001 is the stable choice; proportional updates balance slightly better but score worse on perplexity, and multiplicative biases are worse on both.

What the authors admit

The method is a heuristic: it has one hand-set knob (u), it does not guarantee exact balance (the reported violation is 0.04, not 0), and it depends on tracking loads during training, which the causal variant handles by looking one batch back. The paper does not discuss behavior at trillion-parameter scale, where a later model in this era, DeepSeek-V3, keeps a tiny sequence-wise loss as a safety net for per-sequence extremes.

Practitioner takeaway

If a sparse model underperforms its dense counterpart, suspect the balance loss before the architecture. Try a bias-only router first: it is a few lines of code, adds no gradient, and can be combined with a very weak auxiliary loss only if a specific failure demands it.

3Implementation check

0 of 5 questions answered

  1. 1.In Loss-Free Balancing, what exactly is the bias added to?

  2. 2.Why is b_i updated with sign(e_i) instead of e_i?

  3. 3.Why must the bias update use the previous batch instead of the current one?

  4. 4.What problem does Expert Choice routing have that Loss-Free avoids?

  5. 5.On the 1B model, which pair of results is reported for Loss-Free versus auxiliary loss?

4Build it yourself

Balance MoE experts with bias, not gradient

Intermediate3-4 hours

Reproduce Loss-Free Balancing on a toy router: eight experts with skewed popularity and noisy scores, two chosen per token. Compare an integral load penalty that stands in for the auxiliary-loss gradient against the paper's sign update on a selection-only bias, and measure both load imbalance (MaxVio) and how far each method moves the gate scores away from their honest values.

Milestones

  1. Build the toy router: eight experts with fixed popularity gaps, noisy per-token scores, top-2 selection.
  2. Measure the uncontrolled MaxVio as the imbalance baseline.
  3. Implement the paper's update: after each batch, move each selection bias one step in the sign of the previous batch's load error.
  4. Implement the auxiliary-loss stand-in: an integral penalty added to scores, driven by the same load error.
  5. Sweep the penalty gain and the bias step and record MaxVio and gate distortion (mean absolute score adjustment) for both.
  6. Print the frontier: the balance each method reaches at a given amount of score distortion.
  7. Verify the bias never enters the gate that weights expert outputs, so its distortion is exactly zero.
Starter code
python · editable
Runs locally in your browser.

Success criteria

  • The uncontrolled router shows MaxVio >= 0.2, so there is real imbalance to fix.
  • The loss-free bias reaches MaxVio <= 0.03 with gate distortion 0.0.
  • The penalty controller reaches comparable MaxVio only at a gain whose distortion is many times the load error it corrects.
  • Results average the last 100 of at least 400 training steps and the script runs in under 10 seconds.

Stretch goals

  • Make the popularity distribution drift over time and compare how quickly each method tracks the moving optimum.
  • Try the paper's proportional update b_i += u * e_i and the multiplicative variant, and reproduce their ordering of MaxVio versus quality.
  • Add a second routing layer and show that imbalance compounds layer over layer when uncorrected.

5Keep going