Exercises — Mixture-of-Experts (MoE) architecture
Before we start, one reminder of every symbol you will meet, in plain words:
Level 1 — Recognition
L1.1
For an MoE layer with experts and Top- with : how many experts are stored, and how many do computation for a single token?
Recall Solution
Stored . Every expert physically exists and is trained. Compute for one token . Only the two highest-scoring experts run. This is the whole MoE idea: capacity (32) is decoupled from per-token compute (2). See Sparse vs Dense Models and Conditional Computation.
L1.2
Which quantity does the FLOP (compute) cost per token scale with — or ? State it in one line.
Recall Solution
Compute per token scales with (active experts), not (total experts). Growing grows knowledge/memory; only growing grows per-token compute.
L1.3
Name each of the four stages the router performs, in order.
Recall Solution
- Score — dot product , where is the router's learnable weight matrix and each output number is one score per expert.
- Softmax — turn scores into probabilities that sum to 1.
- Top- + re-normalize — keep the largest (their indices form the set ), zero the rest, rescale so used gates sum to 1.
- Combine — weighted sum , where is the output of expert (a small feed-forward network) on token , and is the Top- index set. Mnemonic: Score → Softmax → Top-k → Combine (one word per stage, matching the four steps above).
Level 2 — Application
L2.1
A model has experts, each expert holds M parameters, and . Shared (attention + embeddings + router) M params. Compute: (a) total expert params, (b) active expert params per token, (c) total params, (d) active params per token.
Recall Solution
(a) Total expert params . (b) Active expert params . (c) Total params . (d) Active params/token . The model knows like a 1.08B model but computes like a 68M one — a gap between capacity and cost. This gap is why Scaling Laws treat MoE so favourably.
L2.2
Router logits for a token are over experts, . Find the softmax probabilities, the Top-2 gates, and write the output .
Recall Solution
Softmax. , sum . . Top-2. Largest two are expert 2 () and expert 3 (). Expert 1 gets gate . Re-normalize. Denominator . , . Output. . Expert 1 is never evaluated. (Check : yes, so this is a proper convex blend.)

L2.3
Batch tokens, experts, capacity factor . Compute the expert capacity . If expert 5 receives tokens, how many are dropped?
Recall Solution
Expert 5 got , exceeding , so tokens are dropped — they skip the expert and pass through the residual unchanged. Higher capacity factor would reduce drops at the cost of more memory/compute.

Level 3 — Analysis
L3.1
An 8-expert layer trains without any auxiliary loss. After a while, one expert receives of tokens, three share the rest, and four are dead. Explain the mechanism that produced this, and name the loss that prevents it.
Recall Solution
Mechanism — "rich get richer." Early on one expert is slightly better, so the router raises its probability, so it sees more tokens, so it trains faster, so it gets even more tokens. This positive feedback loop is routing collapse: a few experts hog everything, the rest never receive gradients and stay useless. Prevention. The auxiliary load-balancing loss minimized when every (uniform usage). It nudges the router to spread tokens. Here is the small coefficient (typically ) that keeps this a gentle nudge rather than the main objective.
L3.2
Compute for two batches with , . Assume for simplicity. (a) Balanced: . (b) Collapsed: . Which is larger, and why is that the right direction for a penalty?
Recall Solution
Formula: (since ). (a) . So . (b) . So . Collapsed is larger (). Correct direction: the imbalanced batch is penalised more, pushing the router back toward uniform. The balanced case hits the theoretical minimum of (equals when perfectly uniform, since ).

L3.3
Why does the load-balancing loss use the soft probability rather than only the hard dispatch fraction ? What would break if you used alone?
Recall Solution
comes from a hard Top-/argmax decision — "which expert did we actually pick" — which is a step function. Its derivative with respect to router weights is zero almost everywhere and undefined at the jumps, so no gradient flows and the router can't be corrected. is the softmax probability: smooth and differentiable. Multiplying (which counts where tokens went) by (which is learnable) gives a term whose gradient actually reaches , letting the optimizer reduce imbalance. See Softmax and Gating Functions.
Level 4 — Synthesis
L4.1
You must design a MoE layer with a compute budget equal to a dense FFN with the FFN width (so expert-FFNs of compute per token), but you want maximum knowledge capacity. Each expert equals one standard FFN in size. Choose , then choose to hit a 32× capacity-to-compute ratio. Justify.
Recall Solution
Compute budget = 2 expert-FFNs per token set (each active expert costs one FFN). Capacity-to-compute ratio . We want this . So: , . Per-token compute stays at 2 FFNs while total expert capacity equals 64 FFNs — a gap. This is exactly the sparse-vs-dense lever: crank for capacity, hold for cost.
L4.2
Same layer (, ), batch tokens across the layer. You observe that in practice each expert receives up to its fair share when the router is nearly balanced. Pick a capacity factor that produces zero drops in this near-balanced regime, and compute .
Recall Solution
With , the total routing slots per batch . Fair share per expert slots. Peak observed load , round up to to cover it. Choose capacity factor so This meets the peak of tokens, giving zero drops in the near-balanced regime. Bigger factor = safer but more memory; this is the tightest choice that still avoids drops. Compare with Model Parallelism & Expert Parallelism where also fixes the fixed-size buffers each device allocates.
Level 5 — Mastery
L5.1
Prove that for fixed dispatch fractions with , the sum is minimized exactly when all , and state its minimum value. (This is why the balanced case is the loss minimum in L3.2.)
Recall Solution
By the Cauchy–Schwarz inequality (or the QM–AM inequality) applied to the vector and the all-ones vector : The left side is . Therefore Equality in Cauchy–Schwarz holds iff is proportional to , i.e. all equal; with that forces . Minimum value . Hence bottoms out at under perfect balance — matching L3.2(a) where gave .
L5.2
A token's logits are (all equal) with , . What are the softmax probabilities? What are the Top-2 gates? What subtle issue does this degenerate case expose about Top- routing?
Recall Solution
Softmax of equal logits is uniform regardless of : for all . Top-2 gates. Any two experts tie for "largest". After picking two and re-normalizing: each kept gate , so on the chosen pair. Subtle issue. With an exact tie, Top- selection is ambiguous — the choice of which two experts depends on tie-breaking (index order, floating-point noise). Routing becomes non-deterministic / discontinuous in the logits: an infinitesimal perturbation of one logit can flip which expert is chosen, giving a jump in . This is why the router is trained to produce peaked, well-separated logits, and why the gate values (not just the selection) receive gradient — smooth gates soften the otherwise hard, jumpy decision boundary.
L5.3
Under perfect load balance with experts and Top- routing, what fraction of the total expert parameters is touched on average by a single token, and what fraction of dispatch capacity is used? Give both as functions of , then evaluate for .
Recall Solution
Params touched per token. A token uses of the experts, so the fraction of expert parameters activated is Capacity used under perfect balance. Perfect balance means each expert receives exactly its fair share, so used capacity (fraction ). No drops, no idle slots. Formally, load per expert , and with capacity factor that equals exactly, so utilization . Takeaway. Each token wakes only of the expert weights (that's the conditional-computation saving), yet with balance the hardware is fully used — the ideal MoE regime. Sparse per token, dense per batch: that duality is the whole efficiency argument.
Recall Final self-check (cover and recite)
Compute scales with ::: (active experts), never . Re-normalize gates over ::: only the kept set , dividing by . Load-balancing loss form ::: , minimized at uniform . Capacity with Top- ::: driven by routing slots, not tokens alone. Minimum of ::: , achieved when all .