advanced35 min studyLesson 55 in Engineering

Sparse mixtures of experts

Follow routed tokens through expert capacity, communication, and load-balancing constraints.

On this page

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.

yt=∑e∈Stgt,eFe(xt),∣St∣=ky_t=\sum_{e\in\mathcal S_t}g_{t,e}F_e(x_t),\qquad |\mathcal S_t|=k
The selected set contains k experts. Gate normalization, capacity overflow handling, and auxiliary router objectives are architecture choices not fixed by this expression.↔ Scroll wide equations horizontally.

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.

C=⌈cTkE⌉C=\left\lceil c\frac{Tk}{E}\right\rceil
This is an illustrative per-expert assignment capacity with capacity factor c. Implementations may use different rounding and allocation rules. The formula reserves space; it does not guarantee every expert receives at most C assignments.↔ Scroll wide equations horizontally.

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.

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.

  1. Top-one routing creates 1,024 assignments, so the average load is 1,024/8=128 per expert.

  2. Capacity is ceil(1.25×128)=160 assignments per expert, allocating 1,280 slots across all experts.

  3. 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.

The result

An aggregate capacity larger than the token count can still overflow an individual expert. Quality consequences depend on the explicitly implemented overflow policy.

Explore the model

Interactive lab

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.

Inspect a bottleneck's backlogFluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Current readings: Fluid backlog: 4; Net rate · λ − μ: −1 /s; M/M/1 mean residence: 1 s. All parameters are adjustable with the labeled controls below.02.557.51001.534.56Elapsed time · sFluid backlogλ < μ
Fluid backlogCurrent time
Fluid backlog
4
Net rate · λ − μ
−1 /s
M/M/1 mean residence
1 s
t = 0 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.

Check your understanding

Which measurement is needed in addition to total and active parameter counts for a distributed sparse expert layer?

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.

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.