Token embedding
Router
small linear layer → logits over experts
Top-k selection
pick k highest-scoring experts
Dispatch
send token to each chosen expert
Weighted sum
combine outputs by router score
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.