What this is about
Most models use all of their numbers to produce every token. A mixture-of-experts model, or MoE, does not. It is built from many smaller parts called experts, and a small piece called the router chooses a few of them for each token. The rest stay asleep for that token.
So a model can be large in total and still do a modest amount of work per token. That is the trick, and it is why one of our biggest models runs on a single home graphics card.
Why it matters
Speed and size are usually linked. A bigger model is slower. An MoE breaks the link a little: the work per token depends on how many experts wake, not on how many exist. A model with 256 experts that wakes 8 does about eight experts' worth of sums per token in those layers.
But there is a catch you should know before you get excited. Sleeping experts still take up memory. All of them must be stored somewhere, because the router could pick any of them next. So an MoE saves effort per token, but it does not shrink the download or the memory you need.
How it works
Picture a hospital. When a patient arrives, a nurse at the door decides which two or three specialists should see them. The hospital employs 256 specialists, but any one patient sees only a few. The nurse is the router.
In an MoE model, each layer has its own set of experts and its own router. For each token, the router scores all the experts and picks the top few. Ours uses top-8 routing: eight of 256. The outputs of those eight are added together, weighted by the router's scores, and the result moves on to the next layer.
Different tokens wake different experts. A token in a math sentence might wake one set, and a token in a poem another. That is part of why speed differs from prompt to prompt, and why we never judge an MoE on one prompt.
Our example: the model that almost fit
Our model of this kind has 256 experts and its full weight pack is 21 gigabytes. Our card has 24 gigabytes. That works, barely. It stops working as soon as anything else wants memory, such as a long chat or the desktop.
So we built a version that keeps only the shared part of the model, 2.68 GB, on the card. The other 18.3 GB of expert weights stay in the computer's main memory, and the engine fetches the ones it needs. On our test of 20 prompts, it gave the same output as the full version every time.
At first it was slow: 39 tokens per second against 107 for the full version in the same session. Nearly the whole time went to waiting on fetches. One test showed a 1.74-second fetch out of a 1.75-second step.
Three fixes changed that, each measured.
- A cache of experts on the card. A cache of 64 slots, 4.5 GB, holds recently used experts. In a replay of 51,200 requests across 20 prompts it covered 76.7 percent of what the model asked for. The live run landed at 77.43 percent, inside the predicted band.
- Pinned memory. We locked the main-memory pages that hold the experts, so they can move to the card directly, without a detour through the operating system's file cache. Speed went from 48.57 to 67.12 tokens per second, with identical output. Nothing about the cache changed. It was only the road the bytes took.
- Reading a miss in place. For a missed expert, the math reads it straight from main memory while it computes, and the slot fills as a side effect. That gave 72.02, a gain of 1.064 times.
The full version of the same model reached 111.89 tokens per second in a comparable session. So the split version runs at roughly two-thirds of the speed, and in return it fits when the model otherwise would not.
What it costs
Locking 18.3 GB of main memory means nothing else on the machine can use it while the engine runs. On a 64 GB machine that also runs other jobs, that is a real cost.
We also have not tested the split design on a model whose experts truly do not fit in 24 GB. Tracing how that model's router picks experts is unfinished work. So we do not claim that it works for any size.
The reading side
Reading a prompt wakes nearly all 256 experts of a layer, not just 8, because a long prompt touches many different tokens at once. So for reading, the engine stages a whole layer's experts onto the card while the previous layer computes. That is covered in the article on prefill and decode.
Words you may not know
- Expert: one of many smaller parts inside an MoE layer.
- Router: the small part that chooses which experts handle each token.
- Top-8 routing: picking the eight best-scored experts.
- MoE: mixture of experts.
- Host RAM: the computer's main memory, as opposed to the card's.
- Pinned memory: main memory locked in place so data can move to the card fast.
- Cache hit rate: the share of requests the cache could answer without a fetch.
Try it
- See how our engine handles split models and the measured results on the mojo-baro project page. The page lists that it handles "split packs for MoE experts held in host RAM".
- When you shop for a model, look for two numbers: total size and active size per token. Total size sets the memory you need. Active size sets the speed you can expect.
- If you try an MoE at home, test at least twenty prompts before you believe a speed.
Read next
- Experts in Host RAM, the full story of the cache, the pinning and the zero-copy read.
- Forty-Two to One Hundred Eleven, how the full-pack version got faster in a day.

Komentarze
Brak komentarzy.
Zaloguj się aby skomentować.