Open-Source MoE LLM Architecture Explained: Sparse Activation and Engineering Practices

    This article explores how the Mixture of Experts (MoE) architecture overcomes the compute bottlenecks of traditional dense models. It provides a detailed breakdown of a 744B parameter MoE model, covering its core specifications, routing mechanisms, training stability strategies, and the engineering costs associated with inference deployment. Finally, it discusses the implications for AI agent applications and offers practical advice for model selection.

    I. Background: Compute Bottlenecks of Dense Models

    Traditional dense models activate all parameters for every token during computation. As parameter counts increase, the compute and memory bandwidth required for a single inference grow linearly. For agentic applications requiring long-chain reasoning or multi-turn tool calls, these costs accumulate rapidly.

    The Mixture of Experts (MoE) architecture offers an alternative approach. The model splits its feed-forward network into multiple “expert” subnetworks, and a router selects a small number of experts for each token. The model’s total capacity is determined by all experts, but a single forward pass only consumes the selected portion. By decoupling these two aspects, the model achieves a balance between large parameter capacity and controllable per-token compute costs.

    II. Core Specifications Overview

    The table below lists the key configurations of the model discussed in this article.

    Metric Value Description
    Total Parameters 744B The scale of all learnable parameters in the model
    Active Parameters per Token 40B The parameters actually involved in a single forward pass
    Activation Ratio ~5.4% 40B ÷ 744B; compute usage is far lower than total parameters
    Number of Routed Experts 256 Experts available for routing in each MoE layer
    Routed Experts Activated per Token Top-8 8 routed experts selected per token in each MoE layer
    Number of Shared Experts 1 An expert that every token must pass through
    Dense Layers First 3 layers No expert routing; all tokens use the same computation path

    Two numbers can be inferred from the table. First, in each MoE layer, the activation ratio for routed experts is 8 ÷ 256, or approximately 3.1%. Second, including the mandatory shared expert, each token runs only 9 expert modules out of a total of 257 modules per MoE layer. Note that the 40B active parameters also include shared computations like attention and embedding layers, not solely the expert networks.

    III. Architecture Breakdown

    3.1 Routing and Sparse Activation

    The routing process can be divided into four steps:

    1. Feed the current layer’s hidden state into the router’s linear layer to obtain scores for 256 experts.
    2. Select the top 8 experts with the highest scores.
    3. Normalize these 8 scores (commonly via softmax) to obtain weights for each expert.
    4. Compute the weighted sum of the outputs from these 8 experts to form the expert portion’s output for that layer.

    Unselected experts do not execute computations, but their parameters must still be stored in memory, ready for invocation. This directly dictates memory planning during deployment, which is discussed later.

    3.2 Routed Experts

    Routed experts form the core of the MoE layer. During training, each expert gradually develops a preference for certain input patterns. These preferences do not necessarily correspond to human-intuitive domains, such as a “code expert” or “math expert.” Engineers should not presuppose semantic divisions among experts; this can only be verified by analyzing expert activation distributions or evaluation results.

    3.3 Shared Experts

    A shared expert is activated for every token. Its common role is to handle universal patterns, such as basic grammatical structures and representations of high-frequency vocabulary. This allows routed experts to avoid redundantly learning general knowledge and instead dedicate their capacity to more specialized patterns.

    The trade-off is clear: the shared expert generates a fixed computational overhead in every layer, accounting for 1/9 of the activated modules per layer in this model.

    3.4 Dense Layers in the First Three Layers

    The first few layers typically handle the extraction of low-level features, such as lexical and local grammatical information. Routing decisions at this stage might be unstable, whereas dense computation ensures every token is fully processed. Therefore, retaining a dense structure for the initial layers is a common design motivation.

    The cost of this design is that the computation for the first three layers is fixed and cannot be reduced via sparsity. Specific considerations should be based on the model developer’s technical disclosures; this article only analyzes the general motivation.

    IV. Routing Mechanism Demonstration

    The following code illustrates the routing flow for a single token and is a simplified demonstration. Actual implementations group tokens by expert and compute in batches, rather than looping token by token.

    1. NUM_ROUTED_EXPERTS = 256
    2. TOP_K = 8
    3. def route_token(hidden, gate_weights):
    4. # hidden: hidden state vector of length d
    5. # gate_weights: routing matrix of shape [256][d]
    6. logits = [sum(h * w for h, w in zip(hidden, row)) for row in gate_weights]
    7. top = sorted(range(len(logits)), key=lambda i: logits[i], reverse=True)[:TOP_K]
    8. exps = [math.exp(logits[i]) for i in top]
    9. total = sum(exps)
    10. return [(i, e / total) for i, e in zip(top, exps)]
    11. def moe_layer(hidden, gate_weights, experts, shared_expert):
    12. out = shared_expert(hidden) # Shared expert: mandatory for every token
    13. for idx, weight in route_token(hidden, gate_weights):
    14. y = experts[idx](hidden) # Compute only the selected routed experts
    15. out = [o + weight * v for o, v in zip(out, y)]
    16. return out

    This code highlights two key points. First, the overhead of the routing function correlates with the total number of experts, but the expert functions only execute for 8 experts. Second, the output of the shared expert is not subject to routing weights and is directly accumulated into the result.

    V. Training Stability: Load Balancing

    A typical problem in MoE training is routing collapse. A few experts are heavily selected, while others receive almost no training signals, ultimately wasting model capacity. Common mitigation strategies in the industry include:

    • Auxiliary Load Balancing Loss: Adding a penalty term to the training objective to encourage a uniform activation frequency across experts.
    • Expert Capacity Limit: Restricting the number of tokens a single expert can process in a batch; excess tokens are rerouted or dropped.
    • Routing Noise: Adding a small amount of random perturbation to the routing scores to help explore more expert combinations.
    • Shared Expert Fallback: Even if routing deviates, the shared expert ensures every token receives a baseline representation.

    Specific strategies depend on the training party’s public information. Engineering teams should focus on monitoring the activation distribution of each expert during in-house training or fine-tuning.

    VI. Engineering Costs of Inference Deployment

    The deployment costs of MoE models differ significantly from dense models, primarily in the following four aspects:

    Memory Footprint. The weights of all experts must reside in VRAM or fast-access storage. Estimated by bytes per parameter, the memory required for weights alone is as follows:

    • BF16 (2 bytes per parameter): ~744 × 2 = 1488 GB
    • 8-bit quantization (1 byte per parameter): ~744 GB
    • 4-bit quantization (0.5 bytes per parameter): ~372 GB

    These figures exclude KV cache, activations, and runtime overhead, serving only for magnitude estimation.

    Compute Volume. The compute volume per token is determined by the ~40B active parameters. A single step requires far less computation than a dense model with an equivalent total parameter count.

    Communication Overhead. When experts are distributed across multiple compute devices, tokens must be dispatched to the devices hosting the corresponding experts and aggregated after computation. This all-to-all communication can become a throughput bottleneck, requiring advance planning for network bandwidth and topology.

    Batching Efficiency. Different tokens are routed to different experts. Larger batches lead to more balanced token distribution among experts and higher device utilization. In small-batch scenarios, some experts may remain idle for extended periods, resulting in wasted compute power.

    VII. Implications for AI Agent Applications

    Agentic tasks typically involve multi-step reasoning, tool calls, and extended contexts, triggering multiple model invocations per task. The advantage of the MoE architecture lies in its lower per-token compute cost, making it suitable for high-throughput batch processing.

    However, latency for a single request may not necessarily be lower. Latency depends on memory access, inter-expert communication, and batching strategies. Therefore, when selecting a model, focus on the following metrics rather than just parameter scale:

    • Time-to-first-token (TTFT) and full response time
    • Tokens output per second (throughput)
    • Inference cost per unit task
    • Success rate and error type distribution for the target task

    Improvements in model quality must be validated through proprietary evaluation sets; they cannot be inferred solely from parameter scale or architecture type.

    VIII. Selection and Implementation Recommendations

    1. Define task objectives. Use the task success rate as the primary evaluation metric.