MoE Architecture Explained: How Mixture of Experts Decouples Capacity from Compute

    This article breaks down how Mixture of Experts (MoE) separates model capacity from per-token compute. It starts from a counterintuitive data point—a model with 671B total parameters but only about 37B activated per token—then explains where parameters sit in a dense Transformer, how replacing one large FFN with N routed experts plus a router splits the capacity equation, and why MoE saves FLOPs rather than memory. It also covers the engineering constraints that matter in practice: load balancing, shared experts, fine-grained experts with multi-way activation, and expert parallelism with its two All-to-All exchanges. Finally, it offers a cost view across training, inference, and capacity planning, plus a quick list of common misconceptions.

    1. Starting From a Counterintuitive Number

    An open-source model technical report states a total of 671B parameters, with training consuming only about 2.788M GPU-hours. Many readers assume the math is wrong: parameters grew nearly a hundredfold, yet cost did not explode at the same rate. Further down, the report adds one line—roughly 37B activated parameters per token.

    Put those two numbers together and you have the entire appeal of Mixture of Experts (MoE): the parameter count is huge, but only a small subset actually participates in computation for each token. The industry often describes this as “large but light on its feet”—the capacity goes up, but running it stays relatively cheap.

    This article answers three questions: where the “largeness” lives, where the “lightness” comes from, and which parts immediately become heavy in production.

    2. Where the Parameters Sit: The Cost Structure of a Dense Model

    A standard Transformer block has two parts: attention and the feed-forward network (FFN). Attention handles information exchange between tokens, and its parameter count scales with hidden dimension and number of heads. The FFN is a position-wise two-layer fully connected module, usually with a 3–4x expansion in the middle layer.

    Take a dense model in the 70B class with hidden dimension around 8192 and intermediate size around 28672. Per layer, attention accounts for about 150M parameters while the FFN accounts for about 700M—the FFN alone takes more than 80% of the per-layer parameters. Sum over 80 layers and most of the model’s “body weight” sits in the FFNs.

    The more important point is the rule that governs dense models: every token must pass fully through every FFN, and all weights must be read and multiplied. That produces an implicit equation in dense architectures:

    1. total parameters (capacity) ≡ activated parameters (compute)

    To make the model smarter, you widen and deepen the FFN. But widening the FFN raises per-token FLOPs and memory-bandwidth pressure at the same time. Capacity and compute are locked together—this is the fundamental cost-efficiency ceiling of the dense architecture.

    3. The First Cut of MoE: Replacing One Large FFN With N Small Ones

    The MoE modification is surgical: it touches only the FFN, not attention.

    1. Replicate the original FFN block N times. Each copy is an expert, structurally still an independent FFN.
    2. Add a lightweight router, typically a bias-free linear projection followed by softmax.
    3. When each token arrives, the router scores the experts and selects the top-k highest-scoring ones (commonly k=1 or 2). Only those experts compute on the token; the rest sit idle.

    Illustrative code (mechanism only, not a production implementation):

    1. def moe_ffn(x, experts, router, top_k=2):
    2. # x: [tokens, hidden]
    3. scores = router(x) # [tokens, n_experts]
    4. weights, idx = scores.topk(top_k, dim=-1)
    5. weights = softmax(weights, dim=-1) # normalize the k selected weights
    6. out = zeros_like(x)
    7. for t in range(x.shape[0]):
    8. for slot in range(top_k):
    9. e = experts[idx[t, slot]]
    10. out[t] += weights[t, slot] * e(x[t]) # only selected experts compute
    11. return out

    The equation is now split in two:

    1. total parameters (capacity) = attention + N × single-expert FFN ← how much it can remember, how smart it is
    2. activated parameters (compute) = attention + k × single-expert FFN ← how much compute each token costs

    Two common configurations from public technical reports make the contrast concrete (magnitudes widely cited in public reports):

    Architecture Total parameters (capacity) Activated per token (compute)
    Dense, ~70B class ~69B ~69B
    Sparse, 8 experts × 7B ~47B ~13B
    Sparse, 256 experts + 1 shared 671B ~37B

    The third row is the answer to the opening puzzle: 671B worth of “smart,” 37B worth of “cost.” That is the first layer of the core idea—decoupling capacity from compute.

    4. Why the Savings Are in Compute, Not Memory

    This is the most commonly misread point, so it needs to be stated plainly.

    The number of matrix multiplications per token depends only on k, so compute (FLOPs) does drop to roughly 1/k of the dense model. But every expert’s weights must stay resident in GPU memory (or host memory), because the next token could route to any expert. Therefore:

    • Compute: grows with k, independent of N;
    • Memory footprint: grows linearly with N, independent of k;
    • Memory-bandwidth reads: only the shards of the experts that are hit, somewhere in between.

    In one sentence: MoE saves floating-point operations and spends memory capacity and interconnect bandwidth. This also explains why “cheap to train” does not mean “cheap to deploy”—the memory threshold at inference time and the cross-device communication introduced by expert parallelism are where the real bill comes from.

    5. Engineering Constraints You Cannot Avoid

    5.1 Load Balancing: Don’t Let a Few Experts Die of Overwork

    Routing is a discrete decision, and early in training it easily produces a winner-take-all pattern: a few experts get selected repeatedly while the rest receive no gradient and effectively freeze. Three common countermeasures:

    • Auxiliary balancing loss: penalize deviation of the expert selection distribution from uniform;
    • Noise injection: add random perturbation to the scores early in training to encourage exploration;
    • Capacity factor and dropping: cap the number of tokens each expert accepts; overflow tokens take the residual shortcut, which keeps tensor shapes static and makes parallelism easier.

    5.2 Shared Experts: Pin Down General Capability

    If all capacity is handed to dynamic routing, the model tends to fragment general abilities such as grammar and common sense across experts. The common industry practice is to keep one (or a few) always-on shared experts that every token passes through, dedicated to general knowledge, while the remaining routed experts handle differentiated, domain-specific expression. This stabilizes training and reduces redundancy between experts.

    5.3 Fine-Grained Experts Plus Multi-Way Activation

    Making experts smaller and more numerous while raising k (for example, hundreds of fine-grained experts with 8-way activation per token) yields a richer set of combinations at the same activated compute budget, and higher expert specialization. The cost is a larger routing-scoring problem and more fragmented communication, which requires finer-grained parallel partitioning.

    5.4 Parallelism: Expert Parallelism Is Mandatory

    The data parallelism, tensor parallelism, and pipeline parallelism used for dense models still apply, but MoE adds expert parallelism: different experts live on different devices, and tokens are dispatched and gathered via two All-to-All operations. Those two communications are the main overhead in MoE training; they need to overlap with computation and be combined with bucketing and compression to hide latency.

    6. The Cost View: Training, Inference, and Capacity Planning

    • Training cost: roughly proportional to activated parameters × number of tokens, so for the same compute budget MoE buys more capacity. That is why the report cited at the start looks cheap.
    • Inference cost: low FLOPs, but high memory and bandwidth requirements. If a single device cannot hold the model, you need multi-device expert parallelism, and the device count is determined by capacity rather than activation.
    • Capacity planning advice: estimate memory and device count from total parameters first, then estimate throughput and latency from activated parameters; load-test the two separately rather than deriving one from the other.
    • Where it runs: model weights can sit on high-capacity storage and caching tiers, while elastic compute for inference can be hosted on a container platform, with monitoring, alerting, and logging to observe routing distribution, expert hit rate, and communication time. Mainstream cloud platforms such as Baidu AI Cloud offer these as general-purpose service categories.

    7. Quick Reference: Common Misconceptions

    1. “More parameters means it must be slower”—wrong; each token computes only k experts, and compute is determined by activated parameters.
    2. “MoE saves memory”—wrong; memory grows with the total number of experts, so it is actually hungrier for capacity.
    3. “More experts is always better”—only with load balancing and communication optimization, otherwise the gains are eaten by communication and dead experts.
    4. “MoE is an inference optimization technique”—it is first a capacity-scaling technique; faster inference is a by-product and depends on the implementation.
    5. “The router is an interpreter”—routing is a learned soft assignment and should not be read directly as human-understandable semantic labels.

    8. Summary

    The first principle of MoE comes down to one sentence: turn “how much to remember” and “how much to compute each time” into two independent knobs. In a dense model the FFN is both the main source of capacity and the main source of compute, and the two are forced together. MoE splits the FFN into multiple experts plus a router, letting capacity scale with the number of experts while compute stays restrained by the number of activations. Once you understand that decoupling, numbers like “671B parameters, 37B activated” become readable, and you can answer the two questions that matter during selection: whether memory can hold all the experts, and whether the interconnect bandwidth can sustain two All-to-All exchanges.