Top-K Routing › Top-1 Routing

Michael BrenndoerferNovember 15, 20259 min read
Language AI HandbookAll chapters
Part 33 of 67Mixture of Experts
Chapter 242Top-K Routing › Top-1 Routing
Reading section 2 of 12 · Top-1 Routing · 9 minSection 2 of 12 · 9 min

Book contents

Section 2 of 12 · 9 min read

Top-K Routing › Top-1 RoutingOne section · Sections in this chapter2 / 12 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Top-1 routing is the most extreme form of sparsity available in a Mixture of Experts architecture: each token is sent to exactly one expert, the one with the highest routing score, and all other experts are completely bypassed. This approach is also called hard routing because the decision is binary: a token either goes to an expert or it does not, with no intermediate values allowed. The simplicity of this approach is appealing because it maximizes the efficiency advantage of MoE. When each token visits only one expert, we can scale the number of experts arbitrarily without changing the computational cost for any individual token.

To understand why top-1 routing is so powerful, consider the arithmetic. If you have 64 experts and each expert's feed-forward network contains 1 billion parameters, the model has 64 billion expert parameters in total. But when routing each token to exactly one expert, only 1 billion of those parameters participate in computing the output for any given token. The other 63 billion parameters sit idle for that token, available to be activated for other tokens that the router deems appropriate. This separation between total model capacity (determined by N experts) and per-token computational cost (determined by K activations) is the basic economic advantage of sparse MoE architectures.

Think of top-1 routing as a binary tournament. Each expert submits a "bid" for each token in the form of a routing score. The highest bidder wins the token entirely. The losers receive nothing from that token, no gradient signal, no opportunity to refine their representation of that kind of input. This creates strong selective pressure: to win routing competitions, an expert must learn to be distinctively better than all other experts at some identifiable class of tokens. The result, when training works well, is a collection of specialists with sharply differentiated capabilities.

The Routing Computation

To understand how top-1 routing works, we will walk through the process step by step. The computation begins by projecting the token's hidden representation through the router's learnable weight matrix to obtain a score for each expert. Specifically, we compute the routing scores (logits) for all experts by projecting the token representation x\mathbf{x} through the router's learnable weights WrW_r:

h=Wrx\mathbf{h} = W_r \mathbf{x}

where:

  • h\mathbf{h}: the vector of routing logits (scores) for all experts, one score per expert
  • WrW_r: the router weight matrix of shape (num_experts×hidden_dim)(\text{num\_experts} \times \text{hidden\_dim})
  • x\mathbf{x}: the input token representation vector of dimension hidden_dim\text{hidden\_dim}

This linear transformation is a compatibility function. Each row of the weight matrix WrW_r can be thought of as a "query vector" for one expert, and the dot product between this query and the token representation measures how well-suited that expert is for processing this particular token. A high dot product means the token's representation is well-aligned with what this expert has learned to handle. Higher scores indicate stronger affinity between the token and the expert.

Why a linear transformation? A more complex routing function, perhaps a small neural network, might produce better routing decisions. The linear router has a practical advantage: it is computationally cheap. Routing must happen before any expert computation, so the overhead of the router should be minimal relative to the cost of the experts themselves. A single matrix multiplication accomplishes this efficiently. Because it operates on the same hidden representation that the model uses for everything else, the linear router can use that representation's full semantic content to make routing decisions.

Then, top-1 routing selects the single expert with the highest score:

k∗=arg⁡max⁡ihik^* = \arg\max_i h_i

where:

  • k∗k^*: the index of the selected expert
  • arg⁡max⁡i\arg\max_i: the operation that finds the index ii maximizing the value
  • hih_i: the routing logit (score) for the ii-th expert

The argmax operation identifies the expert with the highest score. This expert then processes the token. The output for that token becomes simply the output of the selected expert:

y=Ek∗(x)\mathbf{y} = E_{k^*}(\mathbf{x})

where:

  • y\mathbf{y}: the output vector for the token
  • Ek∗E_{k^*}: the feed-forward network function of the selected expert k∗k^*
  • x\mathbf{x}: the input token representation vector

This formula is strikingly clean. The entire computation of the expert layer for this token reduces to a single feed-forward pass through one expert network. There is no mixing, no weighting, no combination: just a direct pass through the winner.

The Straight-Through Estimator Problem

Top-1 routing introduces a significant challenge that is easy to overlook at first: the arg⁡max⁡\arg\max operation is not differentiable. Backpropagation requires gradients, and gradients require the operation to be continuous, but argmax produces a discrete integer index that jumps discontinuously as inputs change. How do gradients flow back through a hard selection?

The standard solution uses the straight-through estimator. It uses different computations for the forward and backward passes, accepting the inconsistency as a pragmatic compromise that enables training. During the forward pass, the token goes through only one expert via true hard arg⁡max⁡\arg\max selection. During the backward pass, the operation is treated as a softmax, allowing gradients to flow back to all experts in proportion to their routing probabilities.

Why does this work? Intuitively, the straight-through estimator provides a smooth surrogate for the discrete selection. Experts with higher routing probabilities receive larger gradient signals, which encourages them to specialize further for the types of tokens that currently prefer them. Experts with lower routing probabilities receive smaller gradients, but they still receive some signal, which prevents them from becoming completely unused. The inconsistency between forward and backward passes is a known theoretical weakness, but empirically it works well enough for MoE training to succeed.

Straight-Through Estimator

The straight-through estimator is a technique for backpropagating through discrete operations by using the discrete value in the forward pass but treating the operation as if it were continuous (typically using softmax probabilities) in the backward pass. The gradient flows straight through the discrete bottleneck as if the argmax had never happened. This creates a deliberate mismatch between forward and backward computations, but it provides a useful approximation that enables training to proceed. The technique was introduced by Hinton (2012) and is widely used in training models with discrete latent variables.

Forced Specialization and Its Consequences

Top-1 routing has another characteristic that can be either a feature or a bug depending on your perspective: it forces complete specialization. Each token must commit fully to one expert's computation, with no blending of perspectives from multiple experts. This creates strong incentives for experts to carve out distinct semantic territories: an expert that specializes narrowly and deeply in a particular kind of input will consistently win the routing competition for that kind of input, while a generalist expert that is merely adequate at everything may rarely be selected.

The flip side of this forced specialization is that it makes the model brittle at boundaries. Consider a token that sits semantically between two categories. With top-1 routing, the model must make a definitive choice about which category's expert to use, potentially losing the fine-grained perspective that a second expert could have contributed. A technical legal term, for instance, might benefit from both a "technical vocabulary" expert and a "legal phrasing" expert, but top-1 routing must choose just one. The model learns to handle these boundary cases as best it can given the hard constraint, but the constraint itself limits expressiveness in a way that top-2 routing avoids.

Out[3]:
Visualization
Bar chart of routing logits for 8 experts, with E3 and E7 highlighted as the two highest-scoring experts.
Router logits for 8 experts. E3 (2.1) and E7 (1.8) show the highest affinity scores for the current token, with the remaining experts scoring between 0.3 and 1.5.
Bar chart showing top-1 routing weights, where all weight is assigned to expert E3 and all other experts receive zero.
Top-1 routing weights. The entire probability mass collapses onto expert E3, the single highest-scoring expert, creating a sparse binary weight vector.
Bar chart showing top-2 routing weights, where E3 and E7 share the probability mass via softmax normalization.
Top-2 routing weights. Probability mass is split between the two highest-scoring experts (E3 and E7) via softmax normalization, letting gradient flow to both.