Sharif University's CAAP Pinpoints What Vision Transformers Actually See
A new attribution method for Vision Transformers intervenes directly on internal activations instead of masking pixels, producing sharper and more faithful saliency maps.
ProTakeaways
- CAAP scores ViT patches by copying their internal activations into a blank image's forward pass and reading the resulting class score.
- Method intervenes on intermediate layers (up to two-thirds of depth) to capture object grouping before background mixing.
- Beats gradient, attention, and perturbation baselines on Deletion, Insertion, AUPR, and Pointing-Game metrics.
- Tested on ViT-L/16, CLIP-L/14, DINOv2-L/14, DeiT3-L/16 plus small/base/huge/giant variants.
- Parallel CLS token trick computes all patch attributions in a single forward pass without approximation.
- No public code release; results on CNNs are weaker, suggesting the method fits transformer architectures best.
Explaining what a Vision Transformer actually looks at is harder than it sounds. The classic playbook of gradient maps, attention rollouts, and pixel perturbations tends to produce heatmaps that are either smeared across the background or oddly focused on a handful of pixels that don't quite match what the model is doing internally. A group from Sharif University of Technology is proposing a different approach: instead of poking at the input image, poke at the network's hidden states directly.
Their method, called Causal Attribution via Activation Patching (CAAP), borrows a technique from mechanistic interpretability research on language models and applies it to patch-level attribution in ViTs. Across multiple ViT backbones and standard metrics, CAAP consistently outperforms existing methods in various settings and produces more faithful and localized attributions.
Why existing attribution maps miss the point
The core issue is that a patch's importance in a ViT isn't determined by its raw pixels. It's determined by the contextualized representation that patch develops after several rounds of self-attention with its neighbors. That mismatch breaks most existing attribution families in different ways:
- Gradient-based methods (Grad-CAM, Integrated Gradients, LibraGrad) measure local sensitivity but don't test whether a patch representation is actually sufficient to support the prediction.
- Attention-based methods (Rollout, Transformer Attribution, TAM) use attention weights as proxies for importance, but attention weights or attention flow are indirect proxies for feature contribution, especially after information from different tokens has been repeatedly mixed across layers.
- Perturbation methods (RISE, ViT-CX, MDA) modify inputs and watch outputs, but input-based deletion does not account for redundancy across patches: when multiple patches encode similar class evidence, removing each patch from a group of redundant patches may cause little change in the output, leading to underestimation of the group's importance.
Insertion-style tests have the opposite problem: dropping a single patch onto a blank canvas produces an out-of-distribution image and severs the interactions with neighboring patches that gave the representation its meaning in the first place.
The activation-patching trick
CAAP sidesteps the input entirely. For each patch you want to score, the method runs two forward passes: one on the real image and one on a blank white image acting as a neutral target. Then it copies the source image's hidden activations for that patch (and a small neighborhood around it) into the corresponding positions of the blank image's forward pass, over a range of intermediate layers. The blank pass then completes, and the resulting class score is the attribution for that patch.

The intuition is that the patched activations already encode all the cross-patch interactions the model built up. You're asking a direct causal question: does this contextualized patch representation, dropped into an otherwise empty context, carry enough evidence to trigger the target class? A high resulting logit means yes.
Why the middle layers matter
The choice of which layers to patch turns out to be critical, and it's where the paper's clearest mechanistic insight sits. ViTs build patch representations through repeated self-attention, causing each patch token to encode information aggregated from other patches. Early layers group intra-object features together; later layers mix in background and unrelated context, which blurs spatial specificity.
The authors measure this directly by tracking how much attention each patch pays to other patches of the same object versus outside it. In early layers, intra-object attention increases and dominates, indicating strong object-level grouping. Around the middle layers, this gap reaches its peak. In later layers, intra-object attention decreases while object-to-background attention increases, reflecting growing extra-object contextualization and reduced spatial specificity.
Based on this, CAAP patches from layer 1 up to roughly two-thirds of the network's depth. That's late enough for class-relevant features to have crystallized, but early enough to avoid the global mixing that would smear the attribution across background regions.
The numbers
The team evaluated on ImageNet-1K using four ViT-L backbones (ViT-L/16, CLIP-L/14, DINOv2-L/14, DeiT3-L/16) plus base, small, huge, and giant variants, and additionally on ImageNet-Hard, Oxford-IIIT-Pet, and Food-101. On the standard Insertion minus Deletion faithfulness score, CAAP posts substantial gains, for example jumping from Libra IxG+'s 30.97 to 41.52 on CLIP-L/14, and from 28.51 to 36.98 on DINOv2-L/14. Localization metrics tell a similar story: on CLIP-L/14, Pointing-Game accuracy climbs from around 56% for the best baseline to 74%.

The multi-object visualizations are particularly interesting. Given an image with several animals, CAAP can generate a different attribution map for each queried class, cleanly isolating the dog when asked about dogs and the horse when asked about horses. Diffuse baselines often light up multiple animals at once regardless of the target class.
Making it tractable
A naive implementation would require N forward passes per image, one per patch. The authors get around this with two tricks:
- Parallel CLS tokens. Because the intervention only affects internal activations, all patch scores can be computed in a single forward pass by introducing one dedicated CLS token per patch, each with an attention mask that routes it to the right combination of source and blank activations. This parallel construction of CLS tokens yields the same attribution map (no approximation) while computing all patch scores in parallel.
- Blank-context precomputation. Since the blank image's key and value projections are fixed, their attention contribution can be cached and reused. This drops the theoretical complexity from roughly O(N³) to O(N).
Caveats and what's missing
Two limitations are worth flagging. First, the patched forward pass isn't a natural distribution of activations, and while ViTs seem robust to this, it's an assumption that could bite in other architectures. The paper's own experiments on ResNet and DenseNet show noticeably weaker results, suggesting activation patching pairs better with transformer-style residual streams. Second, the paper does not link to a public code release, so anyone wanting to try CAAP will have to reimplement Algorithm 1 from the description.
Beyond debugging classifiers, the interesting direction the authors flag is extension to multimodal decoders and generative models, where mechanistic interpretability tools like activation patching are already mature but spatial attribution has lagged behind. If that transfer works, the same intervention-based framing could give clean patch-level explanations for models like CLIP or DINOv2 in downstream visual reasoning tasks.