Where Fast Patch Adversarial Training of Vision Transformers Breaks: Linearity of Attention, Not of the Loss

Adversarial training makes a model robust by training it on deliberately corrupted inputs. The cheap version, which builds each corrupted input with a single gradient step, is known to fail suddenly: partway through training, robust accuracy falls to zero. This failure is called catastrophic overfitting. On convolutional networks it has been traced to the loss surface ceasing to be locally linear, meaning a one-step linear guess no longer predicts how the loss changes. Penalizing that nonlinearity cheaply prevents the collapse (Efficient local linearity regularization to overcome catastrophic overfitting).

Vision Transformers (ViTs) have a sharper weakness. One adversarial image patch can pull the model's attention onto itself and wreck the prediction. In Patch-Fool, DeiT-S robust accuracy drops to 6.25% under a single-patch attack, and standard adversarial training does not close the gap. We propose that these two facts share one mechanism. The softmax that turns attention scores into weights saturates, so the attention a patch receives behaves like a switch: near zero, then suddenly near one. A one-step attack on that switch-like function gives a misleading training signal, and fast patch adversarial training of ViTs should collapse for this reason.

If that is right, the fix should enforce linearity on the attention mass assigned to the perturbed patch, not on the loss. The penalty can be computed with a few extra forward passes, in the style of ELLE.

Core Claim

We make two claims. The first is diagnostic. When ViTs are trained with single-step adversarial patches, catastrophic overfitting occurs, and it is preceded by a rise in the nonlinearity of attention allocation to the patch token. That rise should come measurably earlier and be larger than the rise in loss-level nonlinearity.

The second is a method. Consider an attention-space interpolation penalty, taken over the patch perturbation $\delta$:

$$R_{\text{att}} = \sum_{\ell} \left\| m_\ell(x+\delta_\alpha) - \alpha\, m_\ell(x+\delta_a) - (1-\alpha)\, m_\ell(x+\delta_b) \right\|^2 .$$

Here $\delta_a$ and $\delta_b$ are two random perturbations inside the patch budget, $\delta_\alpha = \alpha\delta_a + (1-\alpha)\delta_b$ with $\alpha$ drawn uniformly, and $m_\ell(\cdot)$ is the column of layer-$\ell$ attention weights that all queries and heads assign to the perturbed patch token. We claim this penalty prevents collapse and yields higher patch robustness than the loss-level ELLE penalty at equal cost.

The penalty is ELLE's interpolation test moved from the scalar loss to the attention column. It stores one $H \times N$ column per layer rather than the full $N \times N$ attention matrices. Here $H$ is the number of attention heads and $N$ the number of tokens. Avoiding the full matrices matters because attention-matching defenses such as TGA-ZSR report roughly 15% extra training cost from computing attention maps.

Prior Work and How This Differs

Work on local linearity supplies the method and the motivation. A Unified Gradient Regularization Family framed adversarial vulnerability through a first-order Taylor view and penalized input-gradient norms. ELLE replaced costly second-order regularizers (GradAlign, CURE) with an interpolation discrepancy that runs 2–3× faster and prevents catastrophic overfitting on CNNs across CIFAR, SVHN and ImageNet. All of this work is convolutional and uses dense perturbations over the whole image. None of it asks which internal component of a transformer carries the nonlinearity.

Three papers motivate looking at curvature in exactly our regime. Understanding Impacts of High-Order Loss Approximations proved that the input Hessian collapses onto the gradient only at high confidence, which is precisely the condition an attack destroys. LP-BFGS showed that in sparse, localized perturbation spaces a quasi-Newton method raises attack success from 18.44% (FGSM) to 47.98% on ResNet-34 with 100 pixels. That is direct evidence that first-order steps mislead when perturbations are localized. Rank-LIME reports that linear surrogates fit transformer decision boundaries poorly.

Work on attention redirection supplies the threat model. Patch-Fool and Are Vision Transformers Robust to Patch Perturbations? (61.5% fooling rate on DeiT-small from one patch) establish attention hijacking. Both optimize first-order and never measure the geometry of the surface they climb. Attacking Attention of Foundation Models shows that attention disruption, more than embedding drift, destroys dense downstream tasks.

The defenses act on the forward pass and do not constrain how attention responds to perturbation:

  • Smoothed Attention uses a softmax temperature above one.
  • RAM caps attention logits and drops attention edges at random.
  • AAD and TGA-ZSR penalize the distance between clean and adversarial attention maps.
  • RVT rescales attention by position.

Our proposal differs from all of them. It regularizes the shape of the function from patch perturbation to attention, rather than its value at one adversarial point. It is aimed at making cheap single-step training work for patch threats on ViTs, a setting the file shows nobody has studied.

Research Program

The first stage is measurement. We train DeiT-Ti and DeiT-S with single-step patch adversarial training. Each step picks the patch location with Patch-Fool's attention-aware selection and builds the perturbation with one signed gradient step inside a dense patch budget. We sweep the step size upward, since collapse on CNNs is step-size dependent.

At every checkpoint we log three quantities on held-out images:

  • loss-level interpolation error, ELLE's quantity;
  • attention-level interpolation error, $R_{\text{att}}$ split by layer;
  • robust accuracy under multi-step patch attack.

We also log how saturated the softmax is: the fraction of queries whose attention to the patch token exceeds 0.5 or falls below 0.01. This tests whether the jump in attention error coincides with saturation. For a small set of images we compute Hessian–vector products restricted to the 768 patch pixels to get the leading eigenvalues. This checks whether the attention-error signal tracks true curvature, using Singla et al.'s gradient–Hessian alignment as the reference measurement.

The second stage is the method. We add $R_{\text{att}}$ to the single-step objective, with an adaptive weight following ELLE-A that raises the coefficient when the measured error spikes. We compare three variants: attention-only, loss-only, and both. We vary which layers are penalized: all layers, or early versus late layers. This tells us whether a few layers carry the switch-like behaviour; Patch-Fool selects patches using layer 5.

The third stage is honest evaluation. Any defense that changes how attention responds to perturbation risks gradient masking, where gradients become uninformative without true robustness. We therefore evaluate with four attacks:

  • Patch-Fool's attention-plus-cross-entropy loss;
  • many-restart patch PGD;
  • the attention-divergence loss of Silva et al. restricted to the patch;
  • a quasi-Newton BFGS patch attack in the style of LP-BFGS, run over the 768 pixel values of the patch, which is small enough for BFGS to be practical.

We also check the masking tell-tales: attack success should rise monotonically with budget and with iteration count, and quasi-Newton and first-order attacks should not disagree sharply. The code builds on the ELLE implementation (LIONS-EPFL/ELLE), which already provides single-step, ELLE, GradAlign and N-FGSM training plus AutoAttack and PGD evaluation scripts. Patch-wise extensions are needed, and easyrobust supplies fast adversarial training utilities for ViT backbones.

Baselines

The naive reference point is an undefended DeiT-S evaluated with Patch-Fool's protocol on the same 2,500-image ImageNet validation subset. Patch-Fool reports 6.25% robust accuracy for DeiT-S under a single-patch attack. We reproduce that number before trusting any comparison. A second naive point is plain single-step patch adversarial training with no regularizer. It shows whether collapse happens at all, and its robust accuracy is the number every regularizer must exceed.

The strongest existing method for preventing collapse is loss-level ELLE-A. It is the most direct competitor because it targets the same failure with the same cheap interpolation trick. The only difference from our method is where linearity is measured, so it isolates our key ingredient. On CNNs, ELLE-A reports 44.32% AutoAttack accuracy on CIFAR-10. We found no reported result on Lacuna for ELLE on ViTs or under patch threats. We run it on the same ViTs, data, patch selection and epochs, and tune its coefficient with the same search budget as ours. Beating it means higher worst-case patch robust accuracy across all four attacks at matched training GPU-hours, with no clean-accuracy deficit beyond one point.

The strongest robustness reference that does not care about cost is multi-step patch PGD adversarial training. Gu et al. and Fu et al. report that adversarially trained ViTs remain weak against patches but give no single comparable figure; Lacuna has no reported result for patch-PGD-trained DeiT-S robust accuracy. We run it with 10 steps both at equal epochs, where it uses about 3–4× our compute, and at equal GPU-hours, where it gets fewer epochs. The claim we make is to match its robustness at a fraction of the cost, not to exceed it.

Architectural defenses are compared as drop-in alternatives and in combination with our method:

  • Smoothed Attention, reported to cut DeiT-small fooling rate from about 60% to 40%.
  • RAM's logit capping. Its target mIoU fell from 40.42% to 14.59% on ADE20K, a segmentation result we do not transfer directly.
  • RVT-S. Its reported FGSM accuracy is 51.3% versus 40.7% for DeiT-S, measured against dense attacks rather than patch attacks.

An attention-preservation loss in the style of AAD and TGA-ZSR is also included. It matches clean and adversarial attention maps at a single point. Comparing it to $R_{\text{att}}$ separates "keep attention the same" from "keep attention linear."

Why not just…?

Why not just apply loss-level ELLE to ViTs and be done? This is the real threat. If loss-level ELLE prevents collapse and matches our robustness, the attention-space version adds nothing. The temporal-precedence measurement and the head-to-head comparison settle it. If attention nonlinearity does not rise before loss nonlinearity, or if loss-level ELLE does as well at equal cost, we report that the ELLE result transfers unchanged to transformers. That is a useful negative result, and we would not push the attention variant.

Why not just train with multi-step PGD patches? It probably works better per epoch, and we expect it to remain the robustness ceiling. Its cost scales with the number of attack steps. The whole point of single-step training is that cost, and the matched-GPU-hour comparison measures whether our method recovers most of the gap.

Why not just smooth the softmax with a temperature or cap the logits? These directly attack the saturation we blame, so they are plausible substitutes. Gu et al., however, report a 40% fooling rate remaining under Smoothed Attention. The RAM authors needed random attention dropout on top of logit capping, and random dropout at inference is a classic source of masked gradients. We test temperature scaling and logit capping alone, combined with single-step training, and combined with $R_{\text{att}}$. If temperature plus single-step training already prevents collapse and survives the quasi-Newton attack, that simpler answer wins and we will say so.

Why not just add random initialization or noise to the single step (N-FGSM)? Noise-based fixes help on CNNs and ship in the ELLE codebase. They are run as baselines under identical settings. Our diagnostic predicts they fail once the softmax saturates, because added noise does not move the switch-like region.

Proposed Experiments and Decisive Checks

The main benchmark is ImageNet with DeiT-Ti and DeiT-S, fine-tuned from public checkpoints with single-step patch training. Evaluation uses the 2,500-image Patch-Fool subset under one and two patches with attention-aware patch selection, plus a worst-of-five check over random locations. CIFAR-10 with a small ViT supports fast step-size sweeps where collapse can be located cheaply. Metrics are clean accuracy, robust accuracy under the worst of the four attacks, training GPU-hours, and the logged linearity and saturation curves. Three seeds are run per configuration, because collapse is sudden.

The first decisive check is whether collapse exists at all in single-step patch training of ViTs. If robust accuracy never collapses across the step-size sweep, the premise is wrong and the proposal reduces to the measurement study. The second is temporal precedence: attention interpolation error should spike at least one evaluation interval before robust accuracy falls, while loss interpolation error lags. The third is the ablation against loss-level ELLE at matched cost. The fourth is that our method's robustness must hold under the quasi-Newton patch attack. A sizeable drop from the first-order to the BFGS attack, in the spirit of LP-BFGS's 18.44% versus 47.98% gap, would indicate masked rather than real robustness.

A secondary check tests whether the result extends beyond classification. We apply the attention-divergence attack of Silva et al. to a patch-trained DINOv2-small backbone and measure ADE20K segmentation. Attention disruption is the main cause of dense-task failure, so stabilizing attention allocation should help there more than on classification.