Sparse Mixture of Experts (SMoE) has become a cornerstone for scaling Transformer models efficiently. By only activating a subset of "expert" layers for any given token, we can build massive models with relatively modest computational costs. However, SMoE comes with a major headache: hyperparameter tuning. How many experts should you have ($K$)? How many should each token activate ($k$)?
A new paper from researchers at CUHK Shenzhen, Westlake University, and Tencent AI Lab introduces DynMoE (Dynamic Mixture of Experts), a technique that aims to automate these choices, allowing models to dynamically adjust their architecture during training.
TL;DR
DynMoE eliminates the need to manually tune the number of experts and their activation rates by introducing a "top-any" gating mechanism and an adaptive training process. It achieves competitive performance across vision, language, and vision-language tasks while activating significantly fewer parameters than traditional fixed-configuration MoE models.
What Problem Does This Paper Address?
The performance of standard MoE models is notoriously sensitive to the choice of $K$ (total experts) and $k$ (top-$k$ activated experts). As shown in the paper, different configurations can lead to a 1-3% performance discrepancy on benchmarks like GLUE. Finding the "sweet spot" usually requires expensive grid searches and multiple training runs, which is a massive waste of computational resources as models grow larger.
Furthermore, traditional top-$k$ routing forces every token to use the same amount of computation. In reality, some tokens are "easier" and might only need one expert, while "harder" tokens might benefit from several.
Methods
DynMoE tackles these issues with two core innovations:
-
Top-Any Gating: Instead of forcing a token to pick exactly $k$ experts, DynMoE treats each expert as an independent "class" in a multi-label classification problem. A token calculates a similarity score for every expert; if that score exceeds a trainable threshold ($G$), the expert is activated. This allows for "top-any" routing, where a token can activate zero, one, or all available experts based on need.
Illustration of the top-any gating method -
Adaptive Training Process: The model starts with an initial set of experts and dynamically adjusts during training:
- Adding Experts: If certain tokens fail to activate any existing experts, the model initializes a new expert using the mean embedding of those "unmatched" tokens.
-
Removing Experts: Experts that are rarely or never activated are pruned to maintain efficiency.
Figure 3: Elaboration on the adaptive training process. We visualize the adaptive training process of DYNMOE, including record routing, experts adding, and experts removing. The green strip connecting the token and the expert indicates records of a token routing to an expert. The red arrow at the bottom part of the figure shows where and when expert addition and removal happens. -
Sparse and Simple Gating Loss: To prevent the model from simply activating all experts to lower training loss, the authors introduced a new auxiliary loss. This loss encourages diversity (making expert representations orthogonal) and simplicity (normalizing weights), ensuring the model stays sparse and efficient.
Datasets
The authors evaluated DynMoE across a wide range of modalities:
- Vision: DomainBed benchmark (PACS, VLCS, OfficeHome, DomainNet).
- Language: GLUE benchmark (COLA, QNLI, RTE, MNLI, MRPC) using a BERT-large backbone.
- Vision-Language: A suite of 10 benchmarks including VQA-v2, GQA, and ScienceQA, using backbones like StableLM-1.6B and Phi-2.
- Pretraining: CIFAR-10 and Tiny-ImageNet.
Key Insights and Ideas
- Computation is Non-Uniform: The "top-any" approach confirms that tokens don't need equal processing. Some layers naturally gravitate towards activating only one expert, while others use more.
- Layer-Wise Specialization: A fascinating finding is that MoE is more critical in the bottom layers of a model. In the top layers (near the prediction head), tokens tend to converge on selecting the same expert, suggesting that the diversity provided by MoE is less useful there.
- Orthogonality Matters: Encouraging experts to be different (via the diversity loss) is more effective for dynamic growth than standard load-balancing losses, which just try to give every expert an equal number of tokens.
Key Results
DynMoE consistently matches or outperforms well-tuned static MoE models while being more efficient.
- Language Tasks: On the COLA dataset, DynMoE achieved 65.17% accuracy, surpassing the average performance of various fixed $(K, k)$ configurations (64.30%).
- Efficiency Gains: In vision-language tasks, DynMoE-LLaVA (using a StableLM backbone) activated 15% fewer parameters than the standard MoE-LLaVA while maintaining comparable or better accuracy across benchmarks.
- Robustness: Unlike fixed models whose performance swings wildly based on hyperparameters, DynMoE achieved stable, competitive results across different tasks without manual tuning.
Limitations and Future Work
While DynMoE is a significant step toward "auto-tuned" models, the authors note a few hurdles:
- Implementation Overhead: The current routing process introduces some overhead. Developing specialized CUDA kernels for top-any gating could make it even faster.
- Memory Management: Currently, all experts (active or inactive) reside in GPU memory. Implementing expert offloading to CPU/System RAM for inactive experts could significantly reduce memory requirements.
- Dynamic Integration: The authors suggest exploring how DynMoE could be combined with other dynamic techniques, such as layer skipping, for even greater efficiency.
Summary updated