📋 KEY INSIGHTS
- Mixture of Experts (MoE) is a neural network architecture that replaces dense feed-forward layers with a set of K expert sub-networks and a learned gating network that routes each input token to a sparse subset of experts (typically top-1 or top-2 out of K=8 to K=64). Because only 1-2 experts are activated per token, the compute per forward pass scales with activated parameters rather than total parameters, enabling models with 10-100Ć more total parameters than a dense model of the same compute cost.
- Sparse MoE models achieve better performance per FLOP than dense models: Mixtral 8x7B has 46.7B total parameters but activates only 12.9B parameters per token ā matching or exceeding the performance of dense 13B models on most benchmarks while running at 13B inference cost. Switch Transformer, GLaM, and GPT-4 are landmark MoE models that established the scaling advantage of sparsity.
- Load balancing is the central training challenge for MoE: without regularisation, the gating network collapses to routing all tokens to the same 1-2 experts (the rich-get-richer problem), leaving most experts undertrained. The auxiliary load-balancing loss ā penalising routing distributions with high variance across experts ā is required to ensure uniform expert utilisation, added to the main language modelling loss during training.
- Expert specialisation emerges organically from MoE training: different experts specialise in different aspects of the input without explicit supervision ā some experts specialise in syntax, others in semantics, others in domain-specific vocabulary. This specialisation is measurable by analysing which token types are routed to which experts and produces more efficient use of total model capacity than a dense model of the same total size.
- Sparse attention models ā Longformer, BigBird, Reformer ā apply the MoE sparsity principle to the attention mechanism rather than the feed-forward layers: instead of computing attention between all O(N²) pairs of tokens in a sequence of length N, sparse attention patterns (local windows, global tokens, random patterns) reduce attention complexity to O(N) or O(N log N), enabling processing of documents with tens of thousands of tokens.
- Expert parallelism is the natural training and serving strategy for MoE models: different experts reside on different devices (GPUs or TPUs), and each token is routed to the device housing its selected experts. This expert parallelism is complementary to tensor parallelism (splitting individual weight matrices across devices) and pipeline parallelism (splitting layers across devices), and the three are combined in large-scale MoE training.
The scaling laws for language models (Hoffmann et al., Chinchilla, 2022) established that compute-optimal training requires proportionally scaling both model size and training data. But scaling dense Transformer models ā increasing the number of parameters while keeping the compute per forward pass proportional ā is expensive: doubling model parameters roughly doubles both training and inference compute. Mixture of Experts offers a way to scale model capacity ā the total number of parameters ā without proportionally scaling compute: by activating only a fraction of experts per token, MoE models achieve the representational capacity of a large dense model at the inference cost of a smaller dense model. This architectural insight, combined with the engineering advances in expert parallelism and load balancing, has made MoE the dominant architecture for frontier-scale language models. This guide covers MoE architecture and routing, load balancing, expert specialisation, sparse attention as the attention-layer analogue, and the engineering considerations for training and serving MoE models.
MoE Architecture ā Routing, Gating and Expert Networks
The standard Transformer block consists of a multi-head self-attention layer followed by a feed-forward network (FFN). In a Transformer MoE block, the single FFN is replaced by K expert FFNs and a gating network G: for each token representation h, the gating network computes softmax logits over K experts, selects the top-k experts by logit, and routes h to those experts: output = Ī£_{i ā top-k} G_i(h) Ć E_i(h), where G_i is the gating weight for expert i and E_i(h) is expert i’s transformation of h. In top-1 routing (Switch Transformer), only one expert processes each token; in top-2 routing (Mixtral), two experts process each token and their outputs are combined. Top-2 routing achieves better performance than top-1 at the cost of doubling per-token FLOPs, but since K is typically 8ā64, even top-2 activates a small fraction of total parameters.
The gating network is typically a simple linear layer: G(h) = Softmax(W_g h + noise), where the noise term (usually Gaussian noise added during training) encourages exploration and prevents all tokens from routing to the same expert. The linear transformation W_g maps the token representation to K logit scores, one per expert. The softmax over the top-k logits normalises the gating weights to sum to 1 within the active expert set. The gradient flow through the gating network is a key architectural consideration: because routing is a discrete selection, gradients do not flow back through the routing decision itself (only through the gating weights). This makes the gating network’s training a form of combinatorial optimisation that the auxiliary loss regularises, connecting to the reinforcement learning perspective where routing is a policy and expert quality is the reward.
| Model | Total Params | Active Params/Token | Experts | Routing | vs Dense Equivalent |
|---|---|---|---|---|---|
| Switch Transformer (Google) | 1.6T | ~7B | 2,048 | Top-1 | Matches T5-11B at lower compute |
| GLaM (Google) | 1.2T | ~96B | 64 (top-2) | Top-2 | Matches GPT-3 at 1/3 energy |
| Mixtral 8x7B | 46.7B | 12.9B | 8 (top-2) | Top-2 | Exceeds Llama 2 70B on most benchmarks |
| Mixtral 8x22B | 141B | 39B | 8 (top-2) | Top-2 | Competitive with GPT-4 on coding/maths |
| DeepSeek-MoE | 145B | 22B | 160 fine-grained | Top-K fine-grained | Better specialisation via fine-grained experts |
Load Balancing and Expert Specialisation
Without explicit regularisation, MoE training collapses: the gating network learns to route most tokens to the same 1ā2 experts (those that first produce slightly lower loss), leaving the remaining experts undertrained. This routing collapse is the MoE analogue of the mode collapse problem in GANs ā a rich-gets-richer dynamic where small initial differences in expert quality compound into complete routing imbalance. The auxiliary load-balancing loss prevents this: L_aux = α Ć K à Σ_{i=1}^K f_i Ć p_i, where f_i is the fraction of tokens routed to expert i and p_i is the average gating probability assigned to expert i. Minimising L_aux encourages the routing distribution to be uniform across experts. The coefficient α (typically 0.01) balances the load-balancing objective against the primary language modelling loss. Switch Transformer introduced this formulation; subsequent works (GShard, Mixtral) refined it with capacity factor constraints that prevent expert overload during training.
Expert specialisation is an emergent property of MoE training that has been extensively studied. Analysis of routing distributions in trained MoE models reveals consistent patterns: syntactic tokens (punctuation, common function words) are often routed to a small set of high-frequency experts; domain-specific vocabulary (medical terms, legal language, code syntax) is routed to domain-specific experts; rare and complex tokens are routed to higher-capacity “generalist” experts. This specialisation improves model efficiency ā each expert develops expertise in a narrow domain, and the gating network learns to route tokens to the expert best suited to process them. The specialisation can be measured by computing the mutual information between token type (or topic distribution) and expert assignment, providing an interpretability signal analogous to the SHAP feature importance for dense models. The connection to clustering algorithms is instructive: the experts in a trained MoE partition the token space into implicit clusters, and the routing function is a soft cluster assignment that can be analysed with the same tools used for mixture model analysis in our Bayesian statistics guide.
Sparse Attention ā Longformer, BigBird and Linear Attention
Standard Transformer self-attention is O(N²) in sequence length N, because every token attends to every other token. For a 32,768-token context window (common in 2026 frontier models), this requires over 1 billion attention operations per layer ā prohibitively expensive for long documents. Sparse attention models reduce this to O(N) or O(N log N) by restricting which tokens can attend to which. Longformer (Beltagy et al., 2020) combines local window attention (each token attends to w/2 tokens on each side, O(Nw) total) with global attention (a small number of designated global tokens attend to all other tokens, O(Ng Ć N) total). The local attention captures nearby syntactic and semantic context; the global attention (applied to [CLS] tokens and task-specific tokens) aggregates global document-level information. BigBird adds random attention (each token attends to r random tokens) to the Longformer pattern, improving theoretical expressiveness while keeping the O(N) complexity. The connection to the full Transformer attention mechanism is direct: sparse attention preserves the self-attention interface and can use the same pre-training and fine-tuning infrastructure, just with a different attention mask pattern.
For data scientists, the practical relevance of MoE and sparse models is primarily in model selection and inference cost: when choosing a foundation model for fine-tuning or RAG applications, MoE models (Mixtral, DeepSeek-MoE) offer a better performance-per-inference-FLOP tradeoff than equivalent-compute dense models, while sparse attention models (Longformer, LongT5) enable processing long documents (contracts, scientific papers, code repositories) that exceed the context windows of standard models. The LoRA fine-tuning workflow applies directly to MoE models ā LoRA adapters are added to each expert’s linear layers ā and the model compression techniques (quantisation, pruning) are applied to each expert independently, with expert-level pruning (dropping entire low-utilisation experts) as an additional MoE-specific compression strategy.
✦ SUMMARIZE THIS ARTICLE WITH AI
Transformer architecture that MoE layers replace the FFN in is in our Transformers guide. LoRA fine-tuning of MoE models ā adapters on each expert’s linear layers ā is in our LLM Fine-Tuning guide. Model compression ā pruning entire low-utilisation experts, quantising expert weights ā is in our Model Compression guide. Scaling laws and compute-optimal training that motivate MoE are introduced in our Generative AI guide. Bayesian mixture models as the statistical predecessor of MoE are in our Bayesian Statistics guide. Expert parallelism and distributed training infrastructure are in our Big Data Technologies guide.



