Why MoE Routing Works at the Token Level Instead of the Sentence Level
This article explains why Mixture-of-Experts (MoE) models route at the token level rather than assigning an entire sentence to a single expert. It covers how routing granularity shapes model capacity, why token-level routing expands the space of expert combinations exponentially, and how it stabilizes load balancing during training. It also shows why fine-grained routing is more hardware-friendly in distributed environments, highlights memory and low-precision pitfalls, and ends with a practical checklist for building MoE systems.
Why Mixture-of-Experts Routes at the Token Level, Not the Sentence Level
When you first work with a Mixture-of-Experts (MoE) architecture, the same question almost always comes up: selecting experts token by token adds routing and communication overhead, so it looks clearly less efficient than simply packing a whole sentence and handing it to one expert. That intuition holds in a single-machine, single-request setting, but in real distributed training and high-concurrency inference it reverses the actual cause and effect. This article aims to settle the question.
1. First, Clarify What Routing Granularity Selects
The core idea of MoE is to split a dense feed-forward layer into several structurally identical “experts” and add a lightweight gating network (the Router) that computes weights for the input and activates only a subset of experts. Routing granularity refers to the smallest unit the gating network scores and selects over.
- Sentence-level (sequence-level) routing: the entire input shares one set of experts. The gate output dimension is the number of experts, shared across the whole sequence.
- Token-level routing: every position in the sequence is scored and routed independently. The gate output shape is
[sequence length, num experts].
Schematically, the only difference is whether the gate input keeps the sequence dimension:
# Sequence-level: pool first, then score; one set of experts for the whole sequencepooled = hidden.mean(dim=1) # [B, D]gate = router(pooled) # [B, E]topk_idx = gate.topk(k, dim=-1).indices # [B, k]# Token-level: keep the sequence dimension and score each positiongate = router(hidden) # [B, S, E]topk_idx = gate.topk(k, dim=-1).indices # [B, S, k]
2. Expressiveness: An Exponential Gap in the Combination Space
This is the most irreplaceable reason for token-level routing. Let the number of experts be E, the number activated per token be k, and the sequence length be S. The number of expert-usage patterns a single sequence can exhibit is on the order of C(E, k)^S.
Take a common configuration in the industry: 256 routed experts plus 1 always-active shared expert, 8 experts activated per token, and a sequence length of 2048. Sentence-level routing can express only about C(256, 8) expert configurations, a fixed constant, while token-level routing raises that to the power of 2048. This is not a difference of one order of magnitude; it turns “constant-level model capacity scheduling” into “scheduling capacity that grows exponentially with sequence length.”
In language modeling, this difference shows up directly as modeling ability:
- Language is locally heterogeneous. Within a sentence, coreference resolution, syntactic constraints, entity recognition, and tone or style control are often handled by different feature subspaces. Sharing one set of experts across the whole sentence forces all subtasks to use the same parameters, so experts end up “learning a bit of everything” and their specialization advantage is erased.
- Shared experts carry general knowledge while routed experts carry differentiated patterns. This division of labor only holds stably under fine-grained routing. Once the granularity gets coarse, the boundary between shared and routed experts blurs.
- From an optimization perspective, fine-grained routing gives each expert a purer sample distribution and more consistent gradient directions, which leads to more stable convergence.
3. Load Balancing: Sentence-Level Routing Amplifies Imbalance
The most common failure mode in MoE training is expert collapse: the gate happens to favor a few experts early on, those experts receive more gradient and become stronger, so they get selected even more, forming a positive feedback loop. In the end most experts receive almost no gradient, and their parameters are wasted.
Sentence-level routing significantly worsens this because it makes too few “decisions.” In a batch, sequence-level routing produces only batch size selections, while token-level routing produces batch size × sequence length selections. With few selections, random fluctuations cannot be averaged out, the probability of repeatedly drawing popular experts rises sharply, and the Gini coefficient is naturally higher.
So engineering practice generally relies on two mechanisms, and both assume routing is fine-grained:
- Auxiliary balancing loss: minimize the product of how often each expert is selected and the average gate probability. A common approach uses the dot product of “dispatch counts” and “average gate probability” as a penalty term, with a small weight coefficient.
- Capacity factor and drop/overflow handling: set a capacity limit per expert,
capacity ≈ capacity factor × (total tokens / num experts) × k. Tokens beyond the limit go through a residual connection or are dropped, preventing individual experts from becoming hotspots and lengthening the critical path.
# Minimal illustration of the balancing auxiliary loss# f_i: fraction of tokens actually assigned to expert i; P_i: average gate probabilityaux_loss = num_experts * sum(f_i * P_i for i in range(num_experts))loss = task_loss + alpha * aux_loss # alpha is usually around 1e-2
4. Engineering Efficiency: Fine Granularity Is the Hardware-Friendly Option
Counterintuitively, token-level routing is actually faster in distributed settings, for three reasons:
- More balanced communication. Under expert parallelism, tokens must be routed to the devices hosting the experts. Fine-grained routing keeps the number of tokens each device receives close to the mean, so All-to-All has low load variance and little long-tail waiting. Sentence-level routing overwhelms some devices while others idle, and the synchronization barrier is gated by the slowest device.
- More regular compute shapes. After dispatch results are sorted by expert for grouped matrix multiplication, when token counts are large enough and the distribution is even, each group has a similar size, matrix multiplication shapes stay stable, and hardware utilization is high.
- Natural compatibility with sequence parallelism. The sequence dimension is already split across devices, so per-token decisions need no extra global pooling synchronization.
5. Memory and Precision: Two Easy Traps
The first trap is inference memory blowup. A naive implementation that “keeps every expert’s output for each token and then takes a weighted sum” multiplies activation memory by the number of experts. The correct approach computes only the selected k experts and accumulates their outputs by gate weight, so both memory and compute scale with k, not E.
The second trap is low-precision training. To reduce memory and bandwidth, the industry commonly uses mixed-precision schemes such as FP8: matrix multiplications run in low precision, while accumulation and normalization keep higher precision, with scaling factors calibrated block by block (block-wise). But low precision amplifies the numerical sensitivity of the gate, and tiny perturbations in routing scores can flip expert selection. So the gate and normalization layers usually keep higher precision, and expert outputs are constrained to a scaling range to avoid numerical explosion.
6. A Checklist If You Build MoE Yourself
- Default to token-level routing; do not fall back to sequence level to save communication.
- Keep at least 1 shared expert for general capability, use 8 to 256 routed experts (a common range), and set top-k to 1 to 8.
- Early in training, monitor each expert’s dispatch count and the gate entropy; entropy collapsing quickly is an early sign of collapse.
- Start the capacity factor tuning from 1.0 to 1.25, monitor the drop rate alongside it, and do not set it very high from the start.
- In low-precision training, keep the gate, normalization, and residual accumulation at higher precision, and calibrate scaling factors block by block.
- On the inference side, compute only the selected experts and avoid materializing all expert outputs.
Conclusion
“Handing a whole sentence to one expert” looks convenient, but it actually sacrifices three things at once: exponential combinatorial expressiveness, load balancing that can be stabilized by averaging, and communication balance in distributed environments. Token-level routing is not a shortcut or compromise in implementation; it is a necessary condition for making a sparse model “sparse with quality.” To put it into production, you can rely on a container platform for elastic scaling, use monitoring, alerting, and logging services to observe expert load and routing entropy, and turn the stability measures above into a sustainable engineering workflow for ongoing tuning.
