Routing or Content? Decomposing How Adversarial Patches Break Vision Transformers

A vision transformer (ViT) splits an image into a grid of patches, turns each patch into a token, and repeatedly mixes tokens through self-attention. Self-attention is a learned weighting: each token decides how much to "listen" to every other token, then averages their content vectors. Adversarial patches, which are small optimized perturbations confined to one grid cell, are unusually damaging to these models. Patch-Fool drives DeiT-S to 6.25% robust accuracy on ImageNet with a single perturbed patch, while a ResNet-50 keeps 24.00%. The usual explanation is attention hijacking: the patch makes every other token listen to it. Yet a perturbed patch changes two things at once. It changes who listens to whom (the attention weights, or routing), and it changes what the corrupted token says (its content vector, which can carry the brittle, human-invisible "non-robust" features that standard training learns to rely on). Every existing attention-centric defense assumes the first channel is what matters. These defenses include softmax temperature smoothing, attention clipping, and attention-alignment losses. Nobody has measured whether that assumption holds.

We propose to measure it. The method uses counterfactual forward passes: the model runs on the clean image but receives only the adversarial routing, or only the adversarial content, at chosen layers. This tells us how much of an attack's damage travels through each channel. We pair this with an attention-budget attack, a fully adaptive attack forced to keep the patch's attention share within the range seen on clean images. The outcome decides what a cheap test-time defense should target. If routing is a true bottleneck, a defense that clips anomalous attention only when it occurs should buy robustness at almost no clean-accuracy cost, and that robustness should survive adaptive attacks. If routing is not a bottleneck, the attention-centric family of defenses is fundamentally limited, and the field should look at content-side interventions instead.

Core Claim

Consider one attention layer. Let $a_{ij}(x)$ be the weight token $i$ places on token $j$ for input $x$, and let $v_j(x)$ be token $j$'s content vector. The layer output for token $i$ is $h_i(x)=\sum_j a_{ij}(x)\,v_j(x)$. For an adversarial input $x'$, the change splits exactly into three terms:

$$ h_i(x')-h_i(x)=\underbrace{\sum_j \big(a_{ij}(x')-a_{ij}(x)\big)v_j(x)}_{\text{routing}}+\underbrace{\sum_j a_{ij}(x)\big(v_j(x')-v_j(x)\big)}_{\text{content}}+\underbrace{\sum_j \Delta a_{ij}\,\Delta v_j}_{\text{interaction}} $$

Here $\Delta$ denotes the adversarial-minus-clean difference.

Our claim is that this split can be turned into a measurement that runs through the whole network. Take a clean image and patch in the adversarial attention maps alone, or the adversarial content vectors alone, at a layer $L$ and all layers above it. Then record what fraction of the attack's classification loss each substitution reproduces. Our main hypothesis is the following. For single-patch attacks at the intermediate layers that Patch-Fool targets (layer 5 by default), routing carries most of the damage. In contrast, ordinary spread-out $\ell_\infty$ attacks act mainly through content.

If this holds, it explains a puzzle in the literature. Are Vision Transformers Robust to Patch Perturbations? found that ViTs shrug off random patchy corruption, with a 1.8% fooling rate, yet fall to optimized patches, with a 61.5% fooling rate. Routing damage requires a token to win the attention competition, which random noise almost never does. The hypothesis also predicts that a defense acting only on routing should cost little clean accuracy, because clean images rarely produce extreme attention concentration.

Research Program

Stage 1: decomposition. We will build the counterfactual-substitution tool for DeiT-S and ViT-B on ImageNet. We will apply it to four attacks:

For each, we will report the fraction of damage carried by routing, content, and interaction, layer by layer. Damage is measured as the share of adversarial loss reproduced and the share of label flips reproduced.

Stage 2: the link to non-robust features. The second stage tests whether the content channel is where the non-robust features live. Distilling Robust and Non-Robust Features in Adversarial Examples by Information Bottleneck separated CNN features into robust and non-robust parts with an information bottleneck. It showed that the non-robust part carries target-class semantics. We will not reuse that machinery. Instead, we will ask a cheaper question: does a content-only substitution, on its own, push a linear probe toward the attack's target class?

Stage 3: fragility of each channel. The third stage probes fragility. APBench shows that low-magnitude shortcut perturbations dissolve under JPEG compression and blurring. We will apply those same transforms to adversarial patches and re-run the decomposition, to see which channel's damage survives. Our hypothesis is that routing damage is more resistant to blurring than content damage, because winning the attention competition depends on coarse token statistics. This hypothesis can fail.

Stage 4: the defense and the bottleneck test. The final stage builds the defense the decomposition calls for and tries hard to break it. If routing dominates, the defense is conditional attention capping. We first record, on clean training images, a high quantile of the total attention each token receives at each layer. At test time, whenever a token's received attention exceeds that quantile, we clip it back down and renormalize. Nothing else changes, and the model receives no retraining.

The bottleneck test is the attention-budget attack: Patch-Fool with an added penalty, or a hard projection, that keeps the patch token's received attention below the clean quantile. We will plot attack success against the attention budget. A steep collapse means routing is necessary for the attack, which makes the defense principled. A flat curve means attackers can route around attention limits, for example by encoding the attack in content that is then propagated through normal attention weights. That flat curve would be a negative result for the whole attention-centric defense line, and we would report it as such.

Baselines

The naive reference is the undefended DeiT-S or ViT-B under each attack. For Patch-Fool single-patch attacks, the reported figure is 6.25% robust accuracy for DeiT-S on ImageNet (Patch-Fool). For a single adversarial patch, the reported fooling rate is 61.5% on DeiT-small (Are Vision Transformers Robust to Patch Perturbations?). We will reproduce both before comparing anything.

The strongest directly comparable competitor is Smoothed Attention. It raises the softmax temperature in every attention layer at inference. It is the closest existing training-free, attention-side defense, and the file reports both its effect and its cost: it reduced DeiT-small's adversarial-patch fooling rate from roughly 60% to 40% with minimal clean-accuracy impact (Are Vision Transformers Robust to Patch Perturbations?).

The second attention-side competitor is the Robust Attention Mechanism from Towards Robust Semantic Segmentation against Patch-based Attack via Attention Refinement. It combines unconditional Max Attention Suppression (capping attention weights) with random attention dropout. We will port it to classification ViTs. In segmentation it reports roughly a 0.15% mIoU clean cost and about a 20% reduction in patch attack success for global-attention models. That low clean cost makes it a serious threat to any argument that conditional capping is needed. The content-side competitor is a PurMM-style intervention, as in PurMM: flag tokens with anomalous attention and zero out their content vectors rather than their attention.

Fairness rules apply to all of these. Every method runs on the same pretrained checkpoints and the same 5,000-image ImageNet validation subset. Each gets the same hyperparameter search budget on a disjoint held-out split: temperature for smoothing, cap level for Max Attention Suppression, threshold quantile for ours. Every defense is then attacked with the same adaptive Patch-Fool variant, which knows the defense and differentiates through it, using equal iteration counts and restarts.

Two ablations isolate the key ingredients. The first applies our cap unconditionally at every layer. If it matches the conditional version, the "only when anomalous" design adds nothing. The second applies the cap only at the layers that Stage 1 identifies as routing-dominated, versus all layers. This tests whether the decomposition actually guides design.

Beating the strongest competitor means two things together. Our method must reach a lower adaptive-attack fooling rate than Smoothed Attention's reported 40% at equal or smaller clean-accuracy loss. It must also sit above both Smoothed Attention and Max Attention Suppression on the clean-accuracy-versus-robust-accuracy curve traced by sweeping each method's single hyperparameter.

Why not just…?

Why not just turn up the softmax temperature everywhere? Smoothed Attention is cheap and works partially, but the reported 40% fooling rate is still above ResNet-50's reported 30.6% (Are Vision Transformers Robust to Patch Perturbations?). Because it flattens attention on every input, it also gives up sharp attention on clean images. Our trade-off curves will show whether conditional capping dominates it. If the curves overlap, we will say so: that would mean the decomposition explains the phenomenon but does not yield a better defense.

Why not just apply Max Attention Suppression unconditionally? This is the most serious threat, because its reported clean cost in segmentation is tiny (RAM). Our unconditional-cap ablation is exactly this comparison. If it matches the conditional version on classification, we will drop the conditional design. The contribution then becomes the decomposition and the attention-budget result, which say why such caps work and whether adaptive attackers can evade them. The RAM paper does not test that evasion question.

Why not just JPEG-compress or blur the input? APBench shows these transforms neutralize shortcut poisons. However, IMPRESS reports that standard processing fails against model-aware perturbations, and indiscriminate filtering costs clean accuracy. Stage 3 runs these transforms directly, both as defenses and as probes of which channel is fragile. If blurring alone matches our defense against adaptive patch attacks, that settles the question against us.

Why not just adversarially train, or use diffusion purification? Patch-Fool reports that adversarial training leaves ViTs more patch-vulnerable than CNNs. TRADES trades clean accuracy for robustness (natural 88.64% versus robust 56.61% on CIFAR-10 at the reported settings). DiffPure requires solving a differential equation for every input. We include an adversarially trained DeiT-S as an upper-cost reference rather than as a like-for-like competitor, and we report wall-clock cost per image for every method.

Proposed Experiments

Decomposition. The core experiment computes the routing, content, and interaction shares across layers for the four attacks on DeiT-S and ViT-B over 5,000 ImageNet validation images. The prediction is that routing carries more than half of the reproduced loss for attention-aware Patch-Fool at intermediate layers, and less than a quarter for dense $\ell_\infty$ attacks. If routing does not dominate even for attention-aware patches, the hijacking narrative is wrong and we pivot the defense to content.

Attention budget. The decisive check is the attention-budget curve: Patch-Fool fooling rate as the cap on the patch token's received attention is tightened from unconstrained down to the clean 99th percentile. A collapse toward the clean error rate supports routing-side defenses. A plateau above roughly 30% would mean attackers can bypass attention limits.

Adaptive evaluation and transfer. The defense evaluation runs the adaptive attack against our conditional cap, its unconditional ablation, Smoothed Attention, ported Max Attention Suppression, and PurMM-style value zeroing, and reports clean accuracy, robust accuracy, and fooling rate. To check that the finding is not specific to classification, we will repeat the decomposition and defense on ADE20K segmentation and compare against RAM's reported clean cost. A secondary check runs the decomposition on Differential Attention ViTs, which Understanding Sensitivity of Differential Attention found to be about twice as attackable on CIFAR-10. The prediction is that their extra fragility shows up in the routing term, which would give that paper's sensitivity result a concrete channel-level explanation.