AI Hints
Home›Generative AI Tutorial›Under the Hood
Generative AI · Lesson 68 of 77

Mixture of Experts and Efficiency

Using only the part of the model you need.

⏱ 2 min read▶ Video at 2:32:54🎓 Free
Watch this lesson in the Generative AI courseWatch on YouTube ↗Full Generative AI course

Imagine a hospital, where every patient is examined by every single doctor. It would be slow, and wasteful. A mixture of experts model is built more sensibly. In this lesson, you will see how it works, and why many of the largest modern models use it.

Mixture of Experts and Efficiency
From the video: Mixture of Experts and Efficiency
  • Every doctor for every patient?
  • Send each token to the right experts
  • Bigger knowledge, lower cost

How a mixture of experts works

Inside the model, the feed forward part of a block is replaced by many smaller parts, called experts. A tiny router looks at each token, and chooses only a few experts, perhaps two out of many, to handle it. The other experts rest. So the model can hold a huge amount of knowledge, in total, while using only a small part of it, for each token.

  1. Token arrivesone piece of text
  2. Router decidespicks the best two experts
  3. Chosen experts workthe others rest
  4. Combine and continuethe answer moves up a layer

Why this matters

The benefit is efficiency. A model with hundreds of billions of weights in total, may use only a fraction, for each token. That makes it faster and cheaper to run, than a dense model of the same total size. The price is complexity. All the experts must still be stored in memory, and training them to cooperate is harder. Still, it is one of the most important ideas, for scaling.

Dense model

  • Every weight works on every token
  • Simple to build
  • Costly to run at large sizes

Mixture of experts

  • A few experts work per token
  • More knowledge for the same cost
  • Complex to train, big memory

Other efficiency ideas

Researchers are working on many other ways, to do more with less. Distillation, trains a small model, to imitate a big one. Pruning, removes weights that barely matter. Better data, so that smaller models learn more. And new designs, that handle very long text, more cheaply. The goal is always the same, more capability, per dollar, and per watt.

Distillationa small model learns from a big one
Pruningremove weights that barely matter
Better datasmaller models, smarter lessons
New designscheaper long-text handling

Summary

Good. A mixture of experts uses a router, to send each token to a few experts, so a huge model costs less per token. Distillation, pruning, and better data push efficiency further. Next, we learn how researchers measure whether one model is better than another.

Key takeaways
  • Router picks a few experts per token
  • More knowledge, same cost
  • Distillation, pruning, better data
Next up: Evaluating Language Models — perplexity, benchmarks and judges