Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / Choosing and combining experts

Routing: selecting experts and weighting their work

A token has hundreds of experts to choose from. Who gets the job, and what if everyone chooses the same few?

Our mixture of experts gives a token several networks it could use. How does it choose?

The token vector already carries its context. We can let the model learn a choice from that same information.

One score for each expert

We have used learned matrices to turn token vectors into queries, keys and values. We can do the same here, but make the output a score for each expert.

A token vector multiplied by learned router weights gives four expert scoresToken vectorLearned router weightsExpert scores1: -0.342: -0.423: 0.154: -0.31The weights are learned during training
One row of router weights for each expert. Multiplying by the token vector produces one score per expert.

Training adjusts these weights alongside the experts. This scoring network is the router.

Most routers are this single matrix. A few models put a small multi-layer network in its place to compute the scores.

Which outputs should count?

We need more than a choice. If two experts produce different updates, how much of each should we use?

First, turn the scores into positive numbers. One approach uses sigmoid, which puts each score between zero and one. Other routers use softmax.

Keep the highest-scoring few. This is top-k selection: with k = 2, two experts run.

Then divide their scores by their sum. Those proportions tell us how to weight the experts’ outputs.

Sigmoid scores select two experts, then their scores set the proportions of the outputExpert 10.42Not selectedExpert 20.40Not selectedExpert 30.54SelectedExpert 40.42SelectedDivide each selected score by their sum0.57 + 0.82 = 1.39Expert 3 output× 0.56Expert 4 output× 0.44+Routed update
Only the selected scores enter the proportions. Here, experts 3 and 4 contribute about 41% and 59% of the routed update.

Multiply each output vector by its proportion, then add the vectors together. That gives us the routed update.

What if the same experts keep winning?

So far, we have followed one token. Now send a batch through the router.

A few experts might receive nearly all the tokens. If experts are spread across devices, some devices wait while others work through a queue.

Could we encourage a more even spread without changing the scores used to weight the outputs?

During training, we can count how much work each expert receives. Give underused experts a small positive selection bias, and busy ones a negative bias.

Same tokens, a more even workload

Interactive

The same 24 tokens pass through the router. Each chooses two experts.

One of those tokens

The adjusted scores decide which experts run. Their original positive scores still determine how their outputs are combined.

The chosen set can change, so its proportions are calculated again. The balancing bias itself never enters that calculation.

Another approach adds a training loss that penalises uneven use. Both give the model a reason to spread work beyond the busiest experts.

Back to the token

The weighted outputs form the feed-forward update, which is added to the residual stream. A shared expert can contribute alongside them without competing for a place in the selected set.

Sources
  • Sparsely-Gated MoE, for learned routing, sparse expert selection and load balancing.
  • DeepSeek-V3 report, §2.1.2, for sigmoid affinity scores, normalisation over selected experts and a selection bias adjusted during training. It also uses a small complementary sequence-wise balancing loss.
  • Llama 4 implementation, for another routing and weighting design.

The diagrams use four experts. The first diagram calculates scores from a fixed token vector and router matrix; the weighting diagram uses those same scores. The balancing example keeps one batch of 24 token vectors’ scores fixed while updating biases from expert counts. Its lower diagram follows one token from that batch. It demonstrates the sigmoid-based selection rule, without grouped routing or an overall output scale.

← Browse all subjectsBack to the beginning ↑