TL;DR
Bayesian Model Merging (BMM) is a novel plug-and-play framework that combines multiple task-specific expert models into a single architecture without any retraining. By framing model merging as an anchor-regularized Bayesian linear regression and globally optimizing module-specific hyperparameters via Bayesian Optimization, BMM significantly reduces task interference and achieves near-expert performance in both data-assisted and data-free settings.
What Problem Does This Problem Address?
Fine-tuning foundation models for specific downstream tasks has become standard practice, but deploying a separate large model for every single task creates massive storage, deployment, and operational overhead. While multi-task learning offers a unified alternative, it requires simultaneous access to all training datasets and incurs prohibitive retraining costs—making it impractical under data privacy constraints or limited computing budgets.
Model merging has emerged as a cheaper, data-private alternative that directly combines the weights of task-specific experts. However, existing merging methods suffer from two major limitations:
- Estimating from scratch: They typically calculate merged weights without exploiting the valuable inductive bias of strong "anchor" models (existing merged solutions).
- Homogeneous assumptions: They apply a uniform hyperparameter setting across all network modules, completely ignoring the structural heterogeneity of deep neural networks.
Methods
BMM addresses these gaps using a bi-level optimization framework that treats model merging through a probabilistic lens:
- Inner Level (Bayesian Linear Regression): BMM frames module-wise weight estimation as an activation-based linear regression. Crucially, it introduces an element-wise Gaussian prior centered around a strong "anchor" model (e.g., Task Arithmetic or TSV). This formulation yields an efficient, closed-form Maximum A Posteriori (MAP) solution for the merged weights.
- Outer Level (Bayesian Optimization): Instead of sharing a single hyperparameter across the entire network, BMM uses a Gaussian Process-based Bayesian Optimization (BO) loop to search for module-specific regularization strengths ($\lambda$) and scaling factors ($s$) globally, maximizing performance on a small validation set.
- Block-wise Parameter Tying: To prevent the BO search space from exploding, BMM groups consecutive Transformer layers into sequential blocks and ties modules within each block into four functional groups (attention-in, attention-out, MLP-in, and MLP-out), keeping the optimization highly efficient.
Going Data-Free
While the standard formulation relies on a small calibration dataset to compute activation statistics, the authors derive a data-free variant of BMM. They prove mathematically that the Gram matrix of input activations is positively correlated with the Gram matrix of the task vectors themselves. This allows BMM to substitute empirical data activations with an expert-weight-induced surrogate, eliminating the need for auxiliary calibration data entirely.
Datasets
The authors evaluated BMM across extensive vision and language benchmarks:
- Vision Tasks: Evaluated using ViT-B/32 and ViT-L/14 backbones across 8-task, 14-task, and 20-task merging scenarios. Datasets included standard image classification benchmarks such as Stanford Cars, DTD, EuroSAT, GTSRB, MNIST, RESISC45, SUN397, SVHN, CIFAR-10/100, STL-10, Flowers102, Oxford-IIIT Pets, PCAM, FER2013, EMNIST, Food101, Fashion-MNIST, Rendered SST-2, and KMNIST.
- Language Tasks: Evaluated using Llama-3.2-3B and Llama-3.1-8B backbones on a 5-task merging benchmark spanning Instruction Following (TULU-3, IFEval), Mathematics (DART, NuminaMath, GSM8k), Multilingual capabilities (Aya, M_MMLU), Coding (Magicoder, MBPP, HumanEval+), and Safety (WildGuard, WildJailbreak, HarmBench, XSTest).
Key Insights and Ideas
- Weights Encode Data Geometry: The most surprising theoretical contribution (Theorem 1) is that a model's fine-tuned weights inherently mirror its activation statistics. This alignment means that the expert models themselves contain enough structural information to substitute for real data during the regression step.
- Anchors as Informative Priors: Rather than trying to resolve weight conflicts blindly, treating an existing merged model as a Bayesian prior provides a strong inductive bias that prevents overfitting on small validation or calibration sets.
- Module Heterogeneity is Essential: Network layers are highly coupled but functionally diverse. Coordinating regularization strengths uniquely across different module groups yields substantial performance boosts over uniform scaling.
Key Results
BMM consistently outperformed all plug-and-play anchor baselines across both vision and language models, showing massive gains over weaker anchors and steady improvements over state-of-the-art methods.
Vision Benchmarks
On the challenging ViT-L/14 benchmark for 8-task merging, a single BMM-merged model reached an accuracy of 95.1% (data-assisted) and 95.0% (data-free), nearly matching the 95.8% average performance of the eight separate, task-specific expert models.
Language Benchmarks
For LLMs, data-free BMM pushed the competitive TSV anchor from 0.471 to 0.486 on Llama-3.2-3B, achieving the top score among all evaluated merging methods. On Llama-3.1-8B, data-assisted BMM paired with TIES achieved the overall best 8B performance of 0.579.
Efficiency
BMM proved highly sample-efficient. The Bayesian Optimization loop typically converged within just 40 to 60 trials, making it significantly faster than exhaustive grid searches or iterative stochastic gradient descent (SGD) optimization methods.
Limitations and Future Work
The authors note that their experiments were currently limited to models up to the 8B parameter scale due to computational constraints. Testing BMM on larger LLMs (e.g., 70B+ parameters) remains an open direction. Additionally, because BMM is a training-free aggregation framework, the merged models risk inheriting underlying biases, safety flaws, or domain-specific failures present in the original expert models.
Summary updated