teachyou.ai academy
← All posts
AI

What Is a Mixture of Experts (MoE) Model?

Ira Menon · Jun 29, 2026 · 15 min read

If you have followed the pace of large language models over the last couple of years, you have probably noticed something strange. The models keep getting bigger, with parameter counts climbing into the hundreds of billions and beyond, yet the cost of running them has not exploded at the same rate. Some of the most capable open models you can download today claim enormous total parameter counts but somehow run on hardware that should not be able to handle them. The trick behind a lot of this is an architecture called Mixture of Experts, usually shortened to MoE. It is one of the most important ideas in modern AI engineering, and once you understand it, a lot of confusing headlines about model sizes suddenly start to make sense.

In this article we are going to walk through what a Mixture of Experts model actually is, why it exists, how the routing works under the hood, and where the real engineering challenges live. We will keep the math light and the intuition heavy, because the goal here is for you to walk away genuinely understanding the concept, not just able to repeat a definition. By the end you should be able to explain to a colleague why a model can have 400 billion parameters but only "use" 40 billion of them for any given token, and why that is such a big deal.

The Core Idea in Plain Language

Imagine you run a large consulting firm. A client walks in with a tax question. You do not gather every single employee in the building into one giant room and ask them all to think about the tax question together. That would be wasteful and slow. Instead, a receptionist glances at the question, recognizes it is about taxes, and routes the client to the two or three tax specialists who actually know the answer. Everyone else keeps doing their own work. The client gets a great answer, and you did not have to pay for the time of five hundred people to solve one problem.

A Mixture of Experts model works almost exactly like this. Instead of one massive dense network where every parameter is involved in processing every input, an MoE model contains many smaller sub-networks called experts. For any given piece of input, a small routing component decides which handful of experts are most relevant, sends the input only to those experts, and ignores the rest. The result is a model that has a huge total capacity, because it contains many experts, but only pays the computational cost of the few experts it actually activates.

This is the central tension that MoE resolves. In a traditional dense model, capacity and cost are locked together. If you want the model to know more, you make it bigger, and making it bigger makes every single forward pass more expensive. MoE breaks that link. It lets you scale the total number of parameters, which is roughly where a model stores its knowledge, without scaling the amount of computation you perform for each token in lockstep. You get the knowledge of a giant model with something closer to the running cost of a much smaller one.

Dense Models Versus Sparse Models

To really appreciate MoE, it helps to be precise about the two words that describe these two worlds: dense and sparse.

A dense model is the classic setup. Every input flows through every layer, and within each layer every neuron and every weight participates. If the model has 70 billion parameters, then processing a single token touches, in some sense, all 70 billion of them. This is simple and predictable. It is also expensive, because the compute cost grows directly with the parameter count. Double the parameters and you roughly double the cost of every inference.

A sparse model, which is what MoE gives you, deliberately leaves large parts of the network switched off for any particular input. The word sparse here refers to the fact that only a small fraction of the total parameters are active at once. The model as a whole is enormous, but the slice of it that lights up for any single token is small. This is why you will often see MoE models described with two different numbers, and understanding the difference between them is the single most useful thing you can take away from this article.

  • Total parameters: the full size of the model counting every expert. This determines how much the model can potentially know and how much memory you need to hold it.
  • Active parameters: the number of parameters actually used to process a single token. This determines how fast and how cheap inference is.

When you read that a model has, say, a large total parameter count but a much smaller active count, that gap is the MoE effect in action. The model stores a great deal of knowledge across all its experts, but it is disciplined about only waking up the parts it needs.

Anatomy of a Mixture of Experts Layer

Let us open up the hood and look at what actually sits inside an MoE model. In most modern language models, the Mixture of Experts idea is applied to a specific part of the transformer architecture: the feed-forward network that appears inside each transformer block. In a dense transformer, each block has an attention component followed by one feed-forward network. In an MoE transformer, that single feed-forward network is replaced by many parallel feed-forward networks, and these are the experts.

Two pieces make an MoE layer work.

  • The experts. Each expert is itself a small neural network, typically a feed-forward block with the same shape as the one it replaced. A layer might contain 8 experts, or 64, or in some large models many more. They all have the same architecture but different learned weights, so over the course of training each one tends to specialize in handling certain kinds of patterns.
  • The gating network, also called the router. This is a small, fast component whose only job is to look at the incoming token and decide which experts should handle it. It produces a score for each expert, and the model then selects the top few highest-scoring experts to actually run.

The number of experts selected per token is a crucial design choice, often written as top-k. A very common setting is top-2, meaning that for each token the router picks the two best experts, runs the token through just those two, and combines their outputs. Everything else in that layer stays dormant for that token. If a layer has 64 experts and uses top-2 routing, then only about 3 percent of that layer's feed-forward capacity is active for any given token, yet across many different tokens the whole set of experts gets used.

Here is a simplified sketch of what a routing step looks like in pseudo-code, just to make the flow concrete.

def moe_layer(token, experts, router, k=2):
    # router produces a score for every expert
    scores = router(token)              # shape: [num_experts]

    # pick the k highest-scoring experts
    top_experts, top_scores = select_top_k(scores, k)

    # turn those scores into weights that sum to 1
    weights = softmax(top_scores)

    # run the token only through the chosen experts
    output = 0
    for expert_index, weight in zip(top_experts, weights):
        output += weight * experts[expert_index](token)

    return output

Notice that the loop only ever runs over the selected experts, never all of them. That single detail is where all the efficiency comes from.

How the Router Decides

The router is the brain of the operation, and it is worth slowing down to understand how it makes its choices. At its simplest, the router is a single small layer of weights that takes the token's current representation and multiplies it to produce one number per expert. Those numbers are the raw affinities, sometimes called logits. A higher number means the router thinks that expert is a better fit for this token.

The model then keeps only the top-k of those numbers and applies a softmax to them, which converts the surviving scores into positive weights that add up to one. These weights are used to blend the outputs of the chosen experts. If expert A gets a weight of 0.7 and expert B gets 0.3, the final output leans mostly toward A but still borrows a little from B.

An important thing to internalize is that this routing happens per token, not per prompt. Within a single sentence, the word "differential" might get routed to one pair of experts while the word "the" three words later gets routed to a completely different pair. And because the model has many MoE layers stacked on top of each other, a token gets re-routed at every one of those layers. This gives the model an enormous number of possible pathways through the network, which is part of why MoE models can capture such rich behavior despite activating only a fraction of their weights at a time.

The router is also learned, not hand-designed. Nobody sits down and decides that this expert handles French and that one handles arithmetic. During training, the router and the experts are optimized together, and specialization emerges on its own as a byproduct of trying to minimize the model's error. The specializations that emerge are often not cleanly interpretable, but they are real, and they are what make the whole system more than the sum of its parts.

The Load Balancing Problem

Now we arrive at the messiest and most interesting engineering challenge in the entire MoE story. If you simply let the router learn freely with no constraints, something bad tends to happen. A handful of experts get chosen far more often than the others, and the rest are rarely picked at all. This is sometimes called expert collapse or the rich-get-richer problem.

The reason it happens is a feedback loop. Early in training, some experts are slightly better than others by pure luck. The router notices this and starts sending them more tokens. Because they receive more tokens, they get more training signal and improve faster. Because they improve faster, the router sends them even more tokens. Before long, a few experts are doing almost all the work and the others are dead weight, which defeats the entire purpose of having many experts.

Engineers solve this with a few complementary techniques.

  1. Auxiliary load-balancing loss. In addition to the normal training objective, the model is given an extra penalty that grows when token traffic is unevenly distributed across experts. This gently pushes the router toward spreading work more evenly, so that experts stay useful.
  2. Expert capacity limits. Each expert is given a maximum number of tokens it can accept in a batch. Once an expert is full, additional tokens routed to it are either dropped or sent to their next-best expert. This acts like a pressure valve that prevents any single expert from being flooded.
  3. Noise during routing. Some designs add a small amount of random noise to the router scores during training. This makes the selection less deterministic and gives underused experts a fairer chance of being explored.

Getting this balance right is genuinely hard, and it is one of the main reasons MoE models are trickier to train than dense ones. Push the balancing pressure too hard and you force tokens into experts that are not actually good for them, hurting quality. Push it too softly and you get collapse. Much of the practical craft of building a strong MoE model lives in tuning this trade-off.

Why MoE Is Such a Big Deal for Efficiency

Let us bring the benefits into sharp focus, because the payoff is what makes all this complexity worthwhile.

The headline advantage is compute efficiency during inference and training. Because only a small fraction of the model runs for each token, an MoE model can deliver the quality associated with a much larger dense model while performing far fewer calculations per token. In practical terms, this can mean faster responses and lower cost to serve the same level of capability, or alternatively a much more capable model for the same compute budget.

There is also a training-cost angle. Training a dense model to a given level of quality can require an enormous amount of compute, because every token in the training data pushes through every parameter. MoE lets researchers grow the total parameter count, and therefore the model's capacity to learn, without every parameter being touched by every training token. This has made it feasible to train models with very large total sizes on budgets that would never stretch to a dense model of the same parameter count.

  • You get more total knowledge capacity per unit of compute spent at inference time.
  • You can scale a model's size along a dimension that is relatively cheap to run.
  • You can often match or beat a dense model's quality while activating far fewer parameters per token.

None of this is free, though, and it would be dishonest to present MoE as a pure win. The costs simply show up somewhere other than raw per-token compute, which brings us to the trade-offs.

The Trade-offs and Hidden Costs

The first and most stubborn cost of MoE is memory. Even though only a few experts run per token, all of the experts have to be loaded and available, because the router might call on any of them at any moment. This means the full total parameter count must fit in memory, even though your compute cost reflects only the active parameters. An MoE model with a huge total size can be very fast to run but still demands a large amount of memory or VRAM to host. In deployment, this often becomes the binding constraint rather than raw speed.

The second cost is complexity in distributed systems. When experts are spread across multiple GPUs or multiple machines, which is common for large MoE models, tokens have to be physically shipped to whichever device holds their chosen experts and the results shipped back. This all-to-all communication can become a serious bottleneck. A great deal of MoE engineering is really networking and systems engineering, focused on keeping those cross-device transfers from eating up the compute savings.

The third cost is training instability. As we saw with load balancing, MoE models have failure modes that dense models simply do not have. Routers can collapse, experts can go stale, and the extra losses used to keep things balanced add tuning knobs that all have to be set carefully. This makes MoE models more finicky to train and more sensitive to getting the recipe right.

There is also a subtler quality consideration. Because capacity limits can cause some tokens to be dropped or rerouted to a less-than-ideal expert, and because specialization is imperfect, an MoE model does not always behave as cleanly as a dense model of equivalent active size. In practice the results are excellent, but the internal machinery is doing more approximation than a straightforward dense forward pass.

A Short History and Where You See MoE Today

The core idea behind Mixture of Experts is not new. The concept of combining multiple specialized sub-models under a gating mechanism goes back decades in the machine learning literature, long before the transformer era. What changed more recently is that researchers figured out how to apply the idea at massive scale inside transformers, and crucially how to make the routing sparse so that the compute savings actually materialize.

The modern wave began when large-scale sparse MoE layers were shown to train effectively inside transformer language models, proving that you really could push total parameter counts to enormous sizes while keeping per-token compute manageable. Since then, MoE has moved from a research curiosity to a mainstream architectural choice. Many of the frontier and open-weight language models you hear about today use some form of Mixture of Experts under the hood, precisely because it offers such an attractive ratio of capability to running cost. You do not always see it advertised on the label, but when a model boasts a very large total parameter count alongside a modest active count, MoE is almost certainly what is going on.

For an engineer, the takeaway is that MoE is no longer exotic. It is a standard tool in the kit for building large models efficiently, and understanding it is part of understanding how the current generation of AI systems is actually built and served.

How to Reason About MoE as a Practitioner

If you are building on top of these models rather than training them from scratch, you still benefit from a working mental model of MoE, because it changes how you think about the numbers.

When you compare models, resist the urge to judge purely by total parameter count. A model with a giant total size but a small active count will behave, in terms of speed and per-token cost, much more like its active size. Conversely, when you plan your hardware and memory budget, you have to respect the total size, because every expert must be resident even if it rarely fires. Holding both numbers in your head at once is the skill.

It also helps to remember what MoE is and is not good at changing. MoE is fundamentally a technique for scaling capacity efficiently. It does not by itself make a model reason better or hallucinate less in some magical way. It gives training and serving a better cost curve, and it is up to the overall design and training data to turn that extra capacity into genuine capability. When you read a model card, seeing an MoE architecture tells you something about efficiency and deployment, not a guarantee about quality on your specific task. As always, the honest move is to test the model on your own workload rather than infer everything from the architecture.

Here is a compact way to summarize the whole concept in a form you can keep in your notes.

MoE in one screen
- Many small expert sub-networks replace one big feed-forward network
- A router picks the top-k experts for each token (top-2 is common)
- Only the chosen experts run, so compute stays low per token
- Total parameters -> capacity and memory footprint
- Active parameters -> speed and per-token cost
- Load-balancing tricks stop a few experts from hogging all traffic
- Main costs: high memory, cross-device communication, trickier training

Wrapping Up

Mixture of Experts is one of those ideas that sounds complicated but rests on a very human intuition: do not make everyone work on every problem, route each problem to the specialists who can handle it. By replacing a single dense feed-forward network with a crowd of experts and a smart little router that activates only a few of them per token, MoE models decouple how much a model can know from how much it costs to run. That decoupling is what has let the field keep scaling model capacity without scaling running costs at the same brutal rate.

The price is paid in memory, in distributed-systems complexity, and in the delicate art of keeping experts balanced during training. But the trade has proven worth it often enough that MoE now sits at the heart of many of the models defining the current moment in AI. Understanding it moves you from being surprised by parameter-count headlines to being able to read them for what they really say about speed, cost, and capability.

If this kind of under-the-hood understanding is what you want more of, and you would like to go from knowing the concepts to actually building, serving, and reasoning about systems like this in production, that is exactly the ground we cover in the AI Engineering Roadmap course on teachyou.ai. It walks you through the architectures, the trade-offs, and the hands-on engineering skills that turn a curious reader into someone who can ship real AI systems with confidence.