A mixture-of-experts layer has 4 experts, each a feed-forward block with and hidden width (two weight matrices, no biases), and a router that picks the top 2 experts per token. For router logits over the four experts, what are the gate weights of the top-2 experts? Compare the total and active parameters of the layer with one dense feed-forward block, and compute the load-balancing loss for and for these experts?
Sequence models and transformers, Transformers
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you understand how sparse routing gives many parameters at a fixed per-token compute, and how the auxiliary loss pushes the router towards balanced use.
Key idea
The layer output is with gates from a softmax over the selected logits. Parameters grow with the number of experts, but per-token compute grows only with . The auxiliary loss (token fraction times mean router probability) equals when use is uniform, which is the balanced target (when tracks , as it does in training, it cannot go lower).
Steps
- Top 2 of logits are and . Softmax over just these gives and , total , so gates . Taking the softmax over all four and renormalising the top two gives the same numbers, since the common denominator cancels.
- One expert: parameters (M). The 4 experts hold (M), plus a router with weights, about M in total.
- Active per token: experts (M), plus the tiny router. So the layer stores the parameters of a dense block but uses only the compute per token.
- Load-balancing loss. is the fraction of tokens sent to expert and the average router probability for it. , so the loss is .
- For perfectly uniform use , so and the loss is . Here , so the router is imbalanced. Gradients flow through (differentiable), pushing probability from busy experts to idle ones.
- In practice experts also get a capacity limit per batch, and tokens beyond it are dropped or sent to the next choice.
Common mistakes
- Saying total compute scales with the number of experts. Only the selected run for each token.
- Forgetting that memory still scales with all experts, since all weights must be stored.
- Using only in the balance loss. comes from an argmax and has no gradient, so is needed to train the router.
How long your answer should be
Half a page; 4–5 minutes.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: A unigram language-model tokeniser has the vocabulary and probabilities h , u , g , s , hu , ug , hug , gs , ugs . Which segmentation of "hugs" does it choose, how is it found efficiently, and how does this differ from BPE?
Next in Sequence models and transformers: An encoder gives states , and . The decoder state is . Bahdanau (additive) attention scores each state as , here with and . Compute the attention weights and the context vector, and say when additive attention is preferred to dot-product scoring?