Vision Transformers are models that cut an image into patches and let every patch "attend to," or weigh information from, every other patch. They can be badly fooled by changing a single patch. The altered patch draws the model's attention toward itself, and the model stops looking at the actual object. The usual fix is adversarial training: repeatedly attack the model during training and teach it to resist those attacks. It is expensive because every attack step runs a full forward and backward pass through the whole network. It also appears not to work well for this threat. Patch-Fool found that adversarially trained ViTs stay more exposed to single-patch attention hijacking than CNNs. The same paper locates the hijacking in early-to-intermediate blocks, with layer 5 of DeiT-S being the most influential.
We propose to exploit that location. Inside the training loop, the attacker would compute one full backward pass, freeze the gradient signal arriving at the output of block $k$, and then run many cheap attack steps that backpropagate only through the first $k$ blocks. The target is attention capture at those blocks plus the frozen downstream signal. This carries the "You Only Propagate Once" idea of YOPO from layer 1 of a CNN to a chosen depth inside a transformer. The claim is narrow and testable. The approach should keep most of the patch robustness of full-depth patch adversarial training at a fraction of the cost. That gain only counts if the robustness survives attacks that see the whole network, not just the truncated piece the defender trained against.
Core Claim
Single-patch attention hijacking does its damage in the first few transformer blocks. If so, the inner attack in adversarial training does not need exact gradients through the deep blocks. A first-order approximation of the deep blocks should be enough, refreshed once per outer step.
Write $h_k(x+\delta)$ for the token representations after block $k$ on the perturbed input. Write $p_k = \partial \mathcal{L}/\partial h_k$ for the gradient of the classification loss with respect to those tokens, computed once by a full pass and then frozen. Write $A_{\le k}(x+\delta)$ for the attention mass that blocks $1..k$ put on the perturbed patch. Each cheap inner step then ascends
$$ J_k(\delta) = \langle p_k,\ h_k(x+\delta)\rangle + \lambda\, A_{\le k}(x+\delta), $$
over a perturbation $\delta$ confined to one patch. Because only $k$ of $L$ blocks are traversed, the cost of $n$ inner steps per full pass is roughly $1 + n k / L$ full-pass equivalents, compared with $n$ for full-depth attacks. For DeiT-S with $L=12$, $k=5$ and $n=10$, that is about 5.2 against 10. The bound comes from counting block traversals and ignores the embedding layer and the classifier head.
The patch's intensity is controlled separately from its direction, following the decoupled direction-and-norm rule of DDN and FMN. The gradient step only chooses which way to push the patch. The budget $\epsilon$ shrinks when the example is already misclassified and grows when it is not. This step needs no model passes and removes the need to tune a budget penalty on top of $\lambda$. It is a supporting ingredient, not the central claim, and the ablations test it as such.
The main risk is specific. A model trained only against truncated attacks might learn to defeat truncated attacks while staying vulnerable to full-depth ones, which is a form of gradient masking. The evaluation is therefore built around full-model adaptive attacks.
Research Program
The first piece of work is a diagnostic that needs no training. For a pretrained and for a standardly adversarially trained DeiT-S, we generate full-depth Patch-Fool attacks. We then measure how well the truncated objective $J_k$ predicts the full loss change, as $k$ varies from 1 to 12. The quantities are the cosine similarity between the truncated and full gradients with respect to the patch, and the attack success rate of truncated-only attacks.
Patch-Fool's layer-5 finding predicts a knee. Fidelity should be poor for $k \le 2$, which is where YOPO's layer-1 freezing would sit, and should saturate somewhere around $k=4$ to $6$. If fidelity only saturates near $k=L$, the central idea is wrong. We would report that and stop.
The second piece is the training algorithm. Each outer step runs one full forward and backward pass to obtain $p_k$ and the weight gradient. It then runs $n$ truncated inner steps on the patch, using the decoupled budget rule. The patch location is chosen as in Patch-Fool from attention scores at block $k$. A single weight update follows on the final adversarial example. We sweep $k$, $n$, and how often $p_k$ is refreshed (every outer step, or every $m$ inner steps as in YOPO's $m \times n$ schedule).
The third piece is the evaluation. It treats the defense as known to the attacker, in the spirit of RobustBench. RobustBench showed that published defenses overstated robustness by more than 10% when tested non-adaptively. Every model is attacked with full-depth Patch-Fool in its single-patch and sparse variants, with more steps and restarts than training used. Models are also attacked with full-depth AutoAttack restricted to the patch, and with A³Attack-style attention-deviation losses. We also run an attack that deliberately targets the deep blocks, the part the defender skipped. It maximizes loss using only the change in block-$k$ outputs that is orthogonal to the frozen $p_k$ direction.
Baselines
The naive reference point is a standardly trained DeiT-S evaluated with Patch-Fool on the 2,500 ImageNet validation images Patch-Fool used. Patch-Fool reports single-patch robust accuracy of 6.25% for DeiT-S against 24.00% for ResNet-50 (Patch-Fool). We reproduce both numbers before anything else.
The strongest competitor on robustness is full-depth patch adversarial training. It is the same procedure with Patch-Fool run through all 12 blocks in the inner loop, at the same $n$. It sets the ceiling for what truncation can retain. The file has no reported robust accuracy for such a model, so we train it ourselves with the same initialization, data, schedule, and outer-step count.
The strongest competitor on cost is compute-matched full-depth adversarial training. It uses as many full-depth inner steps as fit into our method's wall-clock budget, which means roughly half as many steps at $k=5$. Fewer exact steps might simply beat many approximate ones. That is the comparison the method must win.
We also run YOPO's layer-1 freezing applied to the ViT, where $k=1$ freezes the adjoint right after patch embedding. This tests whether depth placement matters at all. On CNNs, YOPO reports 47.98% under PGD-20 on CIFAR-10 for Wide ResNet-34, against 47.04% for slower PGD-10 training (YOPO). We expect the ViT case to be much worse at $k=1$.
The attention-regularized competitor is AAD-style attention preservation trained at full cost (Attention, Please!). No reported result on Lacuna was found for AAD against patch attacks on ViTs.
The parameter-efficient competitor is Robustness Tokens. It reports DINOv2-G recovering from 0.3% to 63.1% under white-box attack with only 200 training steps. That evaluation assumes the tokens stay secret, so we re-evaluate ROB tokens on DeiT-S with the attacker differentiating through known tokens.
Ablations isolate the key ingredients: removing the attention term ($\lambda=0$), replacing the decoupled budget with a fixed $\epsilon$, and freezing $p_k$ for several outer steps. All methods share initialization, data, augmentation, and outer-step count. Each receives the same small hyperparameter search, about eight configurations per method, selected on a held-out validation split.
Beating the field means three things. Robust accuracy under the strongest full-depth adaptive patch attack must be within a few points of full-depth patch adversarial training. It must be clearly above compute-matched adversarial training, outside seed variance over three seeds. Wall-clock training time must be at least 1.7× lower.
Why not just…?
Why not just run fewer full-depth attack steps? This is the most serious threat. Exact gradients from a few steps may be worth more than many approximate ones. The compute-matched baseline addresses it directly at every point of our $k$–$n$ sweep. If it ties or wins, the truncation idea has no value for training, and we report the diagnostic study as the contribution instead.
Why not just use ROB tokens, which cost almost nothing? Their 63.1% recovery on DINOv2-G is measured with tokens the attacker does not know, and the authors describe the tokens as a private key (Robustness Tokens). Defenses that rely on obscurity routinely collapse once the attacker adapts, as shown for masking defenses like DeepCloak and for watermarks (Optimizing Adaptive Attacks against Content Watermarks). Our white-box re-evaluation of ROB tokens settles this. If they hold up against known-token patch attacks, they are the better deal, and we would say so.
Why not just mask high-attention tokens at inference time? Dynamic Attention weakens the most-attended tokens with a randomly sized mask and was evaluated only against black-box text attacks. An attacker who averages gradients over the random mask can spread the hijack across several patches below the masking threshold. We include a top-$m$ attention-masking ViT baseline attacked with expectation over the mask randomness to measure this.
Why not just apply YOPO as published? YOPO itself notes that its savings depend on a simple first layer (YOPO). The $k=1$ arm of our sweep is exactly that transfer. The fidelity diagnostic predicts it will fail because the hijacking happens later in the network.
Decisive Experiments
The main experiment fine-tunes ImageNet-pretrained DeiT-S on ImageNet-1k for a short adversarial schedule. It is evaluated on Patch-Fool's 2,500-image subset with clean accuracy, single-patch and sparse-patch robust accuracy under full-depth adaptive attacks, and GPU-hours. We plot robust accuracy against cost for every $k$, $n$ and baseline.
A second experiment trains a small ViT on CIFAR-10. It is cheap enough to run full-depth patch adversarial training with many steps and three seeds. It also gives a setting next to YOPO's published CNN numbers.
The check that decides the matter is the gap between truncated-attack and full-depth-attack robust accuracy on our trained models. A large gap means the defense learned to beat its own approximation, and the method fails regardless of its speed.
A secondary check compares where the best $k$ falls with Patch-Fool's layer-5 finding. If the optimal training depth tracks the depth at which attention hijacking concentrates, that supports the mechanism and not just the speedup. If time permits, we transfer the best configuration to segmentation on ADE20K. There, ROB tokens report mIoU under attack rising from 4.7 to 23.3 (Robustness Tokens), which tests whether the result extends beyond classification.
References
- Patch-Fool: Are Vision Transformers Always Robust Against Adversarial Perturbations?
- You Only Propagate Once: Accelerating Adversarial Training via Maximal Principle
- Decoupling Direction and Norm for Efficient Gradient-Based L2 Adversarial Attacks and Defenses
- Fast Minimum-norm Adversarial Attacks through Adaptive Norm Constraints
- RobustBench: a standardized adversarial robustness benchmark
- Attention, Please! Adversarial Defense via Activation Rectification and Preservation
- Robustness Tokens: Towards Adversarial Robustness of Transformers
- DeepCloak: Masking Deep Neural Network Models for Robustness Against Adversarial Samples
- Optimizing Adaptive Attacks against Content Watermarks for Language Models
- Improving the Robustness of Transformer-based Large Language Models with Dynamic Attention