Mixture-of-Experts LLMs: Efficient Training, Inference, and Engineering Practices

    This article examines the engineering background and core principles of Mixture-of-Experts (MoE) large language models, including sparse activation, fine-grained and shared experts, and load balancing. It then reviews practical methods for low-cost large-scale training such as FP8 mixed precision, multidimensional parallelism, communication optimization, and stability safeguards, and discusses inference acceleration through multi-token prediction, speculative decoding, KV cache compression, and sparse activation. The final section summarizes implications for developers and enterprises considering model selection, deployment, and cost control.

    1. Engineering Background of Ultra-Large Language Models

    In recent years, the parameter count of large language models (LLMs) has risen from tens of billions to hundreds of billions, and even trillions. By way of example, a representative open-source model released in late 2024 has a total parameter scale of 671 billion, with a pretraining corpus of 14.8 trillion tokens. It has reached the level of top-tier closed-source models on multiple benchmarks, with particularly strong performance on mathematical reasoning and Chinese-language understanding tasks. However, the expansion of parameter scale also brings serious challenges: with a traditional dense architecture, every token’s forward computation requires activating all parameters, making the compute overhead for training and inference unsustainable.

    Against this background, the Mixture-of-Experts (MoE) architecture has become a mainstream technical route for building ultra-large models. Its core idea is that although the model contains a massive number of parameters, each token activates only a small subset of “expert” networks, thereby maintaining model capacity while keeping per-inference computation within an acceptable range. For example, the model above has 671 billion total parameters, but only about 37 billion parameters actually participate in computation for each token, an activation ratio of about 5.5%. This is a direct illustration of the power of the MoE architecture.

    2. Core Principles of MoE Architecture

    2.1 Sparse Activation Mechanism

    MoE replaces the feed-forward network (FFN) layers in a Transformer with several parallel “expert” subnetworks and introduces a router module. For each input token, the router computes relevance scores for each expert based on the token representation, selects the Top-K experts with the highest scores to participate in computation, and keeps the remaining experts dormant. The final output is a weighted sum of the selected experts’ outputs.

    Illustrative pseudocode is as follows:

    1. def moe_forward(x, experts, router, top_k=8):
    2. # router outputs a score for each expert
    3. scores = router(x) # [num_experts]
    4. top_idx, top_w = topk(scores, top_k) # select Top-K experts
    5. top_w = softmax(top_w) # normalize weights
    6. out = 0
    7. for w, idx in zip(top_w, top_idx):
    8. out += w * experts[idx](x) # sparse activation
    9. return out

    The essence of this design is to trade parameter capacity for computation: increasing the parameter count improves knowledge storage and representation capability, while sparse routing decouples computation from total parameter count.

    2.2 Fine-Grained Experts and Shared Experts

    Modern MoE designs commonly adopt a combination of “fine-grained experts + shared experts.” Fine-grained partitioning means dividing the FFN into a larger number of smaller experts—for example, activating 8 out of 256 routed experts at a time—so that expert combinations grow exponentially and enable more flexible knowledge representation. Shared experts are always activated for all tokens and are responsible for capturing cross-task general knowledge, reducing redundancy among routed experts. This structure improves parameter utilization and alleviates expert homogenization.

    2.3 Load Balancing

    A classic challenge in MoE training is load imbalance: if the router always favors a few popular experts, those experts become overloaded while others are “starved,” wasting capacity and creating communication bottlenecks in distributed computing. Common solutions include:

    • Auxiliary load-balancing loss: adding a penalty term to the loss function to encourage experts to be selected evenly;
    • Auxiliary-loss-free bias adjustment: introducing a dynamically adjustable bias term into router scores that affects only expert selection, not weight magnitude, avoiding interference from auxiliary losses;
    • Capacity factor and token dropping: setting a processing upper limit for each expert and passing through tokens that exceed capacity, trading a small amount of accuracy for training stability.

    3. Engineering Practices for Low-Cost Large-Scale Training

    3.1 Understanding Training Cost at the Order-of-Magnitude Level

    The model above was trained using only about 2,048 mainstream data-center GPUs. Pretraining accumulated about 2.664 million GPU-hours; including subsequent alignment and fine-tuning, the total was about 2.788 million GPU-hours. At market rental prices, the R&D cost is about $5.576 million. Compared with industry training investments that often reach tens of millions or even hundreds of millions of dollars, this figure is striking. Behind it are system-level engineering optimizations rather than a single trick.

    3.2 Mixed-Precision Training: The Value of FP8

    One key method for reducing training cost is FP8 mixed-precision training. Traditional BF16 training uses 2 bytes per parameter, while FP8 requires only 1 byte, theoretically doubling matrix multiplication throughput and significantly reducing memory usage and communication bandwidth pressure. However, FP8 has a limited dynamic range, and direct use can easily cause overflow or underflow. Engineering practice therefore commonly adopts:

    • Fine-grained quantization: computing scaling factors separately for small blocks, such as 128×128 weight blocks or 1×128 activation blocks, rather than using one scaling coefficient for an entire tensor;
    • Keeping key modules in higher precision: numerically sensitive components such as embedding layers, output heads, normalization layers, and some attention stages still use BF16 or FP32;
    • Online scaling and accumulation for higher precision: matrix multiplications are executed in FP8, but accumulation is periodically promoted to FP32 to avoid error accumulation from low-precision accumulation.

    3.3 Parallel Strategies and Communication Optimization

    Models with hundreds of billions of parameters must rely on multidimensional parallelism: data parallelism, tensor parallelism, pipeline parallelism, and expert parallelism working together. MoE expert parallelism introduces All-to-All communication, which distributes tokens to the devices hosting the corresponding experts according to routing results. Optimization directions include:

    • Overlapping computation and communication: using scheduling strategies such as dual pipelines to alternate All-to-All communication with expert computation and hide communication latency as much as possible;
    • Cross-node routing limits: limiting the number of nodes to which each token can be distributed, controlling cross-machine communication volume;
    • Fine-grained memory management: using general techniques such as activation recomputation, sharded storage of parameters and gradients, and optimizer state offloading to keep per-GPU memory usage within deployable limits.

    3.4 Training Stability Safeguards

    Ultra-large-scale pretraining cycles last for months, and any loss spike or hardware failure can cause enormous waste. Common best practices include high-frequency checkpoint saving and fast recovery during training, real-time monitoring and alerting for gradient norms and activation distributions, multiple rounds of data cleaning and ratio tuning, and gradually annealing the learning rate and introducing high-quality data in the later stages of training to improve final convergence quality.

    4. Inference Acceleration and Generation Efficiency

    After training is complete, inference cost determines whether a model can truly be deployed at scale. The aforementioned model achieves about a 3× generation speed improvement over its predecessor, mainly due to the following approaches:

    1. Multi-token prediction and speculative decoding: introducing multi-token prediction objectives during training; at inference time, using a draft model to generate multiple candidate tokens at once, which are then verified in parallel by the large model, parallelizing part of the serial autoregressive decoding process;
    2. KV cache compression: compressing key-value caches in attention through low-rank projection, significantly reducing memory usage in long-context scenarios and increasing the sequence length that a single batch can support;
    3. Inherent advantages of sparse activation: because each token activates only about 37 billion parameters, the per-step inference computation of an MoE model is far lower than that of a dense model with the same total parameter count, enabling higher throughput under reasonable deployment;
    4. Deployment form selection: enterprises can choose to build their own inference clusters or use cloud container platforms, GPU compute, and model inference services for elastic deployment, combined with logging and monitoring systems to ensure online stability.

    5. Implications for Developers and Enterprises

    First, model scale does not equal inference cost. The MoE architecture demonstrates that ultra-large capacity and controllable inference overhead can coexist. When selecting models, both total parameter count and activated parameter count should be considered.

    Second, cost advantages come from system-level coordination. FP8 precision, parallel scheduling, communication optimization, and data engineering are all indispensable; single-point optimization is unlikely to reproduce order-of-magnitude cost reductions.

    Third, open-source models lower the barrier to application. Enterprises can privately deploy such models on general-purpose compute platforms, fine-tune them with their own business data, and prioritize scenarios where these models excel, such as mathematical reasoning, code generation, and Chinese knowledge question answering.

    Fourth, continue to monitor inference-side optimization. As technologies such as speculative decoding, cache compression, and quantized inference mature, the serving cost of ultra-large models continues to fall rapidly. Architecture design should leave room for future upgrades.

    6. Conclusion

    671 billion parameters, 37 billion activated parameters, and $5.576 million in training cost—these figures mark a new stage of “efficient sparsification” in large-model engineering. The combination of MoE architecture, low-precision training, and system-level optimization means that top-performance language models are no longer exclusive to a few giants. For developers, understanding the sparse routing mechanism, training engineering methods, and inference acceleration principles behind this approach is a key step toward building technical competitiveness in the era of large models.