Inside-Out: Measuring Generalization in Vision Transformers Through Inner Workings
Organizations: University of Delaware · George Mason University
Abstract
Reliable generalization metrics are fundamental to the evaluation of machine learning models. Especially in high-stakes applications where labeled target data are scarce, evaluation of models' generalization performance under distribution shift is a pressing need. We focus on two practical scenarios: (1) Before deployment, how to select the best model for unlabeled target data? (2) After deployment, how to monitor model performance under distribution shift? The central need in both cases is a reliable and label-free proxy metric. Yet existing proxy metrics, such as model confidence or accuracy-on-the-line, are often unreliable as they only assess model output while ignoring the internal mechanisms that produce them. We address this limitation by introducing a new perspective: using the inner workings of a model, i.e., circuits, as a predictive metric of generalization performance. Leveraging circuit discovery, we extract the causal interactions between internal representations as a circuit, from which we derive two metrics tailored to the two practical scenarios. (1) Before deployment, we introduce Dependency Depth Bias, which measures different models' generalization capability on target data. (2) After deployment, we propose Circuit Shift Score, which predicts a model's generalization under different distribution shifts. Across various tasks, both metrics demonstrate significantly improved correlation with generalization performance, outperforming existing proxies by an average of 13.4% and 34.1%, respectively. Our code is available at https://github.com/deep-real/GenCircuit.
Figures & tables
| Method | PACS (Style Shift) | Camelyon17 (Institution Shift) | Terra Incognita (Geographic Shift) | Average | ||||||
| SRCC | KRCC | SRCC | KRCC | SRCC | KRCC | |||||
| ID Accuracy [ 49 ] | 0.765 | 0.878 | 0.720 | 0.423 | 0.650 | 0.480 | 0.537 | 0.711 | 0.528 | 0.632 0.047 |
| Sharpness [ 3 ] | 0.048 | 0.075 | 0.037 | 0.097 | 0.204 | 0.146 | 0.361 | 0.576 | 0.408 | 0.217 0.060 |
| AC [ 29 ] | 0.646 | 0.755 | 0.582 | 0.535 | 0.793 | 0.620 | 0.367 | 0.563 | 0.408 | 0.585 0.044 |
| ANE [ 29 ] | 0.608 | 0.728 | 0.554 | 0.568 | 0.781 | 0.603 | 0.378 | 0.590 | 0.425 | 0.582 0.040 |
| MDE [ 54 ] | 0.345 | 0.650 | 0.478 | 0.347 | 0.717 | 0.502 | 0.371 | 0.726 | 0.541 | 0.520 0.048 |
| Score | |||||
|---|---|---|---|---|---|
| 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | |
| 0.744 | 0.772 | 0.798 | 0.801 | 0.772 | |
| SRCC | 0.743 | 0.843 | 0.862 | 0.849 | 0.838 |
| KRCC | 0.562 | 0.653 | 0.684 | 0.671 | 0.673 |
| Method | PACS (Style Shift) | FMoW (Temporal Shift) | Camelyon17 (Institution Shift) | ImageNet (Adversarial + Style) | Average | ||||||||
| SRCC | KRCC | SRCC | KRCC | SRCC | KRCC | SRCC | KRCC | ||||||
| AC [ 29 ] | 0.031 | 0.117 | 0.111 | 0.314 | 0.700 | 0.556 | 0.035 | 0.058 | 0.055 | 0.928 | 0.943 | 0.839 | 0.391 0.104 |
| ANE [ 29 ] | 0.105 | 0.200 | 0.222 | 0.315 | 0.767 | 0.611 | 0.038 | 0.033 | 0.034 | 0.921 | 0.942 | 0.833 | 0.418 0.102 |
| MDE [ 54 ] | 0.002 | 0.217 | 0.222 | 0.428 | 0.717 | 0.611 | 0.036 | 0.273 | 0.187 | 0.829 | 0.897 | 0.754 | 0.431 0.088 |
| RANKME [ 20 ] | 0.100 | 0.600 | 0.500 | 0.322 | 0.383 | 0.333 | 0.020 | 0.193 | 0.152 | 0.666 | 0.901 | 0.729 | 0.408 0.076 |
| -ReQ [ 2 ] | 0.325 | 0.650 | 0.500 | 0.306 | 0.433 | 0.333 | 0.024 | 0.132 | 0.087 | 0.419 | 0.714 | 0.547 | 0.373 0.060 |
Appendix figures & tables17 assets
Supplementary material from the paper’s appendix.
Appendix
| Dataset | Shift type | Domain |
|---|---|---|
| PACS [ 38 ] | style shift | art_painting cartoon photo sketch |
| Camelyon17 [ 34 ] | institution shift | ID Hospitals hospital1 hospital2 |
| Terra Incognita [ 4 ] | geographic shift | location 38 location 43 location 46 location 100 |
| Dataset | ID domain | OOD domain |
|---|---|---|
| PACS [ 38 ] | Sketch | art_painting subset 1-3 cartoon subset 1-3 photo subset 1-3 |
| Camelyon17 [ 34 ] | hospital 0 slide 0-7 hospital 1 slide 10-17 | hospital 0 slide 8-9 hospital 1 slide 18-19 hospital 2 slide 20-29 hospital 3 slide 30-39 hospital 4 slide 40-49 |
| FMoW [ 34 ] | Official ID split | time 1 region 0-4 time 2 region 0-4 |
| ImageNet [ 12 ] | ImageNet Validation | ImageNet-Sketch ImageNet-v2 motion blur 0-4 defocus blur 0-4 zoom blur 0-4 snow 0-4 frost 0-4 |
| Model | Timm model name |
|---|---|
| random init ViT OPENAI CLIP LAION2b CLIP ImageNet 21k ImageNet 1k MAE | N/A vit_base_patch16_clip_224.openai vit_base_patch16_clip_224.laion2b vit_base_patch16_224_in21k vit_base_patch16_224.orig_in21k_ft_in1k vit_base_patch16_224.mae |
| Learning Rate | Batch Size | Weight Decay | Fine-tune |
|---|---|---|---|
| 3e-2 1e-2 3e-3 | 128 256 | 0 1e-2 | Only head Whole model |
| Learning Rate | Batch Size | Weight Decay | Fine-tune |
|---|---|---|---|
| 3e-2 1e-2 3e-3 | 128 256 | 0 | Only head Whole model |
| Model | Benchmark | ID accuracy | OOD accuracy | OOD-ID Gap |
|---|---|---|---|---|
| random init | PACS | 0.477 0.018 | 0.201 0.010 | 0.276 0.156 |
| Camelyon17 | 0.934 0.009 | 0.686 0.014 | 0.248 0.006 | |
| Terra Incognita | 0.565 0.014 | 0.221 0.011 | 0.344 0.023 | |
| FMoW | 0.547 0.020 | 0.497 0.009 | 0.051 0.003 | |
| ViT-B MAE pretrained | PACS | 0.580 0.017 | 0.242 0.012 | 0.338 0.011 |
| Camelyon17 | 0.912 0.021 | 0.836 0.018 | 0.076 0.005 |
| Method | Color-MNIST | Waterbirds | ImageNet | |
|---|---|---|---|---|
| small-ViT | ViT-B/16 | ViT-B/16 | ViT-B/16 | |
| Random | 0.555 | 0.748 | 0.754 | 0.732 |
| EActP | 0.466 | 0.095 | 0.271 | 0.360 |
| EAP | 0.332 | 0.103 | 0.299 | 0.376 |
| EAP-IG-inp | 0.567 | 0.063 | 0.242 | 0.325 |
| EAP-IG-act | 0.452 | 0.076 | 0.327 | 0.381 |
| Method | Color-MNIST | Waterbirds | ImageNet | |
|---|---|---|---|---|
| small-ViT | ViT-B/16 | ViT-B/16 | ViT-B/16 | |
| Random | 0.263 | 0.274 | 0.260 | 0.299 |
| EActP | 1.679 | 0.732 | 0.698 | 0.804 |
| EAP | 1.658 | 0.712 | 0.570 | 0.655 |
| EAP-IG-inp | 2.033 | 0.902 | 0.706 | 0.813 |
| EAP-IG-act | 1.658 | 0.858 | 0.656 | 0.810 |
| Score | |||||
|---|---|---|---|---|---|
| 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | |
| 0.441 | 0.467 | 0.750 | 0.491 | 0.433 | |
| SRCC | 0.780 | 0.788 | 0.853 | 0.743 | 0.630 |
| KRCC | 0.592 | 0.609 | 0.681 | 0.565 | 0.478 |
| Score | |||||
|---|---|---|---|---|---|
| 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | |
| 0.683 | 0.516 | 0.541 | 0.500 | 0.447 | |
| SRCC | 0.786 | 0.653 | 0.655 | 0.606 | 0.553 |
| KRCC | 0.620 | 0.514 | 0.519 | 0.478 | 0.433 |