Choosing a Mixture-of-Experts Architecture: Shared Experts vs. Sparse Routing
Mixture-of-Experts (MoE) models decouple total parameter count from per-token inference cost, but the architecture choice affects routing stability, quality, and deployment cost. This article compares shared-expert plus routed-expert designs with pure sparse routing, explains auxiliary load-balancing loss with a PyTorch example, and reviews Top-K selection, gating normalization, capacity factors, model-size series, selection criteria, and a pre-deployment validation checklist.
Why MoE Is Needed
Large models have moved from tens of billions to hundreds of billions or even trillions of parameters, but inference cost cannot scale at the same rate. In a dense model, every token passes through all parameters, so inference cost is roughly proportional to parameter scale. MoE (Mixture of Experts) breaks this relationship through sparse activation: the model can have a very large total parameter count, while each token activates only a subset of expert networks.
It helps to think in terms of two numbers. Total parameters determine the upper bound of knowledge capacity, while active parameters determine the compute required for a single inference pass. Once these are decoupled, training teams can continue increasing parameters while keeping the increase in inference overhead manageable. Many mainstream large models use MoE or its variants, which shows that under current compute constraints, it is a repeatedly validated path.
The basic flow of an MoE layer is as follows: input tokens pass through a router, which is a small fully connected layer, and the router outputs scores for N experts. The Top-K experts with the highest scores participate in computation, and their outputs are weighted by the gating weights and summed to produce the final output.
Two Representative Designs: Shared Experts and Pure Sparse Routing
MoE implementations in the industry broadly fall into two categories.
The first is shared experts plus routed experts, often called an “N+1” structure. Shared experts do not compete in routing. Every token passes through them, and they handle general processing such as syntax and common knowledge. Routed experts each specialize in certain patterns, and the router selects a small number of them to activate for each token.
A common illustrative configuration is one shared expert plus eight routed experts, with two activated per token. This is only an example. The number of shared experts, the number of routed experts, and Top-K are all determined by the specific model design; there is no unified industry standard.
This structure has three main advantages. First, general knowledge is handled by shared experts, so the router only needs to deal with specialized division of labor, which relatively reduces the risk of uneven expert load. Second, each routed expert can receive more training in its niche direction, reducing the number of experts that are never selected for long periods. Third, even if routing makes a mistake, the shared expert still helps keep the output basically stable. Its disadvantage is that the compute and memory occupied by shared experts are fixed overhead, so the activation ratio cannot be reduced indefinitely.
The second category is pure sparse routing, with no shared experts. All experts are selected by the router through competition. Its advantage is that the leverage effect of parameter scale is more direct: total parameters can be much larger than active parameters, and the cost of expanding capacity mainly falls on routing and communication. Its risk is routing collapse, where most tokens flow to a small number of experts and the remaining experts receive almost no training. The load-balancing mechanisms discussed in the next section are mainly designed for this risk.
Load Balancing: Writing the Auxiliary Loss
During training, an auxiliary loss is generally added to penalize uneven load across experts. The formulation proposed by Switch Transformer is relatively common. Here, f_i represents the fraction of tokens assigned to expert i, and P_i represents the average router probability for expert i. The loss is written as N multiplied by Σ f_i·P_i.
Below is an illustrative PyTorch implementation:
import torchdef load_balance_loss(router_probs, expert_mask, num_experts, top_k):# router_probs: [tokens, num_experts], probabilities after router softmax# expert_mask: [tokens, num_experts], 1 at the selected expert positions for each token, 0 elsewheref = expert_mask.float().mean(dim=0) / top_k # assignment fraction per expert; sums to 1p = router_probs.mean(dim=0) # average router probability per expertreturn num_experts * torch.sum(f * p)
With perfectly uniform load, this loss reaches its minimum value of 1. If a small number of experts simultaneously handle many tokens and also have high router probabilities, the loss increases noticeably, and the gradient pushes the router to spread traffic more evenly. When checking whether an implementation is correct, use the value 1 under a uniform distribution as the baseline, not 0.
In addition to auxiliary loss, there are other methods. Some implementations add learnable biases to experts and dynamically adjust scores based on recent load. Others add noisy gating in early training so that experts receive more even exploration opportunities. These methods share the same goal: preventing routing from becoming fixed too early.
Top-K, Gating Normalization, and Capacity Factor
Top-K determines how many experts each token activates. Fine-grained experts with a larger K, such as Top-4 or Top-6, allow more flexible expression, and each individual expert is smaller. Coarse-grained experts with a smaller K, such as Top-2, give each expert stronger capability but offer fewer combinations. Each approach has suitable scenarios, depending on task diversity and available memory.
After selecting Top-K, the gating weights are generally renormalized so that the weights of the selected experts sum to 1. Otherwise, when the total probability produced by the router is small, the magnitude of expert outputs will fluctuate with the routing distribution, affecting training stability.
The capacity factor is another key engineering parameter. Each expert has an upper limit on the number of tokens it can process in one batch. The limit is determined by batch size, K, the number of experts, and the capacity factor. Tokens that exceed the limit are dropped or routed to other paths. A capacity factor that is too small causes more tokens to be dropped and hurts quality. A capacity factor that is too large increases memory and communication overhead. Capacity settings may differ between training and inference, so they need to be checked separately.
Value and Risks of Model Size Series
It is common practice to produce multiple size tiers using the same training framework and data pipeline. For example, a small model can be used for local debugging, while a large model is used for high-quality production. Both have the same interface, which makes migration easier. A small model can also acquire part of a large model’s capability through distillation or inherited training.
This approach also carries risks. Small and large models do not always behave consistently. The same prompt may perform very differently across sizes, so “consistent interface” does not mean “consistent quality.” Capabilities obtained through distillation are usually concentrated on tasks covered by the training distribution and may degrade noticeably on long-tail tasks. When selecting a model, each size should be evaluated separately rather than judged only by the series name.
Selection Criteria
When evaluating an MoE model, consider the following four dimensions.
- Activation ratio and knowledge capacity. The ratio of total parameters to active parameters determines knowledge density. When the activation ratio is too low, the router must choose among more experts, increasing the probability of routing instability. In this case, confirm whether training is sufficient and check whether evaluation results show obvious fluctuations.
- Load-balancing mechanism. Whether the model uses shared experts, auxiliary loss, expert bias, or other methods directly affects performance under long-context and mixed-domain workloads. Test with the same mixed-domain data and observe whether there are obvious gaps across domains.
- Expert granularity and Top-K. Combine task diversity with the tradeoffs described above.
- Deployment stack. MoE has different memory and communication requirements from dense models. When expert weights are distributed across multiple GPUs, each layer requires all-to-all communication. The communication volume is related to token count, K, and expert distribution, and often becomes a bottleneck for multi-GPU inference.
Pre-Deployment Staged Validation Checklist
Before scaling to production, validate the following items one by one.
- Memory: Estimate weight, KV cache, and activation usage based on maximum concurrency and longest context, and reserve headroom.
- Communication: Record the share of all-to-all time per layer and observe whether throughput scales close to linearly as more GPUs are added.
- Capacity factor: Measure the token drop rate and confirm that it is acceptable under the target workload.
- Expert load: Monitor the actual token share of each expert. If persistent skew appears, investigate the router or data distribution.
- Quality: Compare the target size and alternative sizes on business-relevant evaluation sets, not only on public leaderboard results.
- Latency and throughput: Test time to first token and sustained generation speed separately, and record P95 and P99 under typical concurrency.
The core of this checklist is to turn “is the architecture good?” into “is it stable under my workload?” The advantage of MoE is the decoupling of parameters and cost, and this decoupling only truly holds when load balancing, communication, and memory are all under control.
