Part X ยท Other kinds of models
Ch 37. Many experts
Every weight, every token
GPT-2 small is dense: all 124 million of its weights work on every token, so a bigger dense model is slower for every token. A mixture of expertsmixture of experts (MoE): A model whose MLPs are split into many experts, with a router sending each token to only a few of them. Ch 37 gets around this. It splits the MLP in each block into several smaller ones, the experts, and adds a small router that sends each token to only the best few.[1]
GPT-2 small is dense: every one of its 124 million weights takes part in predicting every token. Making a dense model bigger makes every token more expensive to process. A mixture of expertsmixture of experts (MoE): A model whose MLPs are split into many experts, with a router sending each token to only a few of them. Ch 37 gets around this. Take the MLP inside each block (Ch 10) and split it into several smaller MLPs, the experts. In front of them goes a small router: for each token, it scores every expert and sends the token only to the best few.[1][1]
Here is the router at work on โThe cat sat on theโ, choosing 2 of 8 experts for each token. Pick a token, and change how many experts each token gets:
Each tokenโs result blends the outputs of its chosen experts. The other experts donโt run for that token at all.
Each tokenโs output is a blend of its chosen expertsโ outputs, weighted by the routerโs scores. The other experts donโt run at all for that token, so their weights cost nothing. Different tokens go to different experts, so over a whole text every expert gets used.
The router, written down
For a tokenโs vector , the router multiplies by a weight matrix to get one score per expert, keeps the top , and turns those into weights with a softmax. The output is the weighted sum of the chosen expertsโ outputs:
Thatโs Mixtralโs layer, with .[2] The widget takes a softmax over all eight scores and then rescales the top to add up to 1, which gives the same weights.
Only the MLPs are split; attention and the embeddings are shared by every token. Thatโs why Mixtral uses 13 billion weights per token, not a quarter of 47. If each expert has weights and are shared, then billion and billion, so each expert holds about 5.7 billion and about 1.7 billion are shared.
Training needs a push to spread the work. A router that favors a few experts trains them more, which makes it favor them even more, so Shazeer and his colleagues added a loss term that penalizes uneven use.[1] DeepSeek-V3 balances its experts without an extra loss term.[3]
Big, but cheap to run
Many large open models work this way. Mixtral 8x7B has 47 billion weights but uses only 13 billion for each token.[2] DeepSeek-V3 has 671 billion and uses 37 billion.[3]
This is how many large open models are built. Mixtral 8x7B has 8 experts in each block and sends each token to 2 of them: it has 47 billion weights in total, but each token uses only 13 billion, about a quarter.[2][2] DeepSeek-V3 goes further: 671 billion weights in total, 37 billion per token, about 6%.[3][3]
You might imagine one expert for grammar and one for cooking, but trained experts donโt split the work that neatly. In Mixtral, they followed things like code syntax more than topics.[2]
It is tempting to imagine one expert for grammar, one for science, and one for cooking, but trained
experts donโt divide the work that neatly. When the Mixtral team checked which experts handled text
on different topics, they found no obvious pattern. What showed up instead was syntax: the word self in Python code, or the spaces that indent a line, kept going to the same experts.[2][2]
Recipe card
Recap
- A mixture-of-experts model splits each MLP into many experts, and a router sends each token to only a few of them.
- The model can hold far more weights than it uses for any one token: Mixtral uses 13 of its 47 billion.
- Experts arenโt neat topic specialists; the router learns its own way of dividing the work.
- The output is a weighted sum of the top experts; only the MLPs are split, so a token uses more than of the weights.
Next question: attention keeps every earlier token around, and that gets expensive for long texts. Could a model keep just a short summary instead?
Sources
- Noam Shazeer et al. (2017). Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer. ICLR 2017.
- Albert Q. Jiang et al. (2024). Mixtral of Experts. arXiv.
- DeepSeek-AI (2024). DeepSeek-V3 Technical Report. arXiv.
Sources
- Noam Shazeer et al. (2017). Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer. ICLR 2017.
- Albert Q. Jiang et al. (2024). Mixtral of Experts. arXiv.
- DeepSeek-AI (2024). DeepSeek-V3 Technical Report. arXiv.
Sources
- Noam Shazeer et al. (2017). Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer. ICLR 2017.
- Albert Q. Jiang et al. (2024). Mixtral of Experts. arXiv.
- DeepSeek-AI (2024). DeepSeek-V3 Technical Report. arXiv.