Stitchable Neural Networks

Zizheng Pan, Jianfei Cai, Bohan Zhuang

Abstract

Modern deep learning deployment is often hindered by the rigidity of pretrained models, which are typically optimized for specific resource constraints. We present Stitchable Neural Networks (SN-Net), a novel framework that transforms a family of off-the-shelf pretrained models into a single, elastic network. By employing simple $1 \times 1$ convolution layers to "stitch" together different model components, SN-Net enables fine-grained, runtime accuracy-efficiency trade-offs. Our approach outperforms hundreds of individual models in the Timm zoo while requiring significantly less training overhead than traditional Neural Architecture Search (NAS).

1. Introduction

The deep learning community currently faces a "paradox of choice." Public repositories like HuggingFace and Timm host thousands of high-performance pretrained models. However, these models are discrete and inflexible; a "Base" model cannot be dynamically scaled down to a "Tiny" version to accommodate fluctuating hardware constraints, such as a mobile device's battery-saving mode.

Existing approaches to this problem have notable limitations. Network compression techniques like pruning or distillation typically produce a single, static smaller model. Conversely, one-shot Neural Architecture Search (NAS) involves training a "supernet" from scratch—a process that is computationally expensive (often exceeding 1,000 GPU hours) and ignores the vast wealth of existing pretrained weights. SN-Net addresses these issues by introducing a "many-to-many" paradigm that leverages existing model families to handle diverse deployment scenarios efficiently.

2. The SN-Net Framework

2.1 Anchors and Stitching Layers

SN-Net utilizes a family of pretrained models, termed "anchors" (e.g., DeiT-Tiny, Small, and Base). To bridge these anchors, the framework inserts simple $1 \times 1$ convolutional layers that map activations from one anchor's layer to another. This allows the network to transition between different model scales mid-inference. For instance, a path might utilize the first four blocks of a "Tiny" model and then stitch into the remaining blocks of a "Small" model.

2.2 Design Principles

The authors identified several key strategies for effective stitching:

  • Fast-to-Slow Direction: Stitching from a smaller (faster) model’s early layers into a larger (slower) model’s later layers is more stable. This aligns with standard design principles where representation capacity increases as the network deepens.
  • Least-Squares Initialization: Rather than random initialization, the framework uses a small set of images (approximately 100) to solve a least-squares problem. This finds an initial transformation matrix that minimizes the feature map discrepancy between anchors, providing a strong starting point for training.
  • Joint Training: After initialization, a brief joint training phase (e.g., 50 epochs on ImageNet) is conducted. During this phase, different "stitches" (paths through the anchors) are randomly sampled, and knowledge distillation is used to fine-tune both the stitching layers and the anchors.

3. Experimental Results

3.1 Performance and Coverage

Evaluated on ImageNet-1K, SN-Net achieves performance parity with, or superiority over, individually trained models. For example, a stitched configuration with 11.2G FLOPs achieved 81.5% Top-1 accuracy—a metric that many individually trained models of similar size fail to reach. Furthermore, a single Swin-based SN-Net can effectively cover the performance and complexity gap of nearly 200 individual models found in the Timm zoo.

3.2 Efficiency and Versatility

One of the most significant advantages of SN-Net is its training efficiency. Training an SN-Net requires roughly 110 GPU hours, which is approximately a 22x reduction in cost compared to training a similar number of individual models from scratch, and a fraction of the 1,200+ hours required for state-of-the-art NAS frameworks like Once-for-All (OFA).

SN-Net is also architecture-agnostic. The methodology has been successfully applied to plain Vision Transformers (DeiT), hierarchical Transformers (Swin), and standard CNNs (ResNet). Remarkably, the framework can even stitch across different architectures, such as connecting a ResNet backbone to a Swin Transformer block.

4. Discussion and Limitations

The core intuition behind SN-Net is that models within the same family, even when trained separately, reach minima in the loss landscape that can be connected with minimal performance loss. By using multiple pretrained models as a foundation, SN-Net inherits rich knowledge that NAS-based supernets must learn from scratch.

However, some limitations remain:

  • Domain Consistency: Anchors should ideally be pretrained on the same domain. Stitching models across vastly different domains (e.g., ImageNet vs. COCO) is challenging due to the representation gap.
  • Sampling Strategy: While random sampling of stitches is effective, more intelligent sampling strategies could potentially yield even better performance.
  • Task Generalization: While highly effective for classification, further research is required to determine how well these stitched representations generalize to downstream tasks like object detection or semantic segmentation.

5. Conclusion

Stitchable Neural Networks provide a practical and efficient solution to the rigidity of modern deep learning models. By enabling the interpolation between existing pretrained anchors, SN-Net offers a versatile, "one-size-fits-all" model that can adapt to a wide range of resource constraints at runtime without the prohibitive costs of traditional supernet training.

Summary updated

BibTeX
@inproceedings{pan2023stitchable,
  author = {Zizheng Pan and Jianfei Cai and Bohan Zhuang},
  title = {{Stitchable Neural Networks}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2023},
}
Figure