NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Harmony in Diversity: Merging Neural Networks with Canonical Correlation Analysis

Stefan Horoi, Albert Manuel Orozco Camacho, Eugene Belilovsky, Guy Wolf

TL;DR

Model merging aims to combine multiple trained neural networks into a single model to save storage and inference costs, but traditional methods fail because they assume a strict one-to-one mapping between neurons. This paper introduces CCA Merge, a method that uses Canonical Correlation Analysis to align models via linear combinations of their features rather than simple permutations. This flexible alignment significantly reduces performance drops, especially when merging multiple models or networks trained on different data splits.

What Problem Does This Paper Address?

Ensembling multiple neural networks is a reliable way to boost accuracy and robustness, but it comes with a steep price tag: you have to store multiple copies of the weights and run inference on all of them simultaneously.

An appealing alternative is model fusion (or model merging), where the weights of multiple models are averaged into a single network. However, simply averaging weights from independently trained networks usually results in a model that performs no better than random guess. This happens because neural network loss landscapes are highly non-convex, and different training runs land in distinct local minima separated by high loss barriers.

To overcome this, researchers try to align the networks before averaging them. Most existing methods rely on finding the right permutation matrix to match neurons from one network to another. However, the authors argue that permutations are too restrictive: they assume a perfect one-to-one correspondence between neurons across different models. In reality, a feature learned by a single neuron in Model A might be distributed across multiple neurons in Model B.

Methods

The authors propose CCA Merge, a novel model merging algorithm based on Canonical Correlation Analysis (CCA). Instead of forcing a one-to-one neuron mapping, CCA Merge finds soft, linear combinations of features that maximize the correlation between the two models.

Figure 1: Visual representation of using CCA Merge to align two models. Canonical Correlation Analysis is used to find a common representation space where orthogonal linear combinations of the features (neurons) from A and B are maximally correlated. The linear transformation PA

The process operates layer-by-layer:

  1. Pass Data: Run a small dataset through both Model A and Model B to collect internal neuron activations ($X^\mathcal{A}$ and $X^\mathcal{B}$).
  2. Find Projection Matrices: Use CCA to compute projection matrices ($P^\mathcal{A}$ and $P^\mathcal{B}$) that map these activations into a common, maximally correlated representation space.
  3. Compute Transformation: Define a linear transformation matrix $T = (P^\mathcal{B} (P^\mathcal{A})^{-1})^\top$ to align Model B's weight space directly to Model A's space.
  4. Merge: Average the weights of Model A and the transformed Model B.

To merge multiple models (more than two), the authors employ an "all-to-one" approach: they select one model as a reference and align all other models to it before averaging.

Datasets

The method was evaluated using standard image classification architectures and datasets:

  • VGG11 trained on CIFAR-10
  • ResNet20 trained on CIFAR-100
  • ResNet18 trained on ImageNet

Models were trained either using standard one-hot labels or CLIP text embeddings of the class names to ensure a robust, shared output space.

Key Insights and Ideas

  • Features are Distributed, Not Permuted: By analyzing the correlation matrices of different models, the authors show that a single neuron's feature in one network is typically correlated with multiple neurons in another network. Permutation methods completely throw away this distributed relationship.
  • Permutations Cause Mismatches: In standard permutation alignment, between 25% and 50% of neurons are forced into "non-optimal matches" just to satisfy the strict one-to-one constraint.
  • Errors Compound in Multi-Model Merging: When merging more than two models using permutations, indirect alignment errors compound drastically. If you align Model B to A, and Model C to A, the indirect alignment between B and C becomes highly distorted. CCA Merge maintains much tighter consistency across multiple models, preventing this representation collapse.

Key Results

CCA Merge consistently and significantly outperforms popular permutation-based baselines (like Git Re-Basin's Matching Weights and ZipIt!):

  • Standard Merging (2 Models): On CIFAR-10 with a standard-width VGG11, CCA Merge achieved 82.65% accuracy, compared to just ~54-55% for permutation methods (Permute, OT Fusion, Matching Weights).
  • Scaling to Many Models: The performance gap widens dramatically when merging more models. As shown in the paper's multi-model experiments, when merging 5 VGG models, permutation methods collapse to under 20% accuracy, while CCA Merge maintains a stable ~80% accuracy.
Accuracies of averaging multiple models after feature alignment with different merging methods.
  • Disjoint Data Splits: In federated-learning-style setups where models are trained on different subsets of data, CCA Merge is often the only method that successfully outperforms the average performance of the individual base models.

Limitations and Future Work

The primary limitation of CCA Merge is that it is a data-dependent method. It requires a forward pass of input data to compute the activation statistics needed for CCA. In some privacy-sensitive or decentralized settings (like certain federated learning scenarios), a shared alignment dataset might not be readily available. Additionally, computing these correlations adds a minor computational overhead during the merging phase, though the authors note it still takes less than 35 seconds for a ResNet20 on CIFAR-100.

For future work, the authors suggest exploring how CCA Merge handles models trained on entirely different datasets to test the absolute limits of combining distinct feature spaces.

Summary updated

BibTeX
@inproceedings{horoi2024harmony,
  author = {Stefan Horoi and Albert Manuel Orozco Camacho and Eugene Belilovsky and Guy Wolf},
  title = {{Harmony in Diversity: Merging Neural Networks with Canonical Correlation Analysis}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=hLuNVjRnY3},
}
Figure