Abstract
Layer-wise model fusion via optimal transport (OTFusion) has shown promise in unifying pre-trained networks to save computational resources. However, OTFusion traditionally requires input networks to have identical depths. We propose CLAFusion, a framework that enables the fusion of heterogeneous neural networks with varying numbers of layers through cross-layer alignment. By formulating alignment as an unbalanced assignment problem solved via dynamic programming, CLAFusion balances network depths before applying layer-wise fusion. Experimental results on CIFAR and Tiny-ImageNet demonstrate that CLAFusion provides a superior initialization for finetuning, outperforming training from scratch and traditional knowledge distillation.
Introduction
Deep learning often relies on ensembles to achieve state-of-the-art performance, but running multiple models simultaneously is computationally expensive during inference. Model fusion aims to merge these ensembles into a single, efficient network. While recent methods like OTFusion can successfully handle networks of different widths, they are constrained by depth; they cannot easily merge a 34-layer model with an 18-layer one. CLAFusion addresses this "cross-layer alignment" problem, enabling the fusion of heterogeneous architectures by determining functional correspondences between layers of different depths.
The CLAFusion Framework
The CLAFusion framework operates in three distinct stages to bridge the gap between heterogeneous models.
1. Cross-Layer Alignment (CLA)
The first step identifies an optimal one-to-one mapping from a shallower network's layers to a deeper network's layers. This is formulated as an unbalanced assignment problem and solved efficiently with $O(mn)$ complexity using dynamic programming. The similarity between layers is calculated using Linear Centered Kernel Alignment (CKA) based on the models' internal activations.
2. Layer Balancing
Once aligned, the models must be made the same depth. The framework achieves this by either:
- Adding Layers: Inserting identity-mapping layers into the shallower network.
- Merging Layers: Mathematically collapsing multiple layers in the deeper network into a single functional unit.
3. Layer-wise Model Fusion
With depths equalized and layers aligned, the framework applies OTFusion. This uses optimal transport to align neurons (handling different widths) and then averages the weights to create the final fused model.
Key Results and Insights
The authors evaluated CLAFusion across standard benchmarks including CIFAR-10, CIFAR-100, and Tiny-ImageNet.
- Superior Initialization: CLAFusion acts as a powerful initialization strategy. For example, fusing a ResNet-34 and ResNet-18 on CIFAR-10 reached 93.67% accuracy after finetuning, outperforming both the individual ResNet-34 (93.31%) and a ResNet-34 trained from scratch (92.00%).
- Heterogeneous Model Transfer: In teacher-student tasks, using CLA to align layers before transferring weights resulted in a significant jump in initial accuracy—from 18% to 61% on CIFAR-10 compared to standard methods.
- Efficiency: Fused models achieve near-ensemble performance with 3x to 4.5x less computational overhead during inference.
- The "First and Last" Constraint: A critical finding was that forcing the alignment to match the first-to-first and last-to-last hidden layers significantly improved performance, as these layers are functionally unique.
Conclusion
CLAFusion successfully extends model fusion to heterogeneous networks, providing a robust method for model compression and knowledge transfer. While currently optimized for models within the same architecture family (e.g., ResNets), it establishes a foundation for future work in cross-architecture fusion and more complex layer types.
Summary updated