Mixture of Experts

Layer 2 · Mechanics

Mixture of Experts

The router, top-k gating, why load balance is a training-stability problem, and what expert parallelism does to a compute cluster.

9 min read70 XP

  1. Token embedding

  2. Router

    small linear layer → logits over experts

  3. Top-k selection

    pick k highest-scoring experts

  4. Dispatch

    send token to each chosen expert

  5. Weighted sum

    combine outputs by router score

One MoE feed-forward layer, per token. Attention layers are usually left dense.

Concretely, an MoE feed-forward layer replaces a single MLP with parallel MLPs ('experts') of the same shape, plus a router: a small linear layer producing logits per token. A softmax over those logits gives a probability-like weight per expert; top-k routing keeps only the largest (commonly or ) and zeroes the rest, so only experts do any compute for that token. The chosen experts' outputs are combined via a weighted sum using their (renormalized) router weights.

Go deeper: L3 Code