Deep Model Reassembly

Xingyi Yang, Daquan Zhou, Songhua Liu, Jingwen Ye, Xinchao Wang

In the world of deep learning, we are currently living in an era of abundance. Between Hugging Face and various model hubs, there are thousands of pre-trained models available at our fingertips. Usually, we pick one "best" model and fine-tune it. But what if we could treat these models like a box of Legos—taking a block from a ResNet, a stage from a Vision Transformer (ViT), and a piece of an MLP-Mixer to build a customized "Franken-model" that perfectly fits our hardware constraints?

This is the core idea behind Deep Model Reassembly (DeRy).

TL;DR

DeRy is a framework that dissects a "zoo" of heterogeneous pre-trained models (CNNs, Transformers, etc.) into functional building blocks and reassembles them into new, optimized architectures. By identifying "equivalence sets" of interchangeable blocks and using a training-free performance proxy, DeRy can create customized models that often outperform their original "parent" models while strictly adhering to hardware constraints.

What Problem Does This Paper Address?

Standard transfer learning is often a "winner-takes-all" game: you pick one pre-trained model and discard the rest. While model ensembling or distillation can leverage multiple models, these methods are computationally expensive at inference time or limited to models with identical architectures.

Comparison of DeRy with existing transfer learning paradigms.

The challenge is that internal representations of different models (e.g., a ResNet vs. a Swin Transformer) are fundamentally different. You cannot simply "plug and play" a Transformer block into a CNN because the feature dimensions and mathematical properties do not match. DeRy tackles this "universal connectivity" problem, aiming to reuse the vast knowledge stored in diverse model zoos without the massive cost of training new architectures from scratch. It uniquely supports heterogeneous architectures and utilizes all models without requiring additional computation at inference.

Methods

The authors propose a two-stage pipeline to turn a model zoo into a modular toolkit:

The DeRy pipeline: Network Partitioning into Equivalence Sets followed by Network Reassembly.
  1. Network Partitioning (Finding the Legos): The framework first breaks down every model in the zoo into disjoint blocks. To make these blocks interchangeable, DeRy solves a "cover set optimization" problem. It uses Centered Kernel Alignment (CKA) to measure the functional similarity between blocks from different models. Blocks that perform similar transformations are grouped into Equivalence Sets. Within these sets, blocks are treated as functionally swappable.

  2. Network Reassembly (Building the Model): Once the equivalence sets are defined, the user specifies constraints (e.g., "I need a model with under 20M parameters and 4 GFLOPs"). DeRy then searches for the optimal combination of blocks—one from each stage—to maximize performance.

  3. The "Stitch" Layer: To handle dimension mismatches between heterogeneous blocks (like a CNN block feeding into a Transformer block), DeRy inserts a lightweight $1 \times 1$ convolution "stitch" layer.

  4. Training-Free Proxy: Instead of training every candidate model (which would take years), DeRy uses a proxy called NASWOT. It counts the "linear regions" in the feature space to estimate a model's potential performance in seconds.

Datasets

The authors evaluated DeRy using a diverse Model Zoo of 21 architectures (30 total pre-trained weights), including ResNets, RegNets, ViTs, Swin Transformers, and MobileNetV3.

  • Primary Benchmark: ImageNet-1k.
  • Transfer Learning Benchmarks: 9 diverse datasets including CIFAR-10/100, Caltech-101 (general), Oxford-IIIT Pets, CUB-Bird, Stanford Cars, Flowers-102, FGVC Aircraft (fine-grained), and DTD (texture).

Key Insights and Ideas

  • Functional Equivalence is Real: Surprisingly, blocks from a CNN and a Transformer can be functionally similar enough to be swapped. The authors found that similarity is highest when comparing blocks at the same relative "depth" or stage across different models.
  • The Sum is Greater than the Parts: A reassembled model can actually outperform its predecessors. For example, stitching the first two stages of a ResNet trained on iNaturalist with the last two stages of a ResNet trained on ImageNet resulted in a model better than either original.
  • Efficiency via Proxies: By using the NASWOT score, the authors reduced the search cost by a factor of $10^4$ compared to exhaustive training. This makes reassembling a custom model from a zoo of 30+ candidates practically feasible on a single workstation.

Key Results

  • ImageNet Performance: A reassembled model achieved 78.6% top-1 accuracy with all original blocks frozen (only training the tiny stitch layers). When allowed to fine-tune end-to-end, the accuracy rose to 83.2%, surpassing many of the individual models in the zoo.
  • Hardware Flexibility: DeRy successfully generated models across five different computational tiers (from 10M to 90M parameters), consistently finding "hybrid" architectures (e.g., CNN-Transformer mixes) that optimized the accuracy-to-FLOPs trade-off.
  • Universal Transfer: On downstream tasks like Stanford Cars and FGVC Aircraft, DeRy models outperformed standard "off-the-shelf" models, proving that the reassembly process preserves and even enhances transferable knowledge.

Limitations and Future Work

  • Manual "Atomic Nodes": Currently, the authors have to manually define the "atomic nodes" (the smallest breakable units) for each architecture to ensure the graph remains valid. Automating this dissection for any arbitrary code-defined model remains an open challenge.
  • Stitch Layer Overhead: While $1 \times 1$ convolutions are cheap, adding many of them between every block adds some latency and parameter overhead that isn't present in "native" architectures.
  • Zoo Dependency: The quality of the reassembled model is strictly bounded by the diversity and quality of the initial Model Zoo. If the zoo only contains poor models, the reassembled result will likely be poor as well.

Future work could involve expanding DeRy to multi-modal models (mixing vision and language blocks) or using it to "heal" compressed models by replacing pruned blocks with equivalent high-performing ones from a zoo.

Summary updated

BibTeX
@inproceedings{yang2022deep,
  author = {Xingyi Yang and Daquan Zhou and Songhua Liu and Jingwen Ye and Xinchao Wang},
  title = {{Deep Model Reassembly}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=liPb17C9Gs},
}
Figure