Mixture of Experts (MoE) Explained

Photo: Jacob Bobo
The ballooning size of AI large language models is arguably the most serious problem holding back widespread adoption of LLMs on local hardware. Models with more parameters tend to score better in benchmarks than those with fewer, but increasing the number of model parameters also increases the compute performance required to run the model at inference, as well as the space it takes up in memory.
However, there is one recent innovation that's helping to reduce the problem: a mixture-of-experts (MoE) model architecture. An LLM with a MoE architecture only activates a small portion of its parameters when responding to a prompt.
How Mixture-of-experts models work
A typical LLM generates a response by processing tokens through dozens of layers. Doing so requires many compute steps as tokens are processed through the layers to compute a probability for the next token. Every model parameter contributes to the final result. This type of model is referred to as a "dense" model.
Modern LLMs with a mixture-of-experts architecture instead call on only a portion of the model parameters. This is known as sparsity, and models trained for this are referred to as "sparse" models. As you might expect, reducing the parameters involved also reduces compute requirements and in turn improves the tokens-per-second output a model can achieve on any given hardware.
Of course, there's an obvious problem with this approach. A sparse model that activates only some parameters is likely to be less intelligent, because many parameters contribute nothing to its output. That's where the "experts" come in.
Each expert is a grouping of related model parameters. One expert might contain parameters relevant to nature, while another might have parameters relevant to adjectives, and another might have parameters relevant to dates and calendars.
These categories are only examples. In reality, the way MoE models group knowledge is somewhat mysterious. The knowledge each expert has isn't determined manually by the model's creators but instead emerges during training. The experts can have parameters related to many concepts people wouldn't generally consider linked, or may be specialized in ways that people don't commonly associate with expertise. The degree to which MoE model experts truly specialize remains a subject of debate among AI researchers.
Model architectures also vary in how the experts are grouped. Some MoE models activate just one expert at a time, while others activate two or a few. Some MoE models are trained with a smaller number of experts that have many parameters, while others prefer many experts with very few parameters. And some MoE models have a shared expert that is always active.
But the precise details of how each expert's parameters are grouped is not all that relevant at a glance. The important bit is that it becomes possible to activate a smaller number of model parameters relevant to each token processed by the model. That improves the model's speed at inference, which in turn makes the model a lot less demanding.
Mixture-of-experts doesn't reduce memory requirements...
As previously stated, mixture-of-experts models activate fewer parameters as they generate each token, and that in turn reduces the compute the model requires.
And yet, MoE models don't reduce the size of the model. If all else is equal, a dense model with 30B parameters will be roughly equal in size to a sparse MoE model with 30B parameters, and the models will occupy a similar amount of memory in use.
The parameters may not all be active at once, but they're still there, and they're usually all loaded into memory.
In theory, it would be useful to only load the active parameters into memory. This would greatly reduce the memory footprint of a model.
However, models typically process dozens or even hundreds of tokens per second, and each token may require access to a different expert. Trying to load active parameters into memory only as needed would cause the model to stall as activated parameters make the slow journey from your PC's hard drive into memory.
In the long run, we may see new computer architectures built to solve this problem. New types of storage, like high-bandwidth flash, may become pools of fast read-optimized storage for model weights.
...but there are tricks that let MoE models use both CPU and GPU memory
While mixture-of-experts models don't eliminate the need to store the entire model in memory, there's a trick that can take advantage of the MoE model's architecture. Now, I want to be clear—in my experience this isn't a silver bullet. But it exists, and it's worth a look.
As mentioned, MoE models are trained to group related parameters into "experts." However, these models still have a small number of parameters that are always active. These include the self-attention layers, as well as the routing mechanisms which decide which expert or experts to activate.
That means it's possible to place parameters in different portions of memory. On a local PC, this usually means the parameters that are always active are placed on VRAM and handled by the GPU, while the experts are placed into system RAM and handled by the CPU. MoE's architecture makes this sort of CPU off-loading more viable.
Don't get too excited, however.
This means a portion of model inference will happen on the CPU, and using a CPU for AI inference is not great for tokens-per-second performance. The bandwidth between the CPU and GPU is a bottleneck, too.
CPU off-loading is also rather finicky in my experience. I've received a lot of errors when attempting to use it through Ollama and LM Studio.
MoE models are the new reality
Mixtures-of-experts models actually date all the way back to 1991, but it didn't come into vogue for LLMs until the 2023 release of Mixtral 8x7B. Its popularity has only grown since then, and the majority of LLMs meant for use on local hardware now use it.
That's a positive development for people looking to use LLMs on their own PC. MoE models generate tokens more quickly than their dense counterparts without much impact on model quality.
In short, MoE models are almost all upside, and a great fit for local AI.
More from MC News
- Run AI Locally: The Best LLMs for 8GB, 16GB, 32GB Memory and Beyond
- How to Use Local AI With Your Own Files: A Beginner's Guide to RAG
- Reading vs. Answering: The Two Hardware Bottlenecks Behind Local AI Performance
- How to Use a Local LLM in Visual Studio Code
- Hands-On with the AMD Ryzen AI Halo
- Quantization Explained: Why the Same LLM Gives Better Results on High-End Hardware
- Why Context Length, Not AI Model Size, Is Your Biggest VRAM Problem
- How to Use LM Studio to turn your PC into an AI Server
- Why VRAM and Memory Bandwidth are Key for Powering Local AI
- Keyboard 101: Intro to Computer Keyboards
- Fix It Yourself: Talking to iFixit on Why Repairable Tech Matters
- The Local LLM Your Laptop's Been Waiting For
- Gemma vs Qwen: Which Local AI is Best?
Matthew S. Smith is a prolific tech journalist, critic, product reviewer, and influencer from Portland, Oregon. Over 16 years covering tech he has reviewed thousands of PC laptops, desktops, monitors, and other consumer gadgets for publications including PC World, Reviewed, PC Mag, MIT Tech Review, The Verge, Ars Technica, Wired, and Business Insider. Matthew also hosts Computer Gaming Yesterday, a YouTube channel dedicated to retro PC gaming, and covers the latest artificial intelligence research for IEEE Spectrum.
Comment on This Post
See More Blog Categories
Recent Posts
Why Apple Shortcuts Is the Best Mac Local AI Feature You're Not Using
Shortcuts is a powerful automation tool built into Macs, iPhones, and iPads, and this year's Siri AI upgrade made it easier than ever to use.
Continue Reading About Why Apple Shortcuts Is the Best Mac Local AI Feature You're Not Using
