Welcome to the next lesson in our module on Advanced Architectural Innovations. In our previous lesson, we explored Rotary Positional Embeddings (RoPE) and saw how a clever, mathematically-principled change to encoding position could yield significant benefits in length generalization. Today, we turn our attention to an even more impactful innovation that directly addresses the fundamental challenge of scaling large language models: the Mixture of Experts (MoE) architecture.
You'll recall from our module on scaling laws that increasing a model's parameter count is a primary driver of performance. However, for traditional "dense" architectures, more parameters mean more computation (FLOPs) for every single token processed. This creates a computational wall that makes training and inference prohibitively expensive. This lesson will introduce the MoE paradigm, a powerful technique that breaks this direct link.
By the end of this lesson, you will be able to describe the MoE architecture and, crucially, explain how it enables a dramatic increase in a model's total parameter count while keeping the computational cost for processing each token nearly constant.
The Problem of Dense Scaling
In a standard Transformer block, the multi-head attention sub-layer is followed by a position-wise feed-forward network (FFN). In a dense model, every token that passes through this block is processed by the entire FFN. This means all of the FFN's parameters are activated for every token. As you make the model bigger—for instance, by making the FFN wider—the computational cost per token scales proportionally. The challenge, then, is this: how can we endow a model with more knowledge (more parameters) without forcing it to use all of that knowledge on every single token?
The solution is to introduce conditional computation—activating only the parts of the model that are most relevant to the input at hand. This is the core idea behind the Mixture of Experts architecture.
Introducing Mixture of Experts
An MoE layer replaces a single, large FFN with two key components:
- A set of "Expert" Networks: These are typically smaller FFNs. Instead of one monolithic FFN, you might have 8, 64, or even more of these experts. Each expert can be thought of as a specialist, though its specialization is learned automatically during training and is usually more abstract than a human-understandable topic.
- A "Router" or "Gating" Network: This is a small neural network that examines each incoming token and decides which of the experts are best suited to process it.
The process is simple yet powerful: for each token, the router selects a small number of experts (often just one or two) and sends the token's representation only to them. The outputs from the chosen experts are then combined (e.g., via a weighted sum) to produce the final output of the MoE layer. All other experts remain inactive and consume no computational resources for that token.
The following video provides an excellent visual introduction to this concept, contrasting the sparse activation of MoE with the all-at-once activation of a dense model.
A Visual Guide to Mixture of Experts (MoE) in LLMs
This video from Maarten Grootendorst offers a clear, animated guide to the MoE concept.
Please watch the first two segments: The initial explanation: This part introduces the core components (experts and router) and contrasts the sparse activation path of an MoE model with a dense model. The router mechanism: This section zooms in on how the router uses a softmax function to generate probabilities and select the best experts for a given input.
This idea of sparsely activated models dates back to the early 90s but was revitalized and successfully applied to large-scale Transformers by researchers at Google. The following clip from a Stanford lecture provides some of this historical context and reinforces the core mechanism.
Stanford CS25: V1 I Mixture of Experts (MoE) paradigm and the Switch Transformer
This Stanford CS25 lecture discusses scaling Transformers through sparsity, focusing on MoE and the Switch Transformer.
Watch these two clips: The introduction to MoE: This explains how a gating network computes a probability distribution over experts and combines their outputs. The Switch Transformer: This describes a simplified but highly effective MoE variant where each token is routed to only the single best expert (k=1), highlighting the adaptive computation path for different tokens.
Now, let's look at a diagram that brings all these pieces together.

The Decoupling of Parameters and FLOPs
The true power of MoE lies in its ability to decouple the total number of parameters from the per-token computational cost. Let's define two key terms:
- Total Parameters (or Sparse Parameters): The full count of all parameters in the model, including every single expert. This determines the model's memory footprint and its total "knowledge capacity."
- Active Parameters: The parameters that are actually used to process a single token during a forward pass. This determines the computational cost (FLOPs) and, consequently, the training and inference speed.
In a dense model, Total Parameters = Active Parameters. In an MoE model, Active Parameters << Total Parameters.
This architectural choice creates a fundamental trade-off that is the key to MoE's success. Let's make this concrete with a quantitative comparison.
Analyzing Parameter vs. FLOPs Trade-offs - ApX Machine Learning
This article from ApX Machine Learning provides a direct, quantitative analysis of the MoE trade-off.
Please read the sections The Asymmetry of Scaling and A Concrete Comparison. Pay close attention to the calculations for the dense FFN block versus the MoE FFN block. This is the mathematical heart of this lesson's learning outcome.
As the article demonstrates, by replacing a single dense FFN with an MoE layer containing 64 experts and activating only 2 per token, you can achieve a 32x increase in FFN parameters for the exact same computational cost (FLOPs).
This is a profound result. It means you can build a model with a vast "library" of knowledge (the 64 experts) but only consult the two most relevant "books" for any given token, making the process incredibly efficient.
This distinction is often a source of confusion, especially with model names like Mixtral 8x7B. The following resources clarify how to think about sparse vs. active parameters in the context of a real-world model.
A Visual Guide to Mixture of Experts (MoE) in LLMs
Let's return to the "Visual Guide to Mixture of Experts" video.
Watch the section on sparse vs. active parameters. It uses the Mixtral 8x7B model as a concrete example to break down exactly what contributes to the total (sparse) and active parameter counts.
To further solidify this, the following article addresses the "8x7B" question directly.
MoE Math Demystified: What Does 8x7B Actually Mean? - Cerebras
This article from Cerebras provides a detailed breakdown of MoE mathematics.
Read the introduction What Does 8x7B Actually Mean?, which sets up the common confusion. Then, focus on the sections detailing the components of model size and computational cost. Specifically, read the breakdown of model weights to understand what contributes to the total parameter count. Finally, read the paragraph in the "How much compute do I need?" section that explains the FLOPs calculation for the MoE layer. Notice the crucial sentence: "...we only activate k out of N experts per token, thus MoE models require significantly less fewer FLOPs than dense networks with the same total parameter count."
The Impact on Scaling and Performance
This architectural advantage is not just theoretical; it translates into massive real-world performance gains. By trading a fixed compute budget for a much larger parameter count, MoE models can learn more effectively and quickly than their dense counterparts.
For example, the Switch Transformer, which uses an MoE architecture, demonstrated up to a 7x speedup in pre-training compared to an equivalent dense model (T5-Base) with the same computational cost.
Stanford CS25: V1 I Mixture of Experts (MoE) paradigm and the Switch Transformer
Let's revisit the Stanford lecture to see the empirical results of this trade-off.
Watch these final two segments: Scaling with experts: This section shows plots of model performance improving as the number of experts increases, culminating in the 7x speedup result. Trading flops for parameters: This part discusses the Switch-C model, which has 1.6 trillion parameters but fewer FLOPs per token than a smaller dense model. This is a prime example of the MoE philosophy in action, achieving superior performance on a time-to-train basis by prioritizing parameter count over per-token FLOPs.
Conclusion
In this lesson, we've explored the Mixture of Experts architecture, a pivotal innovation for building state-of-the-art LLMs. We've seen how MoE leverages conditional computation to overcome the scaling limitations of dense models.
Here are the essential takeaways:
- Architecture: MoE replaces the dense FFN layer in a Transformer with a set of smaller "expert" networks and a "router" that directs each token to a small subset of these experts.
- The Core Trade-off: This design decouples the total parameter count (which determines memory and model capacity) from the active parameter count (which determines computational cost per token).
- Sparse vs. Dense: In a dense model, all parameters are active for every token. In a sparse MoE model, only a fraction of parameters are active, allowing for models with trillions of parameters to be trained and run with manageable compute.
- Efficiency: This decoupling leads to significant improvements in training and inference efficiency, enabling larger, more capable models to be developed for a given computational budget.
We have established what an MoE layer is and why it's so effective. However, we've treated the router as a bit of a magic box. How does it learn to make good routing decisions? And what happens if it develops bad habits, like sending all tokens to only a few experts? In our next lesson, we will open up this box and examine the mechanics of the router network, including the critical role of an auxiliary "load balancing" loss that ensures the experts are used efficiently.