Auxiliary Balancing Loss › Load Balancing Loss Formulation

Michael BrenndoerferNovember 17, 20259 min read
Language AI HandbookAll chapters
Part 33 of 67Mixture of Experts
Chapter 244Auxiliary Balancing Loss › Load Balancing Loss Formulation
Reading section 4 of 13 · Load Balancing Loss Formulation · 9 minSection 4 of 13 · 9 min

Book contents

Section 4 of 13 · 9 min read

Auxiliary Balancing Loss › Load Balancing Loss FormulationOne section · Sections in this chapter4 / 13 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The Switch Transformer paper (Fedus et al., 2021) introduced a refined formulation that became the standard in modern MoE architectures. This newer approach addresses some limitations of the importance-based loss by more directly measuring actual routing behavior rather than just router preferences. Instead of using coefficient of variation, it directly measures two quantities and penalizes their correlation.

The Switch Transformer formulation separates two components of balance: routing outcomes, meaning how many tokens end up at each expert, and router intentions, meaning how much probability mass the router assigns to each expert. A well-balanced system should keep both in sync. If routing is balanced but router intentions are skewed, the balance is fragile and may break down. If router intentions are balanced but routing is skewed, the discrete selection step behaves unexpectedly.

For a batch of NN tokens and EE experts, we define two complementary measures of expert usage. The first captures what happens during routing, while the second captures what the router intended. Their product forms the balancing loss.

Fraction of tokens routed to expert ii:

fi=1N∑x∈batch1[argmax(g(x))=i]f_i = \frac{1}{N} \textstyle \sum_{x \in \text{batch}} \mathbf{1}[\text{argmax}(g(x)) = i]

where:

  • fif_i: the fraction of tokens routed to expert ii
  • NN: the total number of tokens in the batch
  • 1[⋅]\mathbf{1}[\cdot]: the indicator function, which is 1 if the condition is true and 0 otherwise
  • argmax(g(x))\text{argmax}(g(x)): the index of the expert with the highest probability for token xx
  • ∑x∈batch1[…]\textstyle \sum_{x \in \text{batch}} \mathbf{1}[\ldots]: the total count of tokens in the batch assigned to expert ii

This quantity measures the actual routing outcome. When the router makes its final decision for each token, selecting the expert with the highest probability, some experts will be chosen more frequently than others. The fraction fif_i counts how many tokens were ultimately sent to expert ii and normalizes by the total token count. This is the fraction of tokens where expert ii was selected (had the highest gate probability). It represents the actual load on each expert.

The important aspect of fif_i is that it reflects discrete decisions. A token is either routed to an expert or it isn't, and this binary nature means fif_i captures the ground truth of computational load. If expert 3 processes 40% of tokens, then f3=0.4f_3 = 0.4, regardless of whether those routing decisions were made with high confidence (probability 0.9) or narrow margins (probability 0.26 versus 0.25 for the runner-up).

Fraction of router probability assigned to expert ii:

Pi=1N∑x∈batchg(x)iP_i = \frac{1}{N} \textstyle \sum_{x \in \text{batch}} g(x)_i

where:

  • PiP_i: the fraction of router probability assigned to expert ii
  • g(x)ig(x)_i: the routing probability assigned to expert ii for token xx
  • NN: the total number of tokens in the batch
  • ∑x∈batchg(x)i\textstyle \sum_{x \in \text{batch}} g(x)_i: the sum of routing probabilities for expert ii across all tokens

This quantity measures the router's overall preference for each expert. Unlike fif_i, which counts discrete decisions, PiP_i aggregates the continuous probability values. This is the average probability the router assigns to expert ii across all tokens. It represents the router's "intention" to use each expert, capturing which expert wins the argmax competition and how confident the router is in its choices.

The distinction between fif_i and PiP_i is subtle but important. Consider a batch where half the tokens give expert 1 probability 0.51 and expert 2 probability 0.49, while the other half gives expert 2 probability 0.51 and expert 1 probability 0.49. The fractions P1P_1 and P2P_2 would both be approximately 0.5. This reflects balanced intentions. But if by chance the argmax consistently favors expert 1, then f1f_1 would be much larger than f2f_2, revealing the imbalance in actual routing.

The load balancing loss is the scaled dot product of these vectors. Before writing the formula, note what we want to compute: a quantity that is small when both fif_i and PiP_i are evenly distributed, and large when they concentrate on the same experts. The natural way to detect this joint concentration is to multiply the two vectors element-wise and sum:

Lbalance=E⋅∑i=1Efi⋅Pi\mathcal{L}_{\text{balance}} = E \cdot \sum_{i=1}^{E} f_i \cdot P_i

where:

  • Lbalance\mathcal{L}_{\text{balance}}: the auxiliary balancing loss
  • EE: the total number of experts
  • fif_i: the fraction of tokens routed to expert ii (actual load)
  • PiP_i: the average probability assigned to expert ii (intended load)
  • ∑i=1E\sum_{i=1}^{E}: the summation over all EE experts

The factor EE normalizes the loss so that perfect balance gives Lbalance=1\mathcal{L}_{\text{balance}} = 1. This normalization is a thoughtful design choice that makes the loss interpretable. A value of 1.0 means perfect balance, values above 1.0 indicate imbalance, and the magnitude tells us how severe the imbalance is. Under perfect balance, each expert receives fraction 1/E1/E of both tokens and probability, so fi=Pi=1/Ef_i = P_i = 1/E for all ii. We can verify the loss value:

Lbalance=E⋅∑i=1E(1E⋅1E)(substitute balanced values)=E⋅∑i=1E1E2(simplify terms)=E⋅(E⋅1E2)(sum constant E times)=1\begin{aligned} \mathcal{L}_{\text{balance}} &= E \cdot \sum_{i=1}^{E} \left(\frac{1}{E} \cdot \frac{1}{E}\right) && \text{(substitute balanced values)} \\ &= E \cdot \sum_{i=1}^{E} \frac{1}{E^2} && \text{(simplify terms)} \\ &= E \cdot \left( E \cdot \frac{1}{E^2} \right) && \text{(sum constant $E$ times)} \\ &= 1 \end{aligned}

When load is imbalanced, both fif_i and PiP_i grow for popular experts and shrink for unpopular ones. The correlation between these quantities drives the loss increase. Since both terms are larger for popular experts, their product is even larger, and the sum exceeds 1.

Why This Formulation Works

This loss formulation works because of what it penalizes. The product structure creates a natural feedback mechanism that targets exactly the behavior we want to discourage. Consider what happens when expert ii is overused:

  1. More tokens are routed to it, so fif_i increases
  2. The router assigns higher probabilities to it, so PiP_i increases
  3. The product fi⋅Pif_i \cdot P_i grows quadratically

This quadratic growth matters. When an expert is slightly overused, both fif_i and PiP_i increase slightly, and their product reflects this twice. When an expert is heavily overused, both quantities increase substantially, and their product amplifies the signal further. The loss creates a gradient that pushes the router to reduce probabilities for overused experts.

Only PiP_i contributes gradients, since fif_i involves a discrete argmax and is non-differentiable. But fif_i amplifies the gradient signal: popular experts get stronger pushback. The non-differentiable fif_i acts as a weighting factor, directing optimization toward high-load experts. Experts with high load receive stronger gradient signals on their probability terms, while experts with low load receive weaker signals. This adaptive weighting helps the optimizer prioritize the most severe imbalances.

The formulation also avoids a subtle failure mode. If we only penalized PiP_i variance, the router could game the system by assigning nearly uniform probabilities while still routing most tokens to one expert through tiny differences that favor the same expert. Imagine a scenario where the router learns to give expert 1 probability 0.251 and all other experts probability 0.2497. The probability distribution looks nearly uniform, so a variance penalty would be small. Yet the argmax would consistently select expert 1, creating severe imbalance. By including fif_i, we measure routing decisions rather than only intentions. The combined product fi⋅Pif_i \cdot P_i catches this gaming attempt because f1f_1 would be large even if P1P_1 increases only slightly.

Out[6]:
Visualization
Line plot showing load balancing loss value increasing as expert concentration rises from balanced to fully concentrated routing.
Load balancing loss as a function of expert concentration. The loss equals 1.0 under perfect balance (concentration=0) and increases quadratically as tokens concentrate on fewer experts, giving a strong gradient signal to correct imbalance.
Out[7]:
Visualization
Grouped bar chart comparing token fraction and probability fraction per expert across balanced, moderate, and severe imbalance scenarios.
Token and probability fractions under different imbalance levels. In the balanced scenario (left), distributions are uniform. In the severe imbalance scenario (right), one expert dominates both actual routing (f) and router probability (P).