Rúben GalvãoThe Rabbit Hole

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

Mixture of experts (MoE): a big model that uses only part of itself

A model can hold hundreds of billions of weights. Does every token really need to use all of them?

In the feed-forward network, a token meets the weights the model learned during training. Those weights let it apply what it has learned to this token.

What if we give that network more room?

More weights, more work

Widen the feed-forward network and we add more weights: more capacity for the model to learn.

But those larger matrices take more multiplications. That extra capacity comes with more work to process each token.

A wider feed-forward network has more weights to use for every tokenTwo paths show the same token passing through an up projection, activation and down projection. The second path has taller up-projection and wider down-projection matrices: more learned weights, with more multiplications for each token.A smaller feed-forward networkActivationUpDownWiden the middleActivationUpDown
Both networks return a token-sized update. Widening the middle adds learned weights and more multiplications.

We could use fewer weights to do less work. But then we lose the extra capacity we just added.

Could we keep more weights, but use fewer for each token?

Keep the capacity, choose the work

Instead of one wider feed-forward network, put several smaller ones side by side. Each has its own learned weights.

A token could run through just a few of them. The others would stay available for tokens that need them.

These networks are the experts in a mixture of experts.

But which experts should a token use? We can let the model learn that choice too: multiply the token vector by another matrix of weights to produce a score for each expert. This is the router.

A dense feed-forward block, and a mixture of expertsTop: a token goes through one wide feed-forward block and the result is added to the residual stream. Bottom: a token goes to a router, which chooses two of eight experts; their outputs are multiplied by the router's weights, added together, and the sum is added to the residual stream.Dense blocktokenone big feed-forward blockgate, up, down: all weights used+residual streamMixture of expertstokenrouterexpert 1expert 2expert 3expert 4expert 5expert 6expert 7expert 8x 0.6x 0.4sum+residualstreamOnly the two green experts do any work for this token.The other six (dashed) still sit in memory.
What to notice: The router selects a few experts. Their weighted outputs combine into one update. Unselected experts remain available but do not run for this token.

Each chosen expert produces an update for the token. We weight these updates using the router’s scores, then add them together.

Hold more, run the same

For example, a model can keep hundreds of experts in a layer while sending each token through only a few.

The experts of the selected model and the few each token usesA grid of squares, one for each routed expert in a layer of the selected model. A few are green: the experts a token uses. Beside them is the model's total and active parameter count.
Each token uses only the experts highlighted in green.

Keep the number used fixed, then increase the pool below. How much more work does that token do?

More capacity, without running more experts

Interactive
TokenRouter weightsExpert scores

The expert pool

Violet: learned weights. Green outline: runs for this token.

Add experts and keep the number chosen fixed: the layer holds more weights, but each token still runs through the same few. Raise the number chosen and the work per token grows too.

That gap between weights held and weights used is the reason to build a mixture of experts.

Who decides?

The router reads the token after attention has gathered its context. So the same token can go to different experts in different sentences.

We can also cut the experts into more, narrower pieces, so the router has more combinations to choose from. Or add one expert that every token uses, a shared expert.

That raises two questions. If tokens choose different experts, what happens to work that many of them share? And what stops every token from choosing the same few? Follow them in shared experts and routing and load balancing.

Sources and assumptions

The idea comes from Jacobs, Jordan, Nowlan and Hinton (1991). Shazeer and colleagues (Google, 2017) made it sparse and large.

The model overview shows routed and shared expert counts from each architecture entry. Its squares represent several experts when there are more than 128. The interactive pool draws each routed expert separately and keeps the same token vector and router weights as the controls change. Its router is untrained; the scores and top-k selection are calculated from those vectors. The router matrix and score vector show compact samples. Shared experts are covered separately. All expert weights must be available even when only a few experts run for one token.

← Browse all subjectsBack to the beginning ↑