How Not to Stitch Representations to Measure Similarity: Task Loss Matching Versus Direct Matching

András Balogh, Márk Jelasity

Abstract

Model stitching is a widely used technique for measuring functional similarity between neural network representations. However, the standard approach of Task Loss Matching (TLM)—optimizing a stitching layer for end-task performance—often yields counter-intuitive results. In this work, we demonstrate that TLM-trained stitchers "cheat" by generating out-of-distribution (OOD) representations that exploit the receiving network's weights to maintain high accuracy, regardless of true representational similarity. We propose Direct Matching (DM), which minimizes the distance between representations, as a more robust alternative. Our results show that DM significantly outperforms TLM in identifying corresponding layers across different architectures and training runs while maintaining in-distribution activations.

Introduction

Measuring the similarity between the internal representations of neural networks is a cornerstone of AI interpretability. If two models perform the same task, do they represent the world in the same way? A popular method to answer this is model stitching: taking the first half of Model A, the second half of Model B, and training a "stitching layer" to connect them. If the hybrid model maintains high performance, the representations are considered functionally similar.

Historically, the "gold standard" for functional similarity has been Task Loss Matching (TLM), where the stitcher is trained to minimize classification error. However, TLM often produces anomalies, such as suggesting that early layers are more similar to late layers than the late layers are to themselves. This paper investigates the failure modes of TLM and proposes Direct Matching (DM) as a superior alternative.

The Hidden Pitfalls of Task Loss Matching

The core issue with TLM is its tendency to produce "alien" representations. By optimizing solely for task loss, the stitching layer can transform activations into forms that are highly out-of-distribution (OOD) for the target network but still trigger correct classifications. This "adversarial-like" behavior allows TLM to report high similarity even between layers that are structurally and semantically distinct.

Figure 2: Analysis of TLM failure. (a) High functional similarity scores across distant layers. (b) High OOD separability (AUROC ~1.0) for stitched representations. (c) Energy distribution shift showing stitched data is OOD.

As shown in the figure above, even when TLM achieves high functional similarity (a), the resulting representations are almost perfectly distinguishable from real activations (b). The energy-based OOD detection (c) confirms that TLM "hacks" the second half of the network rather than finding true representational alignment.

Proposed Solution: Direct Matching

To address these pitfalls, the authors propose Direct Matching (DM). Unlike TLM, DM optimizes the stitching layer to minimize the distance (Frobenius norm) between the transformed source representation and the target representation. This ensures that the transformed data stays "in-distribution" while still providing a functional benchmark. DM acts as a hybrid metric that respects both the geometry and the utility of the network's internal states.

Experimental Results

The authors evaluated these methods using standard benchmarks (CIFAR-10, SVHN, ImageNet) across ResNet-18 and ViT-Ti architectures. They employed a rigorous statistical framework to test for Sensitivity (detecting information removal) and Specificity (identifying corresponding layers).

Figure 5: Comparison of TLM and DM heatmaps. DM (right columns) shows much cleaner diagonal alignment, indicating superior layer correspondence compared to the noisy TLM heatmaps (left columns).

Key Findings:

  • Layer Identification: In intra-network tests, DM achieved 100% accuracy in identifying corresponding layers, while TLM's performance plummeted to 24.17% on Vision Transformers (ViTs).
  • Inter-network Correspondence: When identifying layers across different models trained on the same task, DM reached 92.5% accuracy, vastly outperforming TLM’s 35.28%.
  • OOD Robustness: The AUROC for detecting TLM-stitched representations was frequently 1.0 (perfect separation), meaning they were completely unnatural. For DM, the AUROC stayed near 0.5, meaning stitched representations were indistinguishable from real ones.

Conclusion

The study concludes that Task Loss Matching is an unreliable metric for representational similarity because it creates out-of-distribution representations that "cheat" the receiving network. Direct Matching offers a more principled approach, providing a functional similarity measure that remains grounded in the actual distribution of the network's internal states. This shift from task-based optimization to representation-based alignment is essential for accurate model comparison and interpretability.

Summary updated

BibTeX
@inproceedings{balogh2025how,
  author = {András Balogh and Márk Jelasity},
  title = {{How Not to Stitch Representations to Measure Similarity: Task Loss Matching Versus Direct Matching}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i15.33698},
}
Figure