Unifying and Merging Well-trained Deep Neural Networks for Inference Stage

Yi-Min Chou, Yi-Ming Chan, Jia-Hong Lee, Chih-Yi Chiu, Chu-Song Chen

TL;DR

Researchers have developed NeuralMerger, a novel framework that merges multiple pre-trained deep neural networks into a single, compact model for efficient multi-task inference. By decomposing different kernel architectures into a shared "codebook" of weights, the method achieves up to 20x compression and significant speedups on CPUs with negligible loss in accuracy.

What Problem Does This Paper Address?

In modern AI, we often need to handle multiple tasks simultaneously—like recognizing a person's gender while also identifying their clothing. The standard approach is either to run multiple independent models (which is computationally expensive for edge devices) or to train a massive "multi-task" model from scratch (which is a design nightmare and requires enormous training data).

The authors identify a middle ground: model merging. Most well-trained networks contain significant redundancy. If we can identify and share the "representative" weights across different models, we can create a unified architecture that is much smaller and faster than the sum of its parts, without the headache of designing a new architecture from the ground up.

Methods

The NeuralMerger approach consists of two primary phases: Alignment & Encoding and Fine-tuning.

  1. Alignment and Kernel Decomposition: To merge models with different architectures (e.g., one using $3\times3$ filters and another using $5\times5$), the authors decompose all convolutions into a series of $1\times1$ convolutions combined with shift operators. This unifies the spatial dimensions. To handle varying channel depths, they further segment these $1\times1$ kernels into smaller vectors of a fixed length ($r$).
  2. Joint Encoding (Weight Sharing): Once the weights are in a consistent format, the algorithm uses $k$-means clustering to find a small set of "exemplar codewords." Instead of storing every unique weight, the merged model stores a shared codebook. Each original filter is then represented by an index pointing to this codebook.
  3. Inference via Lookup Tables: At runtime, the model pre-computes the results for the codebook and uses a lookup table to generate outputs, significantly speeding up the process.
  4. End-to-End Fine-tuning: Because the encoding process is differentiable, the authors can fine-tune the shared codebook using a combination of standard classification loss and "knowledge distillation," ensuring the merged model behaves like the original experts.
Figure 1: Two tasks accomplished by feed-forward networks, where model A (or B) consists of cA (or cB) convolution and fA (or fB) fully-connected layers, respectively. Our NeuralMerger unifies the two models into a single one consisting of max(cA, cB) convolution and max(fA, fB) fully-connected layers for the model inference; E-Conv and E-FC are referred to as the Jointly-Encoded convolution and fully-connected layers, respectively.

Datasets

The authors evaluated their method across several heterogeneous tasks:

  • Sound20: A dataset of 20 sound classes (animals and instruments) converted into 2D spectrograms.
  • Fashion-MNIST: 60,000 images of clothing items across 10 categories.
  • Adience Dataset: Face images used for gender recognition.
  • Multi-View-Clothing (MVC): A dataset for identifying clothing attributes.

Key Insights and Ideas

  • Inter-Model Redundancy: The most striking finding is that different models—even those trained on completely different data types like sound and images—share redundant weight patterns. NeuralMerger exploits this "inter-model" redundancy to achieve higher compression than compressing models individually.
  • Architecture Agnostic Merging: By breaking kernels down into $1\times1$ segments, the researchers bypassed the rigid constraints of network topology. As shown in Figure 2, they successfully merged three very different models (ZF-Net, VGG-avg, and LeNet) into one.
  • Performance Recovery: The fine-tuning phase is crucial. By using "dark knowledge" (the soft outputs of the original models), the merged model can often match or even slightly exceed the accuracy of the original standalone networks.
Figure 3: Illustration of merging two models’ Conv layers having the kernels of spatial size 3×3 and 2×2, respectively; each layer is divided into 2 segments. They are decomposed into spatially 1 × 1 kernels and the kernels in every segment is clustered via k-means clustering to build a coodbook. The convolutions are pre-computed on the codebook, and a lookup table is built to index the results.

Key Results

The experimental results demonstrate that NeuralMerger is highly effective for resource-limited environments:

  • Compression: For a merged Sound and Image model, they achieved a 10.4x to 15.3x compression ratio. When merging larger models like VGG-avg and ZF-Net, compression reached over 20x.
  • Speedup: Inference speed on a standard Intel Xeon CPU increased by 1.3x to 2.8x.
  • Accuracy: The accuracy drop was minimal, typically less than 1%. In the Sound20 task, the merged model actually performed 0.06% better than the original, suggesting that the joint training acted as a form of regularization.

Limitations and Future Work

While powerful, the current iteration of NeuralMerger has a few constraints:

  • Feed-Forward Only: The study focuses exclusively on feed-forward networks (CNNs). Merging architectures with loops (like RNNs or LSTMs) remains a challenge for future research.
  • Layer Type Matching: The method currently requires merging layers of the same type (Conv to Conv, FC to FC).
  • CPU Optimization: While the lookup table approach is great for CPUs, the authors note that further work is needed to optimize these specific operations for GPU architectures.

In conclusion, NeuralMerger offers a practical path for deploying sophisticated multi-task AI on low-end systems, proving that we don't always need bigger models—sometimes, we just need to share the load.

Summary updated

Abstract

We propose a novel method to merge convolutional neural-nets for the inference stage. Given two well-trained networks that may have different architectures that handle different tasks, our method aligns the layers of the original networks and merges them into a unified model by sharing the representative codes of weights. The shared weights are further re-trained to fine-tune the performance of the merged model. The proposed method effectively produces a compact model that may run original tasks simultaneously on resource-limited devices. As it preserves the general architectures and leverages the co-used weights of well-trained networks, a substantial training overhead can be reduced to shorten the system development time. Experimental results demonstrate a satisfactory performance and validate the effectiveness of the method.
BibTeX
@inproceedings{chou2018unifying,
  author = {Yi-Min Chou and Yi-Ming Chan and Jia-Hong Lee and Chih-Yi Chiu and Chu-Song Chen},
  title = {{Unifying and Merging Well-trained Deep Neural Networks for Inference Stage}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2018},
  doi = {10.24963/ijcai.2018/283},
}
Figure