Soft Merging of Experts with Adaptive Routing

Mohammed Muqeeth, Haokun Liu, Colin Raffel · OpenReview

Abstract

Sparsely activated neural networks with conditional computation learn to route their inputs through different "expert" subnetworks, providing a form of modularity that densely activated models lack. Despite their possible benefits, models with learned routing often underperform their parameter-matched densely activated counterparts as well as models that use non-learned heuristic routing strategies. In this paper, we hypothesize that these shortcomings stem from the gradient estimation techniques used to train sparsely activated models that use non-differentiable discrete routing decisions. To address this issue, we introduce Soft Merging of Experts with Adaptive Routing (SMEAR), which avoids discrete routing by using a single "merged" expert constructed via a weighted average of all of the experts' parameters. By routing activations through a single merged expert, SMEAR does not incur a significant increase in computational costs and enables standard gradient-based training. We empirically validate that models using SMEAR outperform models that route based on metadata or learn sparse routing through gradient estimation. Furthermore, we provide qualitative analysis demonstrating that the experts learned via SMEAR exhibit a significant amount of specialization. All of the code used in our experiments is publicly available.

Introduction

In the quest for more efficient and modular AI, Mixture-of-Experts (MoE) models have become a popular choice. Instead of using every parameter for every input, these models use a "router" to send activations to specific "expert" subnetworks. However, MoE models face a fundamental mathematical hurdle: discrete routing is non-differentiable. If a router chooses Expert A but Expert B would have been better, standard backpropagation cannot easily inform the router how to improve because the choice was a hard, discrete jump. Researchers usually rely on gradient estimation techniques like REINFORCE or Gumbel-Softmax, but these are often high-variance, unstable, and frequently result in "degenerate" models where the router fails to learn meaningful specialization.

Methodology

SMEAR replaces discrete routing with a fully differentiable parameter-merging step. For a given input, a lightweight router produces a probability distribution over $N$ experts. Instead of picking the top expert, SMEAR computes a weighted average of the parameters ($\theta$) of all experts based on the router's output. The input is then processed by this single "merged" expert. Because parameter averaging is a simple linear operation, the entire path from the loss function back to the router is fully differentiable, allowing standard backpropagation to function effectively.

Comparison of Discrete Routing versus the proposed SMEAR approach.

SMEAR only performs one expert-sized forward pass, making it nearly as fast as discrete routing while being much more stable to train. This avoids the $N$-fold computational increase associated with ensemble routing (averaging outputs), which requires running the input through every single expert.

Experimental Setup

The authors evaluated SMEAR across two distinct modalities:

  • NLP (T5-GLUE): Fine-tuning a T5-Base model on the GLUE benchmark. Experts were inserted into the Transformer blocks as adapters.
  • Computer Vision (ResNet-DomainNet): Adapting a ResNet-18 on DomainNet, which contains images across six distinct domains (Clipart, Quickdraw, Sketch, etc.).

Results and Discussion

SMEAR consistently outperforms both gradient estimation techniques and heuristic routing strategies. On T5-GLUE, SMEAR achieved an average accuracy of 81.6%, outperforming "Tag Routing" (78.5%)—which uses oracle metadata—and the best gradient estimator, REINFORCE (80.0%). On DomainNet, SMEAR reached 62.0% accuracy, again beating Tag Routing (61.4%) and all other learned routing baselines.

Average accuracy versus inference speed (examples/second) for T5-GLUE and ResNet-DomainNet.

Qualitative analysis shows that the experts learned via SMEAR exhibit significant specialization. The router learns to group similar tasks together (e.g., grouping sentence-similarity tasks in GLUE) and develops high sparsity, relying on specific experts for specific inputs. Furthermore, SMEAR's inference speed is nearly identical to discrete routing, providing a 1.2x to 1.3x speedup over ensemble methods with virtually no loss in accuracy.

Conclusion

SMEAR offers a robust solution to the training instabilities of MoE models by leveraging parameter merging. While it requires experts to share the same architecture, it provides a computational sweet spot between efficiency and performance. Future work may explore scaling SMEAR to massive MoEs with thousands of experts or employing more sophisticated merging techniques like Fisher-weighted averaging.

Summary updated

Abstract

Sparsely activated neural networks with conditional computation learn to route their inputs through different "expert" subnetworks, providing a form of modularity that densely activated models lack. Despite their possible benefits, models with learned routing often underperform their parameter-matched densely activated counterparts as well as models that use non-learned heuristic routing strategies. In this paper, we hypothesize that these shortcomings stem from the gradient estimation techniques used to train sparsely activated models that use non-differentiable discrete routing decisions. To address this issue, we introduce Soft Merging of Experts with Adaptive Routing (SMEAR), which avoids discrete routing by using a single "merged" expert constructed via a weighted average of all of the experts' parameters. By routing activations through a single merged expert, SMEAR does not incur a significant increase in computational costs and enables standard gradient-based training. We empirically validate that models using SMEAR outperform models that route based on metadata or learn sparse routing through gradient estimation. Furthermore, we provide qualitative analysis demonstrating that the experts learned via SMEAR exhibit a significant amount of specialization. All of the code used in our experiments is publicly available.
BibTeX
@misc{muqeeth2023soft,
  author = {Mohammed Muqeeth and Haokun Liu and Colin Raffel},
  title = {{Soft Merging of Experts with Adaptive Routing}},
  year = {2023},
  eprint = {2306.03745},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.03745},
}
Figure