Adversarial training is the main defense against small, deliberately crafted input perturbations. It is slow because every weight update first has to search for the worst perturbation of each training image, usually with 10 or more extra gradient steps. The cheap fix is to take a single gradient step. For convolutional networks this matches multi-step robustness, but it is fragile: partway through training, robustness can suddenly fall to zero, a failure called catastrophic overfitting. This proposal starts from the reading of self-attention as associative memory, meaning a lookup in which each query token is pulled toward the stored keys it most resembles, like a ball rolling into the nearest basin of an energy landscape. We conjecture that in Vision Transformers, catastrophic overfitting shows up first inside attention. Specific heads see their basins deform under the single-step perturbation before the classifier's output shows any trouble. Every head's basin energy is already computed during the forward pass, so penalizing that deformation should cost no extra forward passes.
The concrete claim has two parts. First, as a diagnostic, a per-head attention-energy gap between the randomly-started point and the one-step adversarial point spikes earlier and more reliably before catastrophic overfitting than the output-level energy signal already known to precede it. Second, as a method, a stop-gradient penalty on that gap lets single-step adversarial fine-tuning of a pretrained ViT reach the AutoAttack robustness of multi-step fine-tuning at large perturbation budgets. It would do so at roughly two forward-backward passes per update instead of eleven. If an output-level energy penalty does equally well, the internal-memory view adds nothing, and the experiments are built to show that outcome if it holds.
Background and what is actually new
Two papers derive softmax attention as one update step that lowers a log-sum-exp energy over stored patterns, and show that this lookup can store exponentially many patterns: Hopfield Networks is All You Need and Modern Hopfield Networks. For one attention head with query $q$, keys $k_1,\dots,k_N$ and inverse temperature $\beta$ (the softmax scaling), the energy of the query's state is
$$E(q) = -\tfrac{1}{\beta}\log\sum_{j=1}^{N}\exp(\beta\, q^\top k_j) + \tfrac12\|q\|^2 .$$
The log-sum-exp term is exactly the normalizer of the softmax the head already computes. Reading $E$ off a head therefore costs essentially nothing. A low value means the query sits deep in a basin around a few keys.
Two lines of work supply the ingredients. Energy Landscape-Aware Vision Transformers treats ViT layers as Hopfield memories. It tracks how many tokens hold 90% of each head's attention mass and uses this to freeze stable layers. It studies clean fine-tuning only, never under attack, and we reuse its per-head measurements as diagnostics. Understanding Adversarial Training with Energy-based Models reads a classifier's logits as an energy. It shows that catastrophic overfitting in single-step training is preceded by a spike in the clean-to-adversarial energy gap, and proposes the Delta Energy Regularizer (DER), which penalizes that gap. DER is the closest prior method, and our proposal differs from it in exactly one way. We measure energy inside attention, per head and per layer, rather than at the logits, and we test whether this localizes and anticipates the collapse in Transformers. DER was evaluated on CNNs only.
Two results motivate looking inside the network. Shedding More Light on Robust Classifiers Under the Lens of Energy-Based Models finds that untargeted attacks lower logit energy, which makes adversarial images look more in-distribution to the classifier. The associative-memory view predicts the opposite at the level of attention, where a perturbation should knock queries out of their correct basins. If the two energies move in opposite directions, the logit signal could be a delayed or even sign-flipped proxy for what attention is doing. That is the gap our diagnostic tests. Dense Associative Memory is Robust to Adversarial Inputs shows that associative memories with sharp, prototype-like basins resist attacks that transfer from smoother models. That result was on MNIST only, but it suggests basin shape is something to protect.
Three papers set the constraints. Fast is better than free establishes randomly-initialized single-step training (FGSM-RS) and its dependence on early stopping. Efficient local linearity regularization to overcome catastrophic overfitting (ELLE) prevents collapse, but it needs about three extra forward passes per sample. That is the overhead we aim to remove. FullLoRA-AT shows that plain low-rank adapters fail in adversarial fine-tuning unless the LayerNorm layers are also adapted. Its LNLoRA design is our parameter-efficient substrate. It still runs multi-step attacks in the inner loop, so it reduces how many parameters are trained but not the cost of the attack.
Research Program
The work has three stages.
Stage 1: the diagnostic study. We fine-tune a pretrained ViT-B with LNLoRA using FGSM-RS on CIFAR-10 and CIFAR-100 at $\epsilon = 8/255$ and $16/255$, a regime where single-step training is known to collapse. At every step we log three kinds of signals:
- the per-head energy gap $\Delta E_{\ell h} = E_{\ell h}(x_{adv}) - E_{\ell h}(x_{init})$, averaged over the query tokens of layer $\ell$ and head $h$, where $x_{init}$ is the randomly perturbed input already used to start the attack;
- the logit energy gap used by DER;
- the 90%-mass token count from ELA-ViT.
The question is which signal crosses a threshold earliest before the drop in robust accuracy on a held-out set attacked with 10-step projected gradient descent (PGD-10), and how consistently it does so across random seeds. We will also check the sign question raised by the "in-distribution paradox": do attention energies rise while logit energy falls?
Stage 2: the regularizer. It is built to use no extra forward passes. FGSM-RS already does a forward pass at $x_{init}$ to compute the attack direction, and a forward pass at $x_{adv}$ to compute the training loss. We cache the per-head energies from the first pass with gradients stopped and add
$$\mathcal{L} = \mathcal{L}_{CE}(x_{adv}) + \lambda \sum_{(\ell,h)\in S} \big(\Delta E_{\ell h}\big)^2 .$$
Here $\lambda$ is a weight and $S$ is the set of heads Stage 1 identifies as early collapsers. Because the reference term is detached, gradients flow only through the adversarial pass that is already being backpropagated. The added cost is a few reductions over tensors that are already in memory. A variant sets $S$ to all heads, which tests whether Stage 1's localization actually matters.
Stage 3: scale and transfer. We move to Imagenette and ImageNet-1K fine-tuning, and to a second backbone (DeiT-B), to see whether the same layers act as early collapsers across datasets and models.
Baselines
The naive reference point is FGSM-RS with LNLoRA and no regularizer, with early stopping chosen on a PGD validation set as Fast is better than free recommends. It shows how much robustness is lost to collapse and how often early stopping rescues it.
The cost ceiling is multi-step adversarial fine-tuning with LNLoRA and PGD-10 attacks, following FullLoRA-AT. It is the robustness target a cheap method must approach. No reported result found on Lacuna for FullLoRA-AT's AutoAttack accuracy on CIFAR-10 or CIFAR-100; the file reports only a 4.29% clean-accuracy gain and about 75% of full fine-tuning time. We therefore re-run it ourselves.
The strongest competitor on the actual question is DER from Understanding Adversarial Training with Energy-based Models, transplanted onto the same ViT and LNLoRA setup. It reports 22.32% PGD robustness and 13.88% AutoAttack robustness on CIFAR-10 at $\epsilon = 16/255$ with single-step training, and 24.38% AutoAttack on CIFAR-100. These are CNN numbers, so we re-run DER on our backbone rather than compare against them directly.
The second strong competitor is ELLE-A (code), which reports 44.32% AutoAttack accuracy on CIFAR-10 in its CNN setting. For a multi-step reference at large budgets, Scaling Adversarial Training to Large Perturbation Bounds reports 22.05% AutoAttack at $16/255$ with OA-AT (code).
Two ablations isolate the key ingredient:
- penalizing attention entropy instead of attention energy, which tests whether basin depth matters or only attention spread;
- applying our penalty to randomly chosen heads instead of the Stage 1 set, which tests whether localization matters.
Every method gets the same backbone, adapter, data, number of epochs, and a matched hyperparameter search of 12 configurations. Cost is reported both as wall-clock time on identical hardware and as forward-backward passes per update.
Beating the field means two things. At $\epsilon = 16/255$, AutoAttack accuracy must be within 2 points of PGD-10 LNLoRA, at no more than 25% of its wall-clock time. And the method must exceed transplanted DER by a margin larger than the seed-to-seed standard deviation, while never collapsing in any of five seeds.
Why not just…?
Why not just use FGSM-RS with early stopping? Early stopping avoids collapse by quitting before it happens. That forfeits the robustness the later epochs would have added, and it requires repeated PGD validation runs. Fast-training collapses completely at $16/255$ (Understanding Adversarial Training with Energy-based Models). The naive baseline with tuned early stopping measures exactly how much is lost. If it already comes within 2 points of PGD-10 on ViTs, the problem we target is smaller than claimed, and we will report that.
Why not just apply DER at the logits? This is the real threat. If logit-level DER prevents collapse on ViTs as well as our attention-level penalty does, the associative-memory framing is decoration. The Stage 1 lead-time comparison and the head-to-head Stage 2 comparison settle it directly. A favorable outcome requires the attention signal to anticipate collapse by more epochs and the penalty to give higher final AutoAttack accuracy. The "in-distribution paradox" (Shedding More Light on Robust Classifiers) is our reason to expect the logit signal to lag, but we treat that as a hypothesis, not evidence.
Why not just use ELLE or plain multi-step PGD with few steps? ELLE works, but it adds about three forward passes per sample (Efficient local linearity regularization), and two-step PGD doubles the attack cost. We report robustness against passes per update so the comparison is on cost, not just accuracy. If PGD-2 with LNLoRA dominates our method on that curve, the method is not worth adopting.
Why not just penalize attention entropy or fix the temperature? Entropy and energy are related but not the same. Energy also reflects how well the query matches the keys at all, not only how evenly attention is spread. The entropy ablation tests whether that distinction matters in practice. If entropy matches energy, we will recommend the simpler entropy penalty.
Proposed Experiments
All robustness is measured with full AutoAttack under the RobustBench protocol. Our regularizer is training-only, so the deployed model is deterministic and contains no inference-time loops, and AutoAttack applies unchanged. We additionally run adaptive attacks that include our energy term in the attacker's loss.
The decisive checks are:
- Lead time. Across five seeds, does the per-head energy gap flag collapse at least one epoch before the logit gap, in at least four of five runs?
- Robustness at matched cost. At $\epsilon = 16/255$ on CIFAR-10 and CIFAR-100, does the regularized single-step run land within 2 AutoAttack points of PGD-10 LNLoRA while beating transplanted DER?
- Stable early collapsers. Is the set of early-collapsing heads consistent across datasets and backbones? If it is, it could be found once and reused. If it is not, the method needs the all-heads variant, and we will report that cost.
- Clean accuracy and calibration. RobustBench flags underconfidence as a known issue for robust models, so we report clean accuracy and calibration alongside robustness, to check that the gain does not come from flattening attention into uninformative averages.
A negative result on the first check would refute the core conjecture regardless of the other outcomes.
References
- Hopfield Networks is All You Need
- Modern Hopfield Networks
- Energy Landscape-Aware Vision Transformers: Layerwise Dynamics and Adaptive Task-Specific Training via Hopfield States
- Understanding Adversarial Training with Energy-based Models
- Shedding More Light on Robust Classifiers Under the Lens of Energy-Based Models
- Dense Associative Memory Is Robust to Adversarial Inputs
- Fast is better than free: Revisiting adversarial training
- Efficient local linearity regularization to overcome catastrophic overfitting
- FullLoRA-AT: Efficiently Boosting the Robustness of Pretrained Vision Transformers
- Scaling Adversarial Training to Large Perturbation Bounds
- RobustBench: a standardized adversarial robustness benchmark