MoE Architecture Explained: Parameter Counts, Routing, and Long-Context Engineering

    This article breaks down how to read modern MoE model spec sheets. It clarifies three often-confused metrics—total parameters, activated parameters per token, and context window—then explains MoE routing with top-k selection, load balancing, and shared experts. It also covers the real bottlenecks of long-context inference (prefill vs. decode, KV cache sizing, cache compression, sparse attention, offload, and PD disaggregation), training-side trade-offs, and a practical checklist for evaluating MoE deployments.

    1. Why It’s Time to Re-Read the Parameter Table

    Over the past year, model spec sheets have started to look like engineering invoices. Total parameter counts routinely run into the hundreds of billions or even trillions, which sounds impressive. But deployment and operations teams care about something else: how much compute, memory, and bandwidth each generated token actually consumes. Mixture of Experts (MoE) architectures exist precisely to balance total model capacity against per-token compute. To understand these architectures, you first need to separate several metrics that are easy to conflate.

    2. Three Metrics That Are Easy to Confuse

    2.1 Total Parameters

    Total parameters are the sum of all learnable weights in the model: expert networks, attention layers, embeddings, routers, and normalization modules. Total parameters determine how much knowledge the model can store, and they determine the size of the weight files. At 2 bytes per parameter (BF16), a model with 200B total parameters needs roughly 400GB of memory just for weights—before counting activations and caches.

    2.2 Activated Parameters per Token

    An MoE model does not route every token through every expert. The router selects a small number of experts for each token, and the rest stay idle. Activated parameters are therefore a better measure of per-token compute. Sparsity can be described with a simple ratio:

    Activation ratio = activated parameters / total parameters

    Suppose a model has 200B total parameters and activates 20B per token. The activation ratio is 10%. Its forward-pass compute is close to that of a 20B dense model, while its knowledge capacity is close to that of a 200B model. Note that activated parameters do not equal real latency. Communication overhead, batch size, KV cache reads, quantization, and the inference framework all affect final response time.

    2.3 Context Window

    The context window determines how many tokens the model can process at once. The number looks like a simple upper bound on input length, but it directly amplifies attention compute and cache usage. When the window grows from tens of thousands to a million tokens, engineering difficulty does not scale linearly with length—it rises rapidly with sequence length.

    3. How MoE Works

    3.1 Routing and Top-k Selection

    A typical MoE layer contains several expert networks and a router. The router outputs a score for each expert given a token, and the system picks the top-k experts to participate in computation. Here is illustrative pseudocode:

    1. def moe_forward(token_hidden, experts, router, top_k):
    2. scores = router(token_hidden) # one score per expert
    3. probs = softmax(scores)
    4. top_idx = argmax_top_k(probs, top_k) # select k experts
    5. output = 0
    6. for i in top_idx:
    7. weight = probs[i] / sum(probs[top_idx]) # normalize among selected experts
    8. output += weight * experts[i](token_hidden)
    9. return output

    This code expresses the logic only and does not correspond to any specific implementation. The key point: unselected experts do not participate in computation, but their parameters still occupy storage.

    3.2 Load Balancing

    If the router persistently favors a few experts, two problems arise. Popular experts become bottlenecks, while neglected experts are undertrained. Common mitigations include adding a load-balancing term to the training loss, setting a capacity limit per expert, and injecting a small amount of noise during routing. Most practice combines several of these techniques.

    3.3 Shared Experts

    Some designs keep one or a few shared experts that process every token, handling common language patterns, while routed experts take on finer-grained specialization. Shared experts add a small fixed amount of compute but reduce knowledge duplication across experts.

    4. The Real Bottlenecks of Long Context

    4.1 Prefill and Decode

    Inference has two phases. The prefill phase processes the input prompt in one pass; it is compute-heavy and usually compute-bound. The decode phase generates output tokens one at a time, reading the historical KV cache at each step; it is usually memory-bandwidth-bound. Long context stresses both phases, and the cache-read pressure in the decode phase is especially pronounced.

    4.2 Estimating KV Cache Size

    In standard multi-head attention, KV cache size can be roughly estimated as:

    KV cache bytes ≈ 2 × layers × KV heads × head dimension × sequence length × batch size × bytes per element

    The factor of 2 accounts for Keys and Values. With 32 layers, 8 KV heads, head dimension 128, a 128K (131,072) sequence length, batch size 1, and BF16 precision, the cache for a single request is about 2 × 32 × 8 × 128 × 131072 × 1 × 2 bytes, roughly 17GB. This shows that the cost of long context comes largely from the cache, not just the attention computation itself.

    4.3 Cache Compression and Sparse Attention

    To reduce cache overhead, the industry commonly uses several approaches:

    • Compress the KV representation: project Keys and Values into a low-dimensional latent space, cache only the compressed vectors, and reconstruct them at use time.
    • Reduce KV heads: multi-query or grouped-query attention lets multiple query heads share one set of KVs, directly shrinking the cache.
    • Sparse attention: compute attention only over the history tokens relevant to the current position, such as a local sliding window plus a small number of global tokens.
    • Hybrid structures: some layers use full attention while others use windowed or linear attention, trading off quality against cost.

    Each method has a price. Compression can lose fine-grained information, sparse attention needs extra retrieval or selection mechanisms, and hybrid structures increase training and debugging complexity.

    4.4 Offload and PD Disaggregation

    When the cache exceeds GPU memory, the system can offload part of it to host memory or lower storage tiers, at the cost of added access latency. Prefill-decode (PD) disaggregation places the two workloads in separate resource pools, each configured for its own characteristics. Both approaches depend on good scheduling and network conditions.

    5. Training-Side Trade-offs

    Architecture sets the ceiling on a model’s capability; training determines whether it performs reliably in target scenarios. For models that need long context, tool calling, and code execution, the post-training pipeline typically includes:

    • Long-document data and long-range dependency tasks, teaching the model to locate key information in very long inputs.
    • Tool-calling samples, teaching the model when to invoke external functions, how to construct arguments, and how to interpret returned results.
    • Reinforcement learning in code execution environments, using runnable test outcomes to improve code generation quality.
    • Multi-turn dialogue and instruction-following data, ensuring consistent behavior in complex interactions.

    These stages affect inference cost indirectly. For example, once tool-calling ability improves, the model may produce longer reasoning traces, increasing the total tokens generated per task. So when evaluating a model, look at the total tokens consumed to complete a task, not just per-token compute or per-token price.

    6. A Checklist for Evaluating MoE Options

    Dimension Questions to confirm Main impact
    Total parameters Do the weights fit in target GPU or host memory? Deployment threshold, load time
    Activated parameters Does per-token compute fit the budget? Throughput, unit cost
    Expert count and k value Are routing granularity and expert load reasonable? Model quality, communication volume
    Attention structure How does it handle long sequences? Cache footprint, long-context cost