Model Stitching: Looking For Functional Similarity Between Representations

Adriano Hernandez, Rumen Dangovski, Peter Y. Lu, Marin Soljacic

TL;DR

Model stitching is a powerful way to compare neural network representations by literally swapping parts between models. This paper extends the technique to different architectures and uncovers a surprising "triangular" similarity pattern: late-stage layers can be successfully stitched into almost any earlier layer, suggesting that these "stitches" might be "hacking" the receiver network rather than measuring true representational similarity.

What Problem Does This Paper Address?

Deep learning’s success is built on "representations"—the intermediate signals neural networks learn to extract from data. However, we lack a robust way to compare these representations across different models. If two models are trained on the same data but have different architectures or random seeds, do they "see" the world the same way?

Existing metrics often rely on statistical or geometric similarity, which can be misleading. A more functional approach is model stitching: taking the first half of Model A (the "sender"), the second half of Model B (the "receiver"), and connecting them with a small, trainable "stitch" layer. If the combined network performs well, we can say the representations are functionally similar.

Previously, this was limited to models with identical layer shapes. This paper aims to break that barrier, allowing researchers to compare representations across entirely different architectures.

Methods

The authors developed a framework to stitch together ResNets of varying depths and widths.

  1. The Stitch: To connect layers with different dimensions, they used strided convolutions for downsampling and nearest-neighbor upsampling (followed by a 1x1 convolution) for upsampling.
  2. Training: They froze the weights of both the sender and receiver networks, training only the thin stitch layer on the original classification task (CIFAR-10).
  3. Controls: To ensure the stitch wasn't simply "learning the task" on its own, they tested stitches against randomly initialized networks. A high-performing stitch between a trained sender and a random receiver would indicate the stitch is "too powerful" and the metric is invalid.
Figure 1: On the left, a diagram exemplifying a stitch from the red (sender) network into the blue (reciever) network comparing layer 3 from both. In this diagram, the blue layer 3 is the expected representation. Unused layers in the stitched network are displayed as partially translucent. The stitch is depicted in green. The arrows denote the flow of computation. The dashed arrows denote the flow of computation in regular operation, absent of stitching. On the right, a diagram exemplifying a 2x2 convolution (downsampling) from left (dotted) to right (solid). A 2x2 convolution such as this one could be used to stitch from a representation with larger width and height to one of smaller dimensions. The colors are chosen so as to elucidate which elements correspond. The blue lines further highlight the correspondence for the blue elements. In the case of upsampling, the image can be read from right (solid) to left (dotted), where the solid blue element is copied four times to the dotted blue elements before it is used (later) for a 1x1 convolution.

Datasets

The study focused on the CIFAR-10 dataset, a standard benchmark for image classification. They trained a family of "Small ResNets" (ranging from 10 to 18 layers) and extrapolated their findings to larger models like ResNet-34.

Key Insights and Ideas

  • The "Triangle" Pattern: The most striking finding was that similarity isn't just a diagonal line (where layer $i$ matches layer $i$). Instead, they found a "lower-left triangle" of high accuracy. This means a late layer in a sender network can be successfully stitched into almost any earlier layer of a receiver network.
  • Functional Asymmetry: While you can easily stitch "backward" (late sender to early receiver), stitching "forward" (early sender to late receiver) rarely works.
  • The Hacking Hypothesis: The authors suggest that the stitch might not be finding a match between representations. Instead, it might be "hacking" the receiver by generating a generic, salient representation—perhaps even an adversarial one—that the receiver's later layers can easily classify, even if it looks nothing like the original data.
  • Information Persistence: Alternatively, this result might challenge the standard narrative that neural networks progressively discard granular information. It’s possible that late layers retain enough raw information to be "re-processed" by an earlier layer in a different model.

Key Results

The authors generated similarity matrices for 256 pairs of ResNets.

  • High Accuracy: In the "triangle" region of the similarity matrix, stitched networks achieved accuracies over 90%, nearly matching the performance of the original standalone models.
  • Scale Invariance: This triangular pattern held true even when stitching very different models, such as a ResNet-18 into a ResNet-34. The success depended on the proportional depth of the layers rather than their absolute numerical index.
  • Similarity vs. Task Training: When they trained stitches to minimize Mean Squared Error (MSE) between representations rather than maximizing classification accuracy, the stitches failed to achieve high task performance. This suggests that task-based stitching finds "functional shortcuts" that pure similarity metrics miss.
Heatmaps showing the 'triangle' similarity pattern. High accuracy (yellow) is visible in the lower-left, indicating late sender layers can stitch into early receiver layers.

Limitations and Future Work

The authors acknowledge that their "hacking hypothesis" is currently a strong intuition that requires more rigorous proof. While they attempted to visualize the "hacked" representations through image generation (Figure 6 in the paper), the results were inconclusive.

Future work could explore:

  • Whether this triangular pattern persists in non-convolutional architectures like Transformers.
  • Developing "constrained" stitches that are less likely to "hack" the receiver.
  • Investigating ResNet length-invariant properties that might explain why proportional depth matters more than absolute depth.

Ultimately, the paper serves as a cautionary tale: model stitching is a powerful tool, but if implemented naively, it may measure a stitch's ability to "cheat" rather than the models' true similarity.

Summary updated

BibTeX
@inproceedings{hernandez2022model,
  author = {Adriano Hernandez and Rumen Dangovski and Peter Y. Lu and Marin Soljacic},
  title = {{Model Stitching: Looking For Functional Similarity Between Representations}},
  booktitle = {SVRHM @ NeurIPS},
  year = {2022},
  url = {https://openreview.net/forum?id=7bHLCO5FQdB},
}
Figure