NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Shallow-Unroll Attacks: Cheap Adversarial Training for Recurrent-Depth Networks

Some neural networks reuse one block of layers in a loop, applying it again and again to their own output. These recurrent-depth networks can "think longer" at test time: a model trained with 20 loop iterations on small mazes solves larger mazes when allowed more iterations. Making any network robust to adversarial examples (tiny, deliberately crafted input changes that flip its prediction) usually requires adversarial training. In adversarial training, every training step first runs several gradient-ascent steps on the input to find a bad perturbation, then trains on it. For a looped network this cost compounds, because each attack step has to backpropagate through all $N$ loop iterations. Robust training then costs roughly $K\times N$ block passes per example, where $K$ is the number of attack steps.

We propose to exploit the one thing feed-forward networks lack. A looped network run for only a few iterations is a cheap, exact-weight copy of itself. We craft the adversarial perturbation with a multi-step attack on the shallow unroll (for example 2 of 20 iterations), then update the weights by training at full depth on that perturbation. The central question is whether attacks found on the shallow unroll carry over to the deep one. If they do, multi-step robust training costs about as much as single-step "fast" adversarial training. We also get a free diagnostic: the alignment between the input gradients at shallow and full depth. We use it both to pick the attack depth during training and to explain when the approach fails.

Core Claim

For weight-shared recurrent networks, a $K$-step attack computed at shallow depth $r \ll N$ gives robustness at full depth $N$, and at extrapolated test depths $M > N$, that matches full-depth multi-step adversarial training. Its per-step cost equals or undercuts single-step full-depth training. Counting cost in block applications (one forward plus backward through the shared block costs about 3 units), one training step costs

$$C(r, K) \approx 3Kr + 3N,$$

where the first term is the attack and the second the weight update. Full-depth PGD-7 at $N=20$ costs about $480$ units, full-depth single-step FGSM about $120$, and shallow PGD-7 at $r=2$ about $102$. The claim is falsified if, at matched cost, full-depth single-step training gives equal or better full-depth robustness. It is also falsified if shallow-trained models are robust only against shallow attacks.

Relation to Prior Work

Two methods supply the efficiency baseline we must beat. Adversarial training for free! reuses the input gradient from each weight-update backward pass to also update the perturbation, replaying minibatches. Fast is better than free shows that a single-step attack with random initialization matches multi-step training, as long as it avoids "catastrophic overfitting," a sudden collapse into a jagged loss surface that fools single-step attacks. Both treat the network as a monolith. Neither can make the attack itself cheaper per step. Our method keeps a genuinely multi-step attack, which may make it less prone to catastrophic overfitting, and makes each step cheap.

The recurrent side supplies the architecture and the reason to care. Can You Learn an Algorithm? establishes the easy-to-hard extrapolation that feed-forward nets cannot match. Recursive Inference Scaling trains with randomized loop counts, so the model is usable at any depth. That property makes a shallow unroll a meaningful model rather than a broken one. The same paper also reports that recursion did not help supervised ImageNet classification. That result constrains us: we cannot justify recurrence on CIFAR-10 accuracy alone. So we treat the algorithmic tasks as the primary regime and CIFAR-10 as the comparability regime.

Three papers constrain the evaluation. A Closer Look at the Adversarial Robustness of Deep Equilibrium Models studies infinite-depth weight-shared models solved by root-finding. It shows that apparent robustness under standard attacks (78.03%) falls to 47.12% under proper attacks through intermediate states, and that adversarial training there slows or breaks the solver. We avoid solvers entirely and use explicit unrolls with exact gradients. We take from this paper the requirement to attack every intermediate depth. Evaluating the Adversarial Robustness of Adaptive Test-time Defenses shows iterative inference-time defenses collapsing to near zero under adaptive attacks. Our loop is a plain forward pass, not a test-time optimization, but we adopt their standard of evidence anyway. Multi-exit work (NEO-KD, BERT Lost Patience) combines adaptive depth with robustness but adds training cost, and it uses unshared layers, where no cheap same-weight surrogate exists.

Research Program

We build recurrent ResNets in the style of Schwarzschild et al. They have an input projection, a shared residual block looped $r$ times, and a readout usable after any iteration. Training uses stochastic loop counts $r \sim \mathcal{U}[1, N]$ for the clean path.

Each training step runs a $K$-step projected-gradient attack with random start, backpropagating only through $r_{att}$ iterations. The attack loss is taken on the readout at depth $r_{att}$. The weights are then updated on the perturbed input at full depth $N$, with loss summed over late-iteration readouts.

The dynamic component is how $r_{att}$ is chosen. Every few hundred steps we measure the cosine similarity between input gradients at depth $r_{att}$ and at depth $N$ on a held-out batch. We increase $r_{att}$ whenever this similarity falls below a threshold. This spends attack compute only when shallow and deep behavior diverge.

The analysis has three parts. First, we track how gradient alignment evolves during training. We want to know whether robust training makes depths agree, or whether the model learns to make its shallow path deceptive, so that the attack is weak and deep features stay fragile. Second, we plot robust accuracy against test depth $M$ from $N/2$ to $2N$. This directly settles whether extra iterations under attack clean up perturbed features or amplify them, the question left open by the DEQ paper. Third, we compare against catastrophic overfitting rates of single-step training at the same cost.

Baselines

The do-nothing reference is the same recurrent network trained without adversarial training, evaluated under the full attack suite. It should sit near zero robust accuracy and sets the clean-accuracy and cost floor.

The strongest efficient competitor is full-depth single-step training with random initialization, as in Fast is better than free. That paper reports 45% robust accuracy against a strong PGD attack on CIFAR-10, with training in 6 minutes versus 80 hours for PGD training, for a feed-forward network. It is the right target because at $N=20$ it costs about the same as our method. If multi-step shallow attacks give no advantage over it, the idea has no reason to exist. We run it on the identical recurrent architecture, data, epoch count and cyclic learning-rate schedule. Step sizes for both methods are tuned on the same grid of equal size. Beating it means at least 2 points higher AutoAttack accuracy at full depth, at equal or lower measured wall-clock time, averaged over three seeds. A second condition also counts as beating it: a substantially lower rate of catastrophic overfitting across the step-size grid at equal robustness.

We also run full-depth "free" training (Adversarial training for free!). It reports about 46% accuracy against PGD-20 on CIFAR-10 in about 13 hours, using a feed-forward network. We give it the same replay-adjusted epoch budget.

Full-depth PGD-7 training serves as the expensive quality ceiling. Matching it within 1–2 points is the target for our method.

For architectural context, we include a feed-forward ResNet-18 with fast training. A Closer Look at DEQs reports 53.58% robust accuracy for adversarially trained ResNet-18 versus 47.12% for DEQ-Large. The feed-forward model is the bar a weight-shared model must approach on CIFAR-10.

Two ablations isolate the key ingredient. The first is a separate small network with unshared weights, trained jointly and used as the attack surrogate at matched cost. It tests whether weight sharing, rather than merely having a cheap surrogate, is what makes the attacks carry over. The second fixes $r_{att}$ instead of adapting it, which tests the alignment-driven schedule.

On mazes and prefix sums, we found no reported result on Lacuna for adversarial robustness of recurrent networks. All adversarial numbers there will be produced by our own runs of these baselines.

Why not just…?

Why not just use full-depth fast single-step training on the recurrent network? This is the real threat. It is already cheap, and on feed-forward networks it matches multi-step robustness when it does not collapse. Our bet rests on two things. First, a multi-step attack finds stronger perturbations than one step. Second, Fast is better than free documents that single-step training is fragile to step size. The matched-cost comparison and the step-size sweep described above settle this directly. If fast training wins on both robustness and stability, we will report that shallow attacks are unnecessary.

Why not just train a feed-forward network with fast adversarial training and skip recurrence? On CIFAR-10 this may well win, and Recursive Inference Scaling suggests recurrence does not help static image classification. But a feed-forward network cannot extrapolate. Can You Learn an Algorithm? reports feed-forward networks near 22% on 13×13 mazes. A recurrent network, by contrast, rises from about 30% to about 70% when given 25 iterations. The comparison that matters is robust accuracy on the harder test sizes, where only the recurrent model has any clean accuracy to protect.

Why not just craft attacks on a small, separate proxy model? Transfer attacks from unrelated models are known to be weaker than white-box ones, and a separate proxy adds parameters and its own training cost. The unshared-surrogate ablation measures this at matched compute. If the ablation matches shallow unrolls, the weight-sharing story is wrong and we will say so.

Why not just train the whole model at shallow depth? That removes the cost problem but also removes the deep computation that extrapolation relies on. We include a run where both the attack and the weight update use depth $r_{att}$. We expect clean and robust accuracy on harder mazes to fall behind at test depths beyond training.

Proposed Experiments

The benchmarks are CIFAR-10 with $\ell_\infty$ radius 8/255, for comparability with the reported numbers above, and the mazes (train 9×9, test 13×13) and prefix-sum (train 32-bit, test 40-bit) tasks from Schwarzschild et al. For the algorithmic tasks, perturbations are bounded $\ell_\infty$ changes to the input encoding. Every model is evaluated with PGD-50 and AutoAttack, backpropagating through the entire unroll. Attacks target the readout at every test depth $M \in \{N/2, N, 1.5N, 2N\}$, plus an ensemble attack over all readouts, following the intermediate-state attacks of A Closer Look at DEQs. We check for masked gradients by confirming that robust accuracy decreases monotonically with attack steps and that input-gradient norms do not vanish with depth. We report wall-clock time, block-application counts and peak memory alongside accuracy.

Three checks are decisive. The first is whether shallow PGD-7 at $r_{att}=2$ beats full-depth single-step training on full-depth AutoAttack accuracy at equal wall-clock time. The second is whether the robustness it buys holds at $M = 2N$ on 13×13 mazes, rather than being robust only at the depth it was trained against. The third is whether gradient alignment between shallow and full depth predicts when robustness carries over, across seeds and schedules. A positive answer to all three would show that the loop structure of recurrent networks is itself a source of cheap adversarial training. A negative answer on the first would show that fast single-step training is already sufficient for this class of models.