Mixture of Experts (MoE) LLM Architecture: A Complete Technical Guide

    This article breaks down how Mixture of Experts (MoE) architecture addresses the trade-off between model capacity and inference cost in large language models. It covers sparse activation and routing, a reusable framework for estimating compute budgets and training costs, key engineering capabilities such as load balancing, parallelism strategies, inference acceleration, and long-context support, as well as cloud deployment practices and model selection advice.

    1. Why Mixture of Experts Has Become a Key Architecture for LLMs

    Large language models face a long-standing tension between parameter count and inference cost. In a dense architecture, every token passes through all parameters, so doubling the parameter count typically doubles the compute as well. Mixture of Experts (MoE) uses sparse activation to decouple total parameter count from per-token compute, making it a mainstream approach for balancing capacity and efficiency.

    The core idea is to define multiple parallel expert subnetworks and use a gating network (the Router) to select a few experts for each token. The model can therefore have a very large total parameter count while each forward pass activates only a small fraction of it. For example, a publicly reported hundred-billion-scale MoE model has roughly 671 billion total parameters with about 37 billion activated per token, an activation ratio of about 5.5% — a typical case of large capacity with low per-call overhead.

    It is important to note that sparsity is not free. Expert parallelism adds communication overhead, and uneven gating can overload some experts while leaving others idle. Engineering practice therefore requires auxiliary load-balancing loss, capacity factor limits, and a sensible parallelism partitioning strategy.

    2. A General Method for Estimating Compute Budget and Training Cost

    Public information indicates that a hundred-billion-scale MoE model of this class completed pre-training on roughly 14.8 trillion tokens using only 2,048 high-end accelerators, for a cumulative total of about 2,788 thousand accelerator-hours, of which pre-training accounted for about 2,664 thousand accelerator-hours. That works out to roughly 1,361 hours per accelerator (about 56.7 days), with an R&D cost on the order of several million dollars.

    The value of these figures for engineering teams is a reusable estimation framework:

    • Total estimate: training accelerator-hours ≈ number of accelerators used × training days × 24.
    • Pre-training share: pre-training usually accounts for more than 90% of total accelerator-hours; post-training (continued pre-training, supervised fine-tuning, preference alignment) is a small share but has a significant impact on the user experience.
    • Efficiency levers: the combination of mixed-precision training, operator fusion, sequence parallelism, expert parallelism, and pipeline parallelism is key to reducing accelerator-hours.
    • Cost structure: beyond compute, you must account for data cleaning and deduplication, building an evaluation system, failed-run retries, and labor costs, so the actual total investment is typically higher than the pure compute figure.

    3. Breakdown of Key Engineering Capabilities

    3.1 Sparse Gating and Load Balancing

    The gating network determines the mapping from tokens to experts. In practice, an auxiliary balancing loss is often introduced along with a per-expert capacity limit; tokens that exceed capacity take an overflow path so that individual experts do not become hotspots.

    Illustrative configuration (pseudocode, conveying the idea only):

    1. router_logits = gate(hidden_states) # [tokens, num_experts]
    2. weights, expert_ids = topk_softmax(router_logits, k=2)
    3. aux_loss = load_balance_loss(router_logits) # discourage skewed expert load
    4. outputs = dispatch(hidden_states, expert_ids, weights, capacity_factor=1.25)
    5. loss = task_loss + alpha * aux_loss

    3.2 Combining Parallelism Strategies

    A typical setup uses expert parallelism to partition along the expert dimension, tensor parallelism to split the matrices within a layer, pipeline parallelism to split layer ranges, and data parallelism to handle the batch dimension; sequence parallelism is added to reduce activation memory pressure for long sequences. The partitioning scheme must match the cluster’s interconnect bandwidth, or communication becomes the bottleneck.

    3.3 Inference Acceleration

    Gains in generation speed usually come from three sources: first, sparse activation itself reduces per-token compute; second, continuous batching and paged key-value cache management in batched inference serving improve memory utilization; third, quantization and operator optimization. The following pseudocode expresses the batching scheduling logic:

    1. while requests_pending:
    2. batch = scheduler.form_batch(max_tokens=8192)
    3. kv_cache = paged_alloc(batch) # allocate on demand, reduce fragmentation
    4. logits = model.forward(batch, kv_cache)
    5. emit_tokens(logits)

    3.4 Long-Context Capability

    Extending the context from tens of thousands of tokens to the million level typically relies on positional encoding extrapolation, attention sparsification, and memory optimization, while retrieval augmentation, hierarchical caching, and per-request resource isolation are needed to ensure stability. Longer context is not always better; trade-offs must be made among latency, cost, and retrieval quality.

    4. Cloud Deployment and Ecosystem Adaptation Practices

    The path to production after a model is released is highly consistent: first open access through a public cloud API, then gradually support dedicated and private deployment, and finally complete adaptation to domestic accelerators and mainstream cloud platforms. After this class of model launched in early 2025, model marketplaces, container platforms, and AI computing cloud platforms from multiple cloud vendors successively offered one-click deployment, forming a complete “train — host — application” chain.

    In the context of Baidu AI Cloud, the common practice can be summarized as:

    1. Model hosting: use the model service category to handle weight loading, elastic scaling, and canary releases.
    2. Data and storage: store training corpora and inference logs in object storage and a logging service respectively, making auditing and traceback easier.
    3. Elastic compute: container platforms host distributed training and inference clusters, with monitoring and alerting to observe accelerator-hours and memory watermarks.
    4. Application integration: connect to business systems through a standard API gateway, use a message queue to smooth out traffic spikes, and use caching to reduce the overhead of repeated requests.

    5. Version Iteration and Selection Advice

    After the first version of this class of model was open-sourced in late December 2024, it went through multiple rounds of evolution, including minor bug-fix releases, capability-enhancement releases, and silent context extensions, giving rise to different branches for general conversation and for reasoning. The takeaway for users is to make model version, context length, and quantization precision configurable items in the architecture design, build a regression evaluation set, and re-verify both quality and latency after each upgrade.

    When selecting a model, focus on four points: per-token activation scale determines unit cost, context length determines the boundary of business fit, the feasibility of private deployment determines the data compliance path, and evaluation results need to align with your own business distribution rather than relying only on public leaderboards. Overall, sparse architectures, fine-grained compute scheduling, and mature cloud hosting capabilities are moving large models from a “compute race” to an “engineering efficiency race.”