Sparse mixtures of experts
Follow routed tokens through expert capacity, communication, and load-balancing constraints.
On this page
The question for today
What you’ll understand
- Separate total expert parameters from active per-token computation.
- Calculate token capacity and identify routing imbalance.
- Explain why sparse arithmetic can still incur communication bottlenecks.
A sparse mixture-of-experts layer replaces one shared computation with several candidate experts and a router that selects a small subset for each token. It increases available parameters without applying every parameter to every token. The saved arithmetic introduces another problem: tokens must reach the correct expert, and expert workloads must remain manageable. Follow one routing batch from scores to dispatch and combine to see both the modeling opportunity and the systems cost.
Routing chooses a conditional computation
Suppose a layer has E feed-forward experts, each accepting a d-dimensional token and returning the same width. A router computes E scores per token. A top-k rule selects k experts and combines their outputs using specified gate weights. Some implementations normalize weights over the chosen experts, while others retain probabilities from the full router softmax. State that convention when reproducing an architecture because it changes output scale and gradients.
If expert architectures match, expert parameter storage grows roughly with E while active expert arithmetic per token grows roughly with k. Shared attention, router computation, embeddings, and other dense components still execute. Expert choice is usually token-dependent rather than a permanent assignment of semantic categories. A router selecting an expert for a token does not demonstrate that the expert has learned a clean human-interpretable specialty.
Average load does not bound peak load
For T tokens with top-k routing, the mean number of expert assignments is Tk/E per expert. Real routing is imbalanced, especially early in training or under distribution shift. A capacity factor allocates headroom beyond that mean. A finite-capacity design must define overflow behavior: drop a branch, reroute, pad to a buffer, or allow variable work. These policies can affect output quality, fairness across tokens, and reproducibility.
Load-balancing losses encourage useful utilization, but equal counts alone are not the entire objective. Experts with different sequence distributions can have different execution costs, and padding can waste compute even when average routing looks balanced. Record counts per expert, overflow rates, router entropy, and performance across data groups. A routing policy can appear efficient on one training distribution while concentrating a new tenant's traffic onto one device.
Dispatch is a distributed operation
When experts reside on different accelerators, dispatch and return commonly require all-to-all communication. Token representations and routing metadata move even though only a small subset of experts runs. Network bandwidth, topology, batch size, and overlap determine whether arithmetic savings become throughput gains. A very small local token batch may create tiny inefficient expert matrix multiplications. The slowest busy expert can also determine the layer's completion time.
Compare dense and sparse models at declared quality and serving budgets. Report total parameters, active parameters, peak memory, token throughput, and tail latency separately. Keeping all expert weights resident may exceed one accelerator even when active compute is modest. Loading experts on demand changes the memory-latency tradeoff. Evaluation must include router stability and overload behavior; a low average loss is insufficient evidence that every deployed batch fits its buffers.
Work it through
Count expert assignments and overflow
Route 1,024 tokens to one of eight experts with capacity factor 1.25. One expert receives 190 assignments. Assume a simple fixed-capacity policy with no rerouting.
Top-one routing creates 1,024 assignments, so the average load is 1,024/8=128 per expert.
Capacity is ceil(1.25×128)=160 assignments per expert, allocating 1,280 slots across all experts.
The busy expert exceeds its capacity by 190−160=30 assignments. Spare slots on other experts do not help automatically because the routing policy does not move those assignments.
An aggregate capacity larger than the token count can still overflow an individual expert. Quality consequences depend on the explicitly implemented overflow policy.
The living notebook
Explore the model
Interactive lab · queue
Inspect a bottleneck's backlog
The lab shows fluid backlog max(0,4+(λ−μ)t) for arrival and service rates. Treat it as a single busy expert's illustrative workload imbalance. Its separately labeled M/M/1 residence time assumes Poisson arrivals and exponential service and applies only when λ<μ; the lab is not a router or all-to-all simulator.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forUnused capacity elsewhere does not drain a bottleneck unless a real routing or scheduling mechanism can use it.
Pause & reason
Check your understanding
Your turn
Try it yourself
A routing batch has 600 tokens, six experts, top-two selection, and capacity factor 1.1. Compute average assignments and per-expert capacity. Does this guarantee no overflow?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Each token contributes two expert assignments, so count assignments before dividing by experts.
Compare with the solution
There are 1,200 assignments, averaging 200 per expert. Capacity is ceil(1.1×200)=220. This is not a no-overflow guarantee: a single expert may receive more than 220 assignments while others receive less. The algorithm must specify how such tokens are handled and whether that changes the combined output.
Keep the idea
Take it with you
- Conditional execution separates total parameter storage from active expert arithmetic.
- Capacity headroom does not remove routing imbalance.
- Communication, padding, and the busiest expert can dominate sparse-layer latency.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.