Temporal Gradient Masking in Fast Adversarial Training of Recurrent Networks

Adversarial training makes a model robust by training it on inputs that a small attack has deliberately corrupted. The attack is almost always built from the gradient of the loss with respect to the input. In a recurrent network, which reads a sequence one step at a time and carries a memory forward, that gradient reaches an early input only after being multiplied by one step-to-step Jacobian for every later step. This is the classic vanishing-gradient problem. We propose that it silently corrupts adversarial training. The attack spends its effort on the last few steps of the sequence. Early steps, which may carry the information the prediction depends on, are barely attacked during training and barely attacked during evaluation. The resulting model looks robust under standard gradient attacks. It may still be fragile to perturbations placed early in the sequence.

The problem gets worse exactly where adversarial training has become affordable. The cheap methods that made adversarial training practical, "free" training that reuses one backward pass for both the weights and the attack, and single-step "fast" training, depend entirely on the quality of that one input gradient. We aim to show that fast adversarial training on recurrent networks has a specific, measurable blind spot along the time axis, which we call temporal gradient masking. We then fix it at zero extra backward passes. The fix reuses a quantity backpropagation through time already computes: how strongly the loss gradient has decayed by the time it reaches each step. We use that quantity to rescale the attack step at each position.

Core Claim

The claim has two parts. The first is diagnostic. When a gated recurrent network such as an LSTM is trained adversarially with single-backward-pass methods, its robust accuracy against full-sequence gradient attacks overstates its robustness to perturbations confined to early time steps. The size of this overstatement grows with how fast the network's gradient decays over time. It shrinks for architectures built to keep gradients stable.

The second part is constructive. A free, time-preconditioned attack step closes most of that gap at the same number of forward and backward passes as standard free adversarial training. We write $g_t = \partial L / \partial x_t$ for the input gradient at step $t$ and $r_t = \|\partial L / \partial h_t\|$ for the norm of the loss gradient at hidden state $h_t$. Both come out of the backward pass that free training already runs. The perturbation update is

$$\delta_t \leftarrow \Pi_{\epsilon}\Big(\delta_t + \alpha \, \frac{g_t}{r_t + c}\Big),$$

where $\alpha$ is the step size, $c$ is a small constant for numerical safety, and $\Pi_\epsilon$ projects back into the allowed perturbation set. Since $g_t$ factors roughly as $\partial L/\partial h_t$ times the local sensitivity $\partial h_t / \partial x_t$, dividing by $r_t$ removes the shrinkage from the long product of Jacobians. What remains is how much each input locally moves the memory. The threat model itself is left unchanged; we only change how the attack spends its budget inside it.

There is one honest caveat. Under an $L_\infty$ budget with sign steps, as in FGSM (the fast gradient sign method), rescaling does not change the sign. So for sign attacks the claim is not about step magnitude. It is that a tiny first-order gradient is a poor predictor of what a finite perturbation does to early steps: gating nonlinearities dominate there, so the sign itself becomes unreliable. For that setting we use normalized-gradient steps followed by clipping. We treat whether sign attacks suffer the same blind spot as an empirical question rather than an assumption.

Why This Is Not Already Done

The closest existing study, Exploring Adversarial Robustness of Deep State Space Models, runs PGD (projected gradient descent) adversarial training, TRADES, FreeAT and YOPO on state space models and a hybrid attention model. It proves error floors for fixed-parameter models and error explosion for input-dependent ones, and adds a small adaptive-scaling module. That work motivates ours but is complementary. It studies images flattened into pixel sequences, never examines how gradients decay across positions inside the attack loop, and does not study long horizons.

ASAT: Adaptively scaled adversarial training in time series rescales the perturbation budget per time step, with a prior that favors recent timestamps. It reports only marginal gains on LSTMs, without explanation. Our hypothesis offers one: a recency prior stacks on top of an attack that is already biased toward the tail. ASAT also changes the threat model, whereas we change only the attack's search inside a fixed threat model, and ASAT keeps full multi-step PGD rather than fast methods.

Input-Cell Attention Reduces Vanishing Saliency of Recurrent Neural Networks shows that LSTM input gradients wrongly favor recent steps even when early inputs drive the prediction. This is the clean-model version of our blind spot, and it motivates our diagnosis. Its fix, attention over the whole input history, costs $O(T^2)$, and it never touches adversarial training.

The fast methods themselves, Adversarial training for free! and Fast is better than free: Revisiting adversarial training, supply the training recipes we reuse. Both were validated only on feedforward convolutional networks.

Research Program

The work has three parts. The first is a position-resolved robustness evaluation, the component we expect to outlast the method. For each trained model we report robust accuracy under attacks confined to a single time segment: early, middle or late. Each segment is attacked three ways. We run long multi-step PGD with restarts. We run an attack that maximizes the change in the hidden state at the end of the segment, which needs only a short backward chain and so sidesteps vanishing gradients by construction. We run a gradient-free random-search attack. We also run transfer attacks from generator networks trained as in Adversarial Attacks on Time Series. The gap between full-sequence gradient robust accuracy and the worst early-segment robust accuracy is our measure of temporal gradient masking.

The second part measures, during training, the per-step profile $r_t$ and the per-step perturbation norm $\|\delta_t\|$. This tests directly whether perturbation strength tracks gradient decay. It also tests whether the profile differs between LSTMs, GRUs, the oscillator-based Coupled Oscillatory Recurrent Neural Network (coRNN) (whose implicit-explicit discretization bounds gradients), and Gated Orthogonal Recurrent Units (which pair a norm-preserving memory transition with forget gates).

The GORU comparison bears on a tension raised in the file. Forget gates are needed to ignore noise, as GORU's Denoise Task results show. They may also be what blocks the attack signal from reaching early inputs. Separating the orthogonal transition from the gates lets us see which part matters.

The third part is the preconditioned free training itself, run at a matched count of forward and backward passes. We also test a variant that normalizes per segment rather than per step, to check that the benefit does not come from amplifying noise in individual steps.

Baselines

The naive reference point is standard training with no adversarial examples, evaluated under the same position-resolved attacks. It anchors how vulnerable each architecture is to begin with.

The strongest affordable competitor is FreeAT from Adversarial training for free!, alongside Fast AT from Fast is better than free: Revisiting adversarial training, which uses FGSM with a random start. These are the methods our variant modifies, and they define the cost budget. We run them with identical data, architectures, epochs, and total forward and backward passes. Each method, including ours, gets the same hyperparameter search over step size, $\epsilon$ and replay count $m$, with early stopping on held-out full-sequence PGD robust accuracy, as Wong et al. recommend. The only reported numbers on Lacuna for these methods are on image convolutional networks, not sequences. On CIFAR-10, Fast AT reached 45% robust accuracy in 6 minutes, and FreeAT with $m=8$ reached about 46% against PGD-20 in about 13 hours. No reported result was found on Lacuna for adversarially trained recurrent networks on psMNIST, noise-padded CIFAR-10 or the Adding Problem, so our runs establish those numbers.

The accuracy ceiling baseline is full multi-step PGD adversarial training, which costs many times more. Beating free training means higher worst-segment robust accuracy at matched cost, with full-sequence robust accuracy and clean accuracy no lower than one standard deviation below it. Approaching multi-step PGD's worst-segment number at a fraction of its cost would count as a strong result.

ASAT's time-dependent scaling, run inside the same free-training loop, tests whether a fixed recency prior can do what the measured profile does. The key ablation replaces $r_t$ with a constant, a random permutation of the measured profile, or a smooth fit decaying exponentially with distance from the end. It isolates whether the measured, per-example decay profile is the active ingredient.

Why not just…?

Why not just run more PGD steps and restarts? More steps along the same vanishing gradient still move early inputs very little, so extra compute may not reach the blind spot. Our evaluation includes long PGD with restarts as an attack and multi-step PGD as a training baseline. If multi-step PGD training closes the early-segment gap on its own, the diagnosis still stands. Our method's claim then shrinks to matching that at free-training cost, which we would report as such.

Why not just use a Transformer or a state space model, whose gradients do not vanish? Attention costs $O(T^2)$ per pass, and adversarial training multiplies passes. The attention-based Mega model in Exploring Adversarial Robustness of Deep State Space Models showed a 40% gap between training and test adversarial accuracy. We include S4 and Mamba-style models in the position-resolved evaluation. If they show no temporal masking under plain free training, that is an informative positive result for them and narrows our method's scope to recurrent networks.

Why not just switch to a gradient-stable recurrent network like coRNN and use plain Fast AT? This is the most serious threat. Our own hypothesis predicts that coRNN will show a small masking gap. If coRNN with plain Fast AT matches preconditioned LSTMs on worst-segment robustness at equal cost, the practical recommendation becomes "change the architecture," not "change the attack." We would say so plainly. The preconditioner would then matter mainly for gated networks that have forget gates for good reasons, and for existing LSTM deployments such as ASAT's forecasting setting.

Why not just use ASAT's per-step budget scaling? ASAT reshapes the threat model with a recency prior. Under our hypothesis, that makes the attack concentrate on the tail even more, and ASAT's own LSTM results were marginal. The ablation against ASAT scaling at matched cost settles which choice helps.

Proposed Experiments

The decisive testbed is noise-padded CIFAR-10 from the coRNN paper. Here the image occupies the first 32 of 1000 steps and the rest is Gaussian noise, so every useful input sits roughly 968 steps from the output. coRNN reaches 59.0% clean accuracy on this task. Our first test is simple: train an LSTM with Fast AT, then compare full-sequence PGD robust accuracy against the worst early-segment attack confined to steps 1 to 32. If the early-segment attacks, particularly the hidden-state and gradient-free ones, do not drive accuracy substantially lower, the temporal masking hypothesis is wrong for this setting, and we would say so.

The second test repeats the comparison under our preconditioned free training at matched cost. The method succeeds if it cuts the early-segment gap without losing full-sequence robustness.

We then extend to permuted sequential MNIST (784 steps, where coRNN reports 97.3% clean accuracy), HAR-2 sensor streams, and a subset of the UCR archive. We also run the Adding Problem at $T$ from 100 to 5000, attacking the two marked positions with a regression loss, to plot masking gap and wall-clock cost against sequence length. Finally we use the Topix500 volume data with an LSTM, to test whether our account explains ASAT's marginal gains.

Across all settings we report clean accuracy, full-sequence and worst-segment robust accuracy, backward passes and wall-clock time, and how often catastrophic overfitting occurs. We use three seeds per configuration.