Abstract
Merging various task-specific Transformer-based models trained on different tasks into a single unified model can execute all the tasks concurrently. Previous methods, exemplified by task arithmetic, have been proven to be both effective and scalable. Existing methods have primarily focused on seeking a static optimal solution within the original model parameter space. A notable challenge is mitigating the interference between parameters of different models, which can substantially deteriorate performance. In this paper, we propose to merge most of the parameters while upscaling the MLP of the Transformer layers to a weight-ensembling mixture of experts (MoE) module, which can dynamically integrate shared and task-specific knowledge based on the input, thereby providing a more flexible solution that can adapt to the specific needs of each instance. Our key insight is that by identifying and separating shared knowledge and task-specific knowledge, and then dynamically integrating them, we can mitigate the parameter interference problem to a great extent. We conduct the conventional multi-task model merging experiments and evaluate the generalization and robustness of our method. The results demonstrate the effectiveness of our method and provide a comprehensive understanding of our method. The code is available at https://github.com/tanganke/weight-ensembling_MoE
Introduction
Deep learning has increasingly shifted toward fine-tuning large-scale pre-trained models, such as CLIP, for specialized downstream tasks. While effective, this paradigm creates a deployment challenge: maintaining and running multiple task-specific models is computationally prohibitive. Model merging offers a solution by combining specialized weights into a single unified architecture. However, traditional merging techniques often suffer from "parameter interference," where the weights optimized for one task conflict with those of another, leading to significant performance degradation.
Existing methods like Task Arithmetic attempt to find a static "sweet spot" in the parameter space. This paper argues that a static solution is inherently limited. Instead, we propose WEMoE (Weight-Ensembling Mixture of Experts), which dynamically integrates shared and task-specific knowledge for every individual input.
Methodology
Knowledge Separation and Empirical Motivation
The WEMoE framework is built on the observation that different components of a Transformer layer adapt differently during fine-tuning. By analyzing cosine similarity and $L_2$ distances between pre-trained and fine-tuned weights, we found that Attention layers remain relatively similar to the base model, whereas MLP layers diverge significantly to capture task-specific features.
The WEMoE Architecture
Based on this insight, WEMoE employs a hybrid merging strategy:
- Static Merging for Attention: Attention layers and LayerNorm modules are merged using standard linear interpolation (Task Arithmetic), as they primarily contain shared knowledge.
- Dynamic Upcycling for MLPs: The MLP layers are transformed into a Weight-Ensembling MoE module. This module maintains the original pre-trained MLP weights (shared knowledge) and a dictionary of "Task Vectors" (the difference between each fine-tuned model and the base).
As shown in Figure 1, a small Router (a simple MLP) processes the input to determine the optimal weighting for these task vectors. The final weights for a specific instance are calculated as: $$\theta = \theta_0 + \lambda \sum_{i} w_i \tau_i$$ where $\theta_0$ represents the base weights, $\tau_i$ are the task vectors, and $w_i$ are the dynamic weights produced by the router.
Test-Time Adaptation (TTA)
To train the router without access to the original training data, WEMoE utilizes unlabeled test data. The router is optimized by minimizing Entropy Loss, which encourages the model to produce high-confidence, task-appropriate predictions for each input.
Experimental Results
Performance and Robustness
The researchers evaluated WEMoE using CLIP-ViT architectures across eight diverse image classification datasets, including SUN397, Stanford Cars, and EuroSAT. On CLIP-ViT-B/32, WEMoE achieved an average accuracy of 89.4%, significantly outperforming Task Arithmetic (69.0%) and Ties-Merging (72.8%). Notably, it even surpassed the traditional Multi-Task Learning (MTL) baseline (88.9%), suggesting that dynamic weight ensembling is more effective than forcing a single set of weights to learn all tasks simultaneously.
WEMoE also demonstrated superior robustness against image corruptions (e.g., noise, blur) and better zero-shot generalization to unseen tasks compared to static merging methods.
Efficiency
While WEMoE increases the total parameter count due to the task vector dictionary, it remains highly efficient. The number of trainable parameters (the router) constitutes only about 1.25% of the total model size, and the dynamic routing adds minimal inference latency.
Conclusion
WEMoE represents a shift from static to dynamic model merging. By identifying the specialized role of MLP layers and employing a weight-ensembling MoE approach, the method effectively mitigates parameter interference. Future work will explore applying this philosophy to Large Language Models (LLMs) and utilizing low-rank approximations to further reduce the memory footprint of the task vector dictionary.
Summary updated