Bring the mental model from Scaled Dot-Product Attention & Transformer Layers; this page will reuse it instead of restarting from zero.
Efficiency
Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism
Conditional computation: a router picks a few experts per token. You can increase total expert parameters while keeping activated expert FFN compute small, but distributed systems may pay in communication and scheduling.

Concept Structure
Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learning map
Sparse Mixture of Experts: Routing, Load Balancing & Expert ParallelismConceptual Bridge
What should feel connected as you move through this page.
Conditional computation: a router picks a few experts per token. You can increase total expert parameters while keeping activated expert FFN compute small, but distributed systems may pay in communication and scheduling.
The next edge should feel earned: use the demo prediction here before following MoE Serving & Scheduling: Token Dispatch, All-to-All, Disaggregated Parallelism.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Sparse Mixture of Experts (MoE) is a conditional-computation layer pattern that routes tokens to a small subset of experts.
Instead of running the same dense MLP for every token, you keep a large set of expert MLPs and a small router that decides which experts each token should use. That buys you:
- Capacity: lots of total parameters (many experts).
- Efficiency: only run experts per token (small activated compute).
But it also sells you new problems: routing skew can overload experts, create stragglers, or drop tokens, and distributed expert-parallel implementations can introduce all-to-all communication. In MoE, "sparsity" is as much a systems story as a modeling story.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Router probabilities
Let a token hidden state be . A linear router produces logits and probabilities:
Top-k gating (sparse activation)
Let . Only experts in run:
Load balancing (avoid expert collapse)
In the cited MoE setups, routing can become imbalanced, so auxiliary losses and routing noise encourage balanced expert usage. A classic form uses:
- : fraction of tokens assigned to expert
- : average gating probability for expert
and:
Expert capacity (selected is not always served)
Top-k routing only proposes token-expert assignments. A serving or training system may also cap each expert at a finite number of token slots for the batch. If expert can accept assignments, then an assignment is served only while:
Once the expert is full, later assignments to that same expert overflow unless the implementation has an explicit rerouting or fallback rule. The important distinction is:
The interactive demo uses a deliberately simple dispatch rule: process tokens in batch order, fill each expert's slots, and mark later assignments to full experts as overflowed. Real implementations can add different overflow, padding, or rerouting policies, but they still have to account for finite expert capacity.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
rng = np.random.default_rng(0)
E, d, T = 8, 16, 2000 # experts, hidden dim, tokens
W = rng.standard_normal((E, d)) # router weights
h = rng.standard_normal((T, d)) # token hidden states
z = h @ W.T
p = np.exp(z - z.max(axis=1, keepdims=True))
p = p / p.sum(axis=1, keepdims=True)
top = p.argmax(axis=1) # top-1 routing
freq = np.bincount(top, minlength=E) / T # f_i
P = p.mean(axis=0) # P_i
L_lb = E * float(np.sum(freq * P))
print("freq f_i:", np.round(freq, 3))
print("mean gate P_i:", np.round(P, 3))
print("load-balancing loss:", round(L_lb, 3))
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Use the demo to predict whether a small batch's top-k token-expert assignments fit inside finite expert slots. The top-k candidates are visible before reveal; final loads and overflowed assignments are hidden until you commit to the capacity outcome. It is a teaching model, not a trained router or production load-balancing simulator.
Live Concept Demo
Explore Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Conditional computation: a router picks a few experts per token. You can increase total expert parameters while keeping activated expert FFN compute small, but distributed systems may pay in communication and scheduling.

Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism should make visible.
Visual Inquiry
Make the image answer a mathematical question
Conditional computation: a router picks a few experts per token. You can increase total expert parameters while keeping activated expert FFN compute small, but distributed systems may pay in communication and scheduling.
Which visible object should carry the first intuition?
Pick the cue that should make Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Introduces sparsely gated experts and the conditional-computation motivation behind MoE layers.
Open sourceGrounds top-1 expert routing, capacity tradeoffs, and the practical scaling recipe for sparse transformer experts.
Open sourceClaim Review
Conditional computation: a router picks a few experts per token. You can increase total expert parameters while keeping activated expert FFN compute small, but distributed systems may pay in communication and scheduling.
Claims without a substantive review badge still need exact source-support review.
shazeer-2017-sparsely-gated-moe, fedus-2021-switch-transformers
Use equation, code, and demo objects to check whether the source support is operational.
Shazeer defines trainable sparse/noisy top-k gating, many expert FFNs with only selected experts evaluated, and importance/load losses for imbalance. Fedus supports Switch top-1 routing, expert capacity/capacity-factor overflow and dropped tokens, f_i/P_i auxiliary load loss, and reduced-but-present dispatch/communication costs. Local witnesses instantiate router/top-k, load signals, and toy capacity overflow.
Sources: Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer, Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient SparsityReviewed routing/load/capacity mechanics only. Math/code/demo are toy local witnesses; no exact throughput, quality or specialization, all-to-all/expert-parallel implementation, scheduler optimality, serving latency/cost, or guarantee that MoE improves wall-clock performance.A bounded review summary is present; still check caveats and exact source scope.Shazeer supports trainable sparse/top-k MoE gating: only selected experts run, enabling large total expert parameters with limited active compute, plus importance/load balancing for skew. Fedus supports Switch top-1 routing, expert capacity/capacity-factor overflow tradeoffs, dropped tokens, the f_i/P_i auxiliary load loss, and reduced-but-present dispatch/all-to-all communication costs.
Reviewer: codex+oracle+codex-5.3; reviewed 2026-05-08Source support candidates
paper 2017Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts LayerIntroduces sparsely gated experts and the conditional-computation motivation behind MoE layers.
paper 2021Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient SparsityGrounds top-1 expert routing, capacity tradeoffs, and the practical scaling recipe for sparse transformer experts.
Practice Loop
Try the idea before it explains itself
Conditional computation: a router picks a few experts per token. You can increase total expert parameters while keeping activated expert FFN compute small, but distributed systems may pay in communication and scheduling.
Before touching the demo, predict one visible change that should happen in Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism
What is the smallest example that makes Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:efficiency/mixture-of-experts.
- Source ids to inspect: shazeer-2017-sparsely-gated-moe, fedus-2021-switch-transformers
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism Object key: concept:efficiency/mixture-of-experts Context: Efficiency Anchor id: concept/concept-notebook/efficiency/mixture-of-experts Open question: What is the smallest example that makes Sparse Mixture of Experts: Routing, Load Balancing & Expert Parallelism click without losing the math? Evidence to inspect: - Source ids to inspect: shazeer-2017-sparsely-gated-moe, fedus-2021-switch-transformers - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/efficiency/mixture-of-experts
concept:efficiency/mixture-of-experts