Auxiliary Balancing Loss › Worked Example: Computing the Balancing Loss by Hand
Language AI HandbookAll chapters Auxiliary Balancing Loss › Worked Example: Computing the Balancing Loss by HandOne section · Sections in this chapter5 / 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
To solidify the mechanics of the load balancing loss, let's work through a small concrete example step by step, using numbers that are easy to follow. We will use a batch of 8 tokens and 3 experts, and trace through the entire computation manually.
Imagine we have a batch of 8 tokens and the router produces the following probabilities for each token. Each row sums to 1.0 because the probabilities come from a softmax operation.
| Token | Expert 0 | Expert 1 | Expert 2 | Selected |
|---|---|---|---|---|
| t1 | 0.70 | 0.20 | 0.10 | 0 |
| t2 | 0.60 | 0.25 | 0.15 | 0 |
| t3 | 0.15 | 0.65 | 0.20 | 1 |
| t4 | 0.10 | 0.70 | 0.20 | 1 |
| t5 | 0.55 | 0.30 | 0.15 | 0 |
| t6 | 0.20 | 0.15 | 0.65 | 2 |
| t7 | 0.65 | 0.25 | 0.10 | 0 |
| t8 | 0.25 | 0.60 | 0.15 | 1 |
Notice that Expert 0 is selected most often (4 out of 8 tokens), while Experts 1 and 2 receive 3 and 1 tokens respectively. This is a moderately imbalanced distribution that our loss should detect.
Step 1: Compute (fraction of tokens routed to each expert)
Count the tokens assigned to each expert via the argmax, then divide by 8:
Under perfect balance with 3 experts, we would expect each . Expert 0 is overloaded at 0.5, and Expert 2 is underloaded at 0.125.
Step 2: Compute (average router probability per expert)
Sum the probabilities in each expert's column, then divide by 8:
We can verify: . This must always hold because the softmax probabilities for each token sum to 1, so summing across all tokens and then averaging preserves this property.
Step 3: Compute the load balancing loss
We compute the dot product of and , scaled by :
The loss of 1.1156 is above the perfect-balance baseline of 1.0, confirming that the distribution is moderately imbalanced. The deviation is modest because the imbalance itself is moderate; if Expert 0 had received all 8 tokens, the loss would be much higher. Under perfect balance with experts, we would have for all , and the loss would compute to exactly 1.0.
Intuition check: The product is largest for Expert 0. It receives the most tokens and has the highest average probability. This is the "double penalty" mechanism: an overloaded expert contributes disproportionately to the sum because both factors increase.