Auxiliary Balancing Loss › Load Balancing Loss Formulation
Language AI HandbookAll chapters 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 tokens and 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 :
where:
- : the fraction of tokens routed to expert
- : the total number of tokens in the batch
- : the indicator function, which is 1 if the condition is true and 0 otherwise
- : the index of the expert with the highest probability for token
- : the total count of tokens in the batch assigned to expert
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 counts how many tokens were ultimately sent to expert and normalizes by the total token count. This is the fraction of tokens where expert was selected (had the highest gate probability). It represents the actual load on each expert.
The important aspect of is that it reflects discrete decisions. A token is either routed to an expert or it isn't, and this binary nature means captures the ground truth of computational load. If expert 3 processes 40% of tokens, then , 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 :
where:
- : the fraction of router probability assigned to expert
- : the routing probability assigned to expert for token
- : the total number of tokens in the batch
- : the sum of routing probabilities for expert across all tokens
This quantity measures the router's overall preference for each expert. Unlike , which counts discrete decisions, aggregates the continuous probability values. This is the average probability the router assigns to expert 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 and 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 and would both be approximately 0.5. This reflects balanced intentions. But if by chance the argmax consistently favors expert 1, then would be much larger than , 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 and 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:
where:
- : the auxiliary balancing loss
- : the total number of experts
- : the fraction of tokens routed to expert (actual load)
- : the average probability assigned to expert (intended load)
- : the summation over all experts
The factor normalizes the loss so that perfect balance gives . 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 of both tokens and probability, so for all . We can verify the loss value:
When load is imbalanced, both and 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 is overused:
- More tokens are routed to it, so increases
- The router assigns higher probabilities to it, so increases
- The product grows quadratically
This quadratic growth matters. When an expert is slightly overused, both and 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 contributes gradients, since involves a discrete argmax and is non-differentiable. But amplifies the gradient signal: popular experts get stronger pushback. The non-differentiable 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 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 , we measure routing decisions rather than only intentions. The combined product catches this gaming attempt because would be large even if increases only slightly.

