Exercises — Load balancing in MoE
Quick symbol refresher (so nothing is used before it is named):
Before the exercises, one picture to keep in your head. The figure below plots both quantities side by side — cyan bars are the hard dispatch fractions , amber bars are the soft router probabilities — first when the layer is perfectly balanced, then when it has collapsed onto expert 1. Notice in the collapsed panel how towers over the rest (the amber arrow marks the overloaded expert whose the gradient will shove down) while expert 3 is starved to (cyan arrow). Refer back to this whenever a problem talks about "overloaded" or "starved" experts.

Level 1 — Recognition
L1.1
A Top-2 MoE layer has experts. In a perfectly balanced batch, what fraction of tokens does each expert receive, and what value should each router probability settle to?
Recall Solution
Perfect dispatch balance means . With : . Perfect probability balance means . Note these are different numbers — sums to , sums to . Confusing them is the classic slip.
L1.2
State, without deriving, which of and carries a gradient during backprop, and why the other does not.
Recall Solution
carries the gradient — it is a smooth softmax output of . does not — it is built from an indicator function (a hard yes/no count). Its derivative is zero almost everywhere, so backprop treats as a constant.
L1.3
Write the Switch Transformer auxiliary loss and identify each factor.
Recall Solution
- : small weight (typically ), already inside the loss.
- : normalizer so the balanced value is scale-free.
- : constant load factor (measured dispatch).
- : differentiable probability the gradient acts on.
Level 2 — Application
L2.1
, , Top-1. Dispatch: tokens 1–4 → E1, tokens 5,6 → E2, token 7 → E3, token 8 → E4. Router averages . With , compute .
Recall Solution
Fractions: , and indeed . ✓ Dot product: Loss: .
L2.2
Same layer, now perfectly balanced: , for all . Compute and confirm it equals the fixed-point prediction .
Recall Solution
. . Fixed-point formula: . ✓ Matches. The imbalanced case (L2.1) gave — imbalance always sits above the floor.
L2.3
Capacity factor. , , . What is each expert's capacity? In L2.1's dispatch, how many tokens does E1 drop?
Recall Solution
Capacity tokens per expert. E1 was assigned 4 tokens but can hold only 2 → it drops tokens. Those two tokens skip the expert and pass through as a residual.
Level 3 — Analysis
L3.1
Show that the gradient of with respect to is , and explain in one sentence why this makes the loss a feedback controller.
Recall Solution
Treat each as constant (L1.2). Then The push to lower is proportional to the current measured load . Overloaded experts (big ) get their probability shoved down hardest; because , that freed mass flows to under-used experts. That load-proportional correction is the feedback loop.
L3.2
Fact 1 from the parent note claims the bare dot product , under only and , is minimized at a corner, not at uniformity. Demonstrate this: with , , fix and find the (subject to , ) that minimizes .
Recall Solution
With fixed, is a weighted average of the using weights . To minimize a weighted average, dump all weight on the smallest . The smallest are . So put (or ): all tokens to expert 3. Value . Compare uniform giving . The corner () beats uniform (). So the bare dot product does not prefer uniformity — this confirms Fact 1. Balance emerges only because is a measured constant and gradients act on (L3.1), not because the dot product itself is uniform-loving.
L3.3
Suppose the router collapses: and (router mirrors the load), , , . Compute and compare to the balanced floor .
Recall Solution
. . Floor: . The collapsed loss () is over triple the balanced floor — exactly the strong corrective signal we want.
Level 4 — Synthesis
L4.1
Design a mini training step. , , Top-1. Current router logits give , and the current hard dispatch gives (E3 got starved this batch). Using with : (a) compute the gradient on each ; (b) state which expert's probability gets pushed down hardest and which experts get no auxiliary push, and explain the consequence.
Recall Solution
(a) : (b) E1 () gets pushed down hardest — it's the overloaded chef. E3 gets gradient : because it was starved (), the aux loss does not lower its probability at all. Since gradient descent reduces and softmax renormalizes (), the freed probability mass flows toward E3 (and the others). Next batch E3 receives more tokens — the controller self-corrects.
L4.2
Combine load balancing with capacity. , , Top-1, . Router dispatches (8 tokens), (4), (2), (2). (a) Compute per-expert capacity. (b) How many tokens does each expert drop? (c) What is the total number of dropped tokens, and what fraction of the batch is that?
Recall Solution
(a) Capacity tokens per expert. (b) Drops :
- E1: dropped.
- E2: .
- E3: .
- E4: . (c) Total dropped . Fraction . Interpretation: raising from (capacity , would drop ) to (capacity , drops ) reduces token loss but costs more memory per expert — the core capacity trade-off.
Level 5 — Mastery
L5.1
Prove the fixed-point value. Show that when both dispatch and probability are perfectly balanced (, for all ), the auxiliary loss equals exactly , independent of .
Recall Solution
The from the sum-of--equal-terms and the outer combine: . The 's cancel completely → floor is , a constant chosen so different-sized MoE layers report comparable balanced losses.
L5.2
Sensitivity / worst case. For fixed and with experts, and the worst collapse where a single expert takes everything (), express and compute the ratio of worst-case to balanced-floor loss for . Then say what this ratio tells you about the loss's dynamic range.
Recall Solution
Worst case: , so . Floor: (since ). Ratio . So the loss ranges over a factor of between full collapse and perfect balance. With more experts, the dynamic range grows — the aux loss shouts louder (relative to its floor) precisely when there are more experts to potentially waste, giving proportionally stronger correction where it matters most.
L5.3
Full pipeline. , , Top-1, , . A batch dispatches with router probabilities , and the task loss for this batch is . Compute (a) , (b) , (c) capacity and tokens dropped by the busiest expert.
Recall Solution
(a) . . (b) (no double ). (c) Capacity . Busiest expert E1 has tokens → drops tokens.
Recall Self-test recap
Balanced dispatch fraction with Top-2, N=8 ::: Balanced router probability with N=8 ::: Which quantity carries the gradient ::: (differentiable softmax) Gradient of aux loss w.r.t. ::: Balanced fixed-point loss value ::: Worst-case (full collapse) loss value ::: Expert capacity formula ::: Tokens dropped by an expert :::
Related: Switch Transformer · GShard · Top-K Routing in MoE · Expert Capacity and Token Dropping · MoE Training Dynamics · Gradient Routing in MoE · Mixture of Experts (MoE) Architecture