Understanding Fine-Grained Experts and Shared Experts in MoE Architecture
This article explains the design principles behind Mixture of Experts (MoE) architecture, focusing on fine-grained expert splitting and shared expert isolation. It covers the computational workflow of MoE layers, the rationale for splitting experts into smaller units, how shared experts reduce parameter redundancy, load balancing strategies for training stability, and key engineering considerations for deployment. The article also discusses suitable use cases and current limitations of MoE-based models.
The Scaling Challenge of Dense Models
In a standard Transformer architecture, the feed-forward network (FFN) in each layer applies the same set of parameters to every input token. The larger the model, the more matrix operations are required to process each token. When parameter count doubles, the computational cost for both training and inference typically doubles as well. This tight coupling between model capacity and hardware cost is the most direct constraint in scaling large models.
The Mixture of Experts (MoE) approach splits a single FFN into multiple “experts,” each being a small feed-forward network with identical structure but independent parameters. A router selects a small number of experts for each token based on its hidden representation. The total parameter count can be very large, but each token only activates a fraction of them. This separation of total parameters from activated parameters is what allows sparse models to scale capacity without linearly increasing computational overhead.
Basic Computational Workflow of MoE
A single forward pass through an MoE layer typically involves three steps:
- Routing scoring: The router computes a score for each expert. A common approach is to apply a linear transformation to the hidden vector, followed by softmax normalization to obtain a probability distribution over experts.
- Sparse selection: The top-k experts with the highest scores are selected; the remaining experts do not participate in computation for this token.
- Weighted combination: Each selected expert processes the token, and their outputs are summed with weights determined by the routing scores.
Assuming N experts and k activated per token, the proportion of expert parameters actually used per token is approximately k/N. For example, with 64 experts and 6 selected per token, the activation ratio is about 9.4%. This ratio determines the computational cost of the sparse model and is fundamental to understanding subsequent design choices.
The following pseudocode illustrates the workflow described above. It is meant for conceptual clarity, not as a directly runnable implementation:
def moe_forward(x, experts, router, k):# x: input with shape [tokens, hidden]scores = softmax(router(x)) # probability of each token for each experttopk_scores, topk_idx = top_k(scores, k) # select k experts per tokentopk_scores = topk_scores / topk_scores.sum(-1, keepdims=True)out = zeros_like(x)for expert_id, expert in enumerate(experts):token_ids, slot = where(topk_idx == expert_id) # find tokens assigned to this expertif len(token_ids) == 0:continuey = expert(x[token_ids]) # only compute for selected tokensout[token_ids] += topk_scores[token_ids, slot][:, None] * yreturn out
Real-world implementations require additional handling for batched scheduling, capacity limits, and distributed communication, but the core logic remains consistent with the structure above.
Fine-Grained Expert Splitting
Traditional MoE designs typically use a relatively small number of large experts. This approach has two problems. First, each token can only choose among a few large experts, limiting the combination space. Second, large experts tend to learn overlapping general knowledge, creating parameter redundancy and lacking clear specialization.
Fine-grained expert splitting reduces the size of each expert while increasing the total number of experts, and correspondingly raises the number of experts activated per token. The intermediate dimension of each expert is shrunk so that the total activated computation remains roughly the same.
Consider this simplified comparison:
- Option A: 16 large experts, each token selects 2, giving C(16,2) = 120 possible combinations.
- Option B: 64 small experts, each with roughly one-quarter the intermediate dimension of Option A, each token selects 8, giving C(64,8) ≈ 4.4 billion combinations.
The per-token activated computation is similar in both cases, but Option B offers a vastly larger combination space. This means different tokens can be processed by different combinations of small experts, and finer-grained knowledge patterns have a better chance of being assigned to specialized experts.
The benefits of fine-grained splitting manifest in three main ways. First, experts become more specialized, with each small expert handling a narrower pattern. Second, multiple experts can collaboratively process a single token, enabling more flexible representations. Third, the model can accommodate more parameters without increasing activated computation, expanding the headroom for capacity growth.
This design comes with clear trade-offs. More experts increase routing computation and scheduling overhead. Small matrix operations typically achieve lower hardware utilization than larger ones, which may reduce actual throughput. In distributed deployments, token dispatch and collection across devices become more frequent. Therefore, the granularity of splitting must balance expressiveness against system efficiency; pursuing ever-finer splits is not always beneficial.
Shared Expert Isolation
Even with fine-grained splitting, routed experts may still redundantly learn certain general capabilities, such as common syntactic structures, basic semantics, and high-frequency patterns. These capabilities are useful for nearly all tokens, and having multiple routed experts store them separately wastes capacity.
Shared expert isolation addresses this by setting aside a small number of experts that are always activated. These shared experts bypass the router and process every token, serving as the repository for general-purpose foundational knowledge. The remaining routed experts can then concentrate their capacity on differentiated, domain-specific knowledge.
The output of such a layer can be summarized as:
def shared_moe_layer(x, shared_experts, routed_experts, router, k):shared_out = sum(e(x) for e in shared_experts) # all tokens pass through shared expertsrouted_out = moe_forward(x, routed_experts, router, k) # routed experts computed on demandreturn shared_out + routed_out
Shared expert isolation offers two direct benefits. First, knowledge redundancy among routed experts is reduced, leading to clearer division of labor. Second, every token has a stable foundational computation path, which improves representation consistency and makes training more stable.
This design also requires trade-offs. Shared experts process every token, so their number and size should not be too large; otherwise, the computational savings from sparsity are diminished. There is no universal fixed ratio between shared and routed experts; it needs to be determined through controlled experiments based on the task and model scale.
Load Balancing and Training Stability
The router is prone to developing preferences early in training: certain experts receive high scores and are selected by many tokens, while others receive little to no training signal. This phenomenon is commonly called routing collapse. Its consequences include undertrained experts, wasted model capacity, and severely imbalanced computational load across devices.
Common mitigation strategies used in practice include:
- Auxiliary load balancing loss: A penalty term is added to the total loss, increasing when the distribution of expert selection is more uneven. The coefficient of this loss requires careful tuning. If too large, the model sacrifices language modeling quality for balance; if too small, the balancing effect is insufficient.
- Capacity factor: Each expert is assigned a maximum number of tokens it can process per step. Tokens exceeding the capacity may be dropped or redirected to the next-best expert. A larger capacity factor reduces token dropping but increases memory and communication pressure.
- Bias adjustment without auxiliary loss: A dynamically updated bias term is maintained for each expert. The bias only affects top-k selection during routing and does not directly contribute to the weighted output. During training, experts with higher load have their bias gradually lowered, while underloaded experts have their bias raised. This approach avoids direct conflict between the auxiliary loss and the language modeling objective.
In addition, input normalization for the router, initialization schemes, and numerical precision of routing scores can also affect training stability. Routing scores are sensitive to numerical errors, so higher precision is often maintained at critical steps in practice.
Key Engineering Challenges
MoE models have very large parameter counts; all expert weights must reside in GPU memory or RAM, even though only a small fraction is used per token. Experts are therefore typically distributed across multiple devices, forming an arrangement known as expert parallelism.
The primary overhead in expert parallelism comes from all-to-all communication. Tokens on each device must be sent to the devices hosting their selected experts, and results must be sent back after computation. Common engineering optimizations include:
- Sorting tokens by their target expert to reduce scattered write overhead;
- Overlapping communication with computation to reduce latency;
- Placing experts strategically so that frequently communicating pairs reside on the same node;
- Evaluating whether sparse computation still provides throughput benefits when batch sizes are small.
For ongoing operations, it is recommended to monitor the following metrics: the number of tokens received by each expert and its distribution, the dispersion of expert load, the proportion of tokens dropped due to capacity limits, and the fraction of step time spent on communication. These metrics can be logged and used to set alert thresholds. If an expert is persistently overloaded or idle, the router state and balancing strategy should be investigated.
Applicable Scenarios and Limitations
MoE architecture is well suited to the following scenarios. First, tasks with broad coverage that require the model to master knowledge across multiple domains. Second, situations where larger model capacity is needed within a limited inference budget. Third, training data scales large enough to support multiple experts in developing specialized capabilities.
Its limitations must also be acknowledged:
- High memory footprint: All expert weights must be stored, making deployment requirements higher than dense models with similar activated parameter counts.
- Complex fine-tuning: When fine-tuning on small datasets, experts are prone to overfitting, and the routing distribution may drift. Freezing certain parameters or adding routing constraints may be necessary.
- Sensitivity to training details: Load balancing strategies, capacity factors, and shared expert ratios can significantly affect final performance with only small changes.
- Diminished returns at small batch inference: When each request contains few tokens, parallelism among experts is insufficient, and the speed advantages of sparse computation weaken.
