Mixture of Experts: How It Works, Evolution, and Production Deployment

    This article explains the Mixture of Experts (MoE) architecture for large language models, covering its core mechanism, the benefits of sparse activation, key training challenges such as load imbalance and auxiliary losses, parallelization and communication overhead, infrastructure considerations like supernodes, and practical points for inference deployment. It provides a technical overview suitable for engineers and researchers evaluating or implementing MoE systems.

    Why Mixture of Experts

    In dense models, every input must pass through the full set of parameters. As the model grows, the computational cost per inference increases, and training and serving expenses rise roughly linearly. Mixture of Experts (MoE) offers a different approach: the network is split into multiple subnetworks, called experts, and only a subset is activated for each input. This allows the total parameter count to scale up while keeping the parameters actually used per input within a manageable range.

    To understand this idea, it helps to distinguish two concepts. Total parameter count determines the model’s capacity and storage footprint. Activated parameter count determines the cost of a single computation. The core value of MoE is decoupling these two. A model can have a very large total parameter count, but each token only passes through a small number of experts, making the computational cost close to that of a much smaller dense model.

    Between 2025 and 2026, this architecture continued to evolve. Trillion-parameter MoE models have appeared, and applications have expanded from general language tasks to embodied intelligence, healthcare, industrial manufacturing, and edge devices. These use cases show that sparse activation has moved from research to engineering practice, making related training, deployment, and infrastructure issues a priority for the industry.

    Basic Structure

    An MoE layer typically replaces the feed-forward network module in a Transformer. It consists of three parts.

    The first part is the expert networks. Experts are several feed-forward networks with identical structure but independent parameters. During training, each expert gradually learns to handle a certain type of feature or pattern, but there is no manually assigned division of labor among experts; the division emerges naturally from the training process.

    The second part is the gating network, also called the router. It is usually a small linear layer that takes the hidden representation of a token as input and outputs a score for each expert. After normalization, these scores can be interpreted as the probability of assigning the token to each expert.

    The third part is output combination. The system takes the selected experts’ outputs, weights them by the routing probabilities, and sums them to produce the final output of the layer.

    The following pseudocode illustrates the basic forward computation of a single layer:

    1. def moe_forward(x, experts, router, k):
    2. # x: [batch, hidden], each row is a token's hidden representation
    3. logits = router(x) # raw scores for each expert
    4. probs = softmax(logits) # normalize to probabilities
    5. topk_probs, topk_idx = top_k(probs, k) # select top-k experts per token
    6. topk_probs = topk_probs / sum(topk_probs) # re-normalize among selected experts
    7. output = zeros_like(x)
    8. for i in range(k):
    9. for e in range(len(experts)):
    10. mask = (topk_idx[:, i] == e) # find tokens assigned to expert e
    11. if any(mask):
    12. output[mask] += topk_probs[mask, i] * experts[e](x[mask])
    13. return output

    This code omits details like distributed communication and capacity limits, but it captures the core logic: each token only touches a few experts, and the remaining experts do not participate in this forward pass.

    Top-k Routing and Sparse Activation

    Top-k routing is the most common practice today. Each token selects only the top-k experts with the highest scores, where k is usually a small integer. The selected experts contribute to the computation with normalized weights; unselected experts produce no computation.

    The benefit of sparse activation is straightforward. If a model contains many experts but each token only activates a small number, the floating-point operations per computation are mainly determined by k and the size of a single expert, not by the total number of experts. This allows the model capacity to keep expanding without a proportional increase in inference cost.

    Sparsity also introduces trainability issues. The selection action in routing is discrete and cannot be differentiated directly. In practice, gradients mainly flow back to the router through the gating weights, while selected experts are updated through normal backpropagation. Unselected experts receive almost no gradient in that step, which affects their learning progress and is one of the problems that load-balancing designs need to address.

    Key Training Challenges

    Load Imbalance and Expert Collapse

    If some experts happen to perform better early in training, the router tends to assign more tokens to them. Those experts receive more training, improve further, attract even more tokens, and a Matthew effect emerges. The result is that a few experts become overloaded while many others remain idle, and the model’s effective capacity is far below what the total parameter count suggests. This phenomenon is often called expert collapse.

    Auxiliary Losses

    To suppress collapse, training usually adds a load-balancing auxiliary loss. The idea is to penalize situations where certain experts both receive a high fraction of tokens and have high average routing probabilities, encouraging a more even distribution across experts.

    1. # f_e: fraction of tokens actually assigned to expert e
    2. # P_e: average normalized routing probability for expert e
    3. # lambda: weight of the auxiliary loss, needs tuning
    4. aux_loss = num_experts * sum(f_e * P_e for e in range(num_experts))
    5. total_loss = task_loss + lambda_ * aux_loss

    The weight of the auxiliary loss needs careful setting. If it is too small, load imbalance persists; if it is too large, the router will prioritize balancing at the expense of task performance. In engineering practice, this requires monitoring validation metrics and expert utilization curves, with iterative adjustments.

    Capacity Limits and Token Dropping

    To keep computation and communication predictable within a batch, the system often sets a capacity limit for each expert. The capacity is usually related to “batch token count divided by the number of experts, multiplied by a capacity factor.” Tokens that exceed the capacity limit are dropped, or they skip the layer via the residual connection.

    The capacity factor is a trade-off parameter. A small value leads to more dropped tokens and hurts quality; a large value wastes memory and computation and increases communication pressure. Monitoring the token drop rate is a basic way to judge whether the capacity setting is appropriate.

    Parallelism Strategies and Communication Overhead

    Expert Parallelism

    When there are many experts and each expert has large parameters, a single accelerator cannot hold all experts. Expert parallelism places different experts on different devices, and each device stores and computes only its assigned experts.

    All-to-All Communication

    The key step in expert parallelism is token dispatch and collection. Each device’s tokens must be sent to the devices hosting their assigned experts based on the routing result, and after computation the results are sent back to the original device. This process is typically an All-to-All collective communication, meaning every device exchanges data with every other device.

    Communication volume scales with the number of tokens in the batch, the hidden dimension, and the value of k. A larger k means more copies of each token must be sent, increasing communication pressure.

    Combining with Other Parallelism

    In real training runs, expert parallelism is rarely used alone. It is usually combined with data parallelism, tensor parallelism, and pipeline parallelism. Communication from different parallel dimensions can overlap or accumulate, so the design of the parallel scheme must consider the overall topology, communication frequency, and memory usage. A general principle is to place the most communication-intensive steps on links with the highest bandwidth and to put lower-bandwidth synchronization on cross-node links.

    Supernodes and New Computing Infrastructure

    MoE’s All-to-All communication is highly sensitive to cross-node bandwidth. When experts are distributed across multiple servers, network latency and bandwidth between nodes often become the bottleneck, and a significant portion of device computation time may be spent waiting for communication.

    Supernodes have emerged as an infrastructure solution to this problem. The core idea is to organize a large number of accelerators into a logically large-scale computing domain through high-speed interconnect, so that communication bandwidth between devices within the domain is far higher than traditional cross-node networks. For MoE, this means most inter-expert communication can happen within the high-bandwidth domain, improving the ratio of computation to communication.

    When using supernodes, several aspects need to be evaluated:

    • Interconnect bandwidth and topology: evaluate the upper bound of intra-domain bandwidth, latency, and the impact of topology on All-to-All efficiency.
    • Failure domain: the larger the supernode, the more devices are affected by a single point of failure, requiring finer-grained fault tolerance and rescheduling mechanisms.
    • Scheduling and resource utilization: queueing, splitting, and elastic scaling of large tasks all affect overall utilization.
    • Cost structure: high-speed interconnect devices are expensive, so the return on investment should be judged based on task scale and utilization.

    The choice of infrastructure should serve the specific model size and training goals, rather than simply pursuing a larger scale.

    Inference and Deployment Considerations

    Memory Capacity

    During MoE inference, although each token only activates a few experts, the parameters of all experts usually still need to reside in accessible storage. The larger the total parameter count, the higher the requirement for GPU memory or a combination of GPU memory and external memory. Common approaches include distributing experts across multiple GPUs, using hierarchical loading, or moving less frequently used experts to slower storage and loading them on demand when memory is insufficient.

    Batch Size and Expert Utilization

    The request batch size during inference directly affects expert utilization. With small batches, each expert may receive very few tokens, leaving compute units idle for long periods and achieving low hardware efficiency. Increasing the batch size or using request batching can improve expert utilization, but it also increases the queuing latency for requests. Therefore, the batch size should be chosen based on the requirements of the specific application scenario.