On Cross-Layer Alignment for Model Fusion of Heterogeneous Neural Networks

Dang Nguyen, Trang Nguyen, Khai Nguyen, Dinh Q. Phung, Hung Hai Bui, Nhat Ho · DOI

TL;DR

This paper introduces CLAFusion, a novel framework for merging neural networks with different architectures (heterogeneous networks), a task previously challenging for existing methods like OTFusion. CLAFusion achieves this by first aligning layers across networks using a dynamic programming approach and then balancing their depths before applying standard model fusion. This enables more effective knowledge transfer, leading to improved performance in tasks like model compression and knowledge distillation.

What Problem Does This Paper Address?

The field of deep learning heavily relies on large, pre-trained neural networks. While these models achieve impressive performance, deploying them can be computationally expensive due to their size and inference time. Model fusion techniques aim to combine knowledge from multiple pre-trained models into a single, more efficient network. However, existing methods like OTFusion, which use optimal transport for layer-wise fusion, are limited to networks with the exact same number of layers (homogeneous networks). This paper addresses the critical gap of fusing heterogeneous neural networks, specifically those with different depths (number of layers), which is a common scenario in practice. The challenge lies in establishing meaningful correspondences between layers of varying depths and then effectively merging them.

Methods

CLAFusion is a three-part framework designed to fuse heterogeneous neural networks:

  1. Cross-Layer Alignment (CLA): This is the core novelty. It formulates the problem of matching layers between two networks with different depths as an unbalanced assignment problem. The authors propose a dynamic programming algorithm to efficiently solve this, finding a one-to-one mapping between the hidden layers of the shallower network and the deeper network. This mapping is constrained to be strictly increasing to preserve the sequential order of layers. Layer representation is based on pre-activation matrices, and dissimilarity is measured using Linear CKA.
  2. Layer Balancing: Once the cross-layer alignment is established, this step equalizes the number of layers between the two networks. Two methods are proposed:
  3. Adding layers: New layers are inserted into the shallower network to match the depth of the deeper one. This is presented as a function-preserving transformation.
  4. Merging layers: Layers from the deeper network are merged to match the shallower one. This involves more complex weight matrix calculations.
  5. Layer-wise Model Fusion: After the networks are depth-balanced and aligned, a standard layer-wise model fusion method (like OTFusion) is applied to combine their weights.

Datasets

The paper evaluates CLAFusion on several standard image classification datasets:

  • CIFAR10
  • CIFAR100
  • Tiny-ImageNet

For ablation studies and specific experiments, they also use:

  • MNIST (for fully connected networks)

Key Insights and Ideas

  • Cross-layer alignment is crucial for heterogeneous fusion: Simply aligning layers by index (e.g., layer 1 to layer 1) fails when networks have different depths. A learned alignment is necessary to find meaningful correspondences.
  • Dynamic programming for efficient alignment: The authors demonstrate that the cross-layer alignment problem, despite being an unbalanced assignment problem, can be solved efficiently using dynamic programming, making the approach practical.
  • Layer balancing is a necessary precursor to fusion: Before fusing, the networks must have compatible structures. CLAFusion's layer balancing methods provide a systematic way to achieve this.
  • CLAFusion as an initialization strategy: The fused model from CLAFusion serves as a strong initialization for training larger networks, outperforming methods like NET2NET in some scenarios. This suggests that CLAFusion effectively aggregates knowledge from multiple sources.
  • Potential for model compression and distillation: The framework shows promise in compressing large models and improving knowledge distillation by providing better initializations for student networks.

Key Results

  • Improved accuracy on image classification: When fusing RESNET34 and RESNET18 models on CIFAR10, CIFAR100, and Tiny-ImageNet, CLAFusion followed by finetuning achieved the highest classification accuracies compared to baselines like finetuning individual models or using NET2NET for initialization. For example, on CIFAR10, the fused and finetuned model achieved 93.67% accuracy, outperforming other initializations.
  • Effective heterogeneous model transfer: CLAFusion significantly boosted performance in heterogeneous model transfer tasks, showing substantial accuracy gains (e.g., 42.97% on CIFAR10) compared to methods without CLA.
  • Successful teacher-student fusion: In teacher-student settings (e.g., VGG models), the fused model yielded better performance than retraining the student model alone.
  • Efficient knowledge distillation initialization: Using the CLAFusion-generated fused model as an initialization for knowledge distillation resulted in the best performance among various initialization strategies.
  • Computational efficiency: CLAFusion produces a compact fused model, significantly reducing memory and inference time compared to ensemble learning, especially as the number of fused models increases.

Limitations and Future Work

  • Architecture constraints: CLAFusion currently assumes networks belong to the same architecture family (e.g., all ResNets or all VGGs). It does not generalize to complex architectures like LSTMs or Transformers due to the difficulty in combining weights of different component types.
  • Bias and batch normalization: While the authors mention these can be handled, they were not explicitly considered in the experiments.
  • Fine-tuning required: Similar to other model fusion methods, an additional finetuning step is necessary after fusion to achieve optimal performance.
  • Merging layers in CNNs: The current merging layer technique is not directly applicable to convolutional layers.
  • Multi-network fusion formulation: Extending CLA to multiple networks is formulated as a multi-index assignment problem, which is an interesting direction for future work.
  • Choice of initial fused model (MF) for multi-network fusion: The paper notes that the choice of the initial fused model (MF) for multi-network fusion is unclear in prior work and suggests using the network with the most layers as an initialization.

Summary updated

BibTeX
@inproceedings{nguyen2023cross,
  author = {Dang Nguyen and Trang Nguyen and Khai Nguyen and Dinh Q. Phung and Hung Hai Bui and Nhat Ho},
  title = {{On Cross-Layer Alignment for Model Fusion of Heterogeneous Neural Networks}},
  booktitle = {IEEE International Conference on Acoustics, Speech and Signal Processing},
  year = {2023},
  doi = {10.1109/icassp49357.2023.10097156},
}
Figure