Where to Perturb: Testing Whether Bidirectional Attention Decides the Best Layer for Adversarial Training

Adversarial training teaches a model to resist small, worst-case input changes by training it on those changes. For text models it usually perturbs the word embeddings at the bottom of the network. One recent paper offered a geometric reason why this works poorly on BERT-style encoders, the models in which every token attends to every other token in both directions. In these models, the number of directions the data actually varies along (its intrinsic dimensionality) is highest at the input and shrinks toward the top layers. That is the reverse of decoders and vision models. A perturbation at the input therefore stays close to the data and acts like ordinary data augmentation, while a perturbation at the lowest-dimensionality layer pushes the model off the data surface and builds real robustness margins (Explaining the role of Intrinsic Dimensionality in Adversarial Training). That paper, which introduces the method SMAAT, compared model families that differ in attention mask, training objective, data and size all at once. So we do not know what causes the reversal, and practitioners lack a reliable rule for where to perturb a given backbone.

This proposal uses a now-available controlled testbed to answer that question. The testbed is the ETTIN suite of paired encoders and decoders trained on identical data with identical recipes from 17M to 1B parameters (Seq vs Seq), together with decoders converted to bidirectional attention (Adapting Decoder-Based Language Models). The two-sentence version is this. We separate whether the attention mask or the pretraining objective produces the encoder's dimensionality reversal, and we check against an exhaustive layer sweep whether the dimensionality minimum actually predicts the best layer for injecting adversarial perturbations. If it does, one cheap measurement tells you where to adversarially train any encoder, converted decoder or decoder. It also lets us state, at matched size and data, whether bidirectional attention buys adversarial robustness and not just clean accuracy.

Core Claim

We hypothesize that the reversal is set mainly by the attention mask and not by the training objective. If so, ETTIN encoders show decreasing dimensionality with depth and their paired decoders show increasing dimensionality. A causal decoder whose mask is replaced with a bidirectional one moves toward the encoder profile. The layer of minimum dimensionality, measured once before fine-tuning, should land within one or two layers of the empirically best perturbation layer found by sweeping every layer. Matched-size encoders trained with perturbation at that layer should be more robust on AdvGLUE than their paired decoders trained with their own best layer.

Each part can fail independently, and each failure is informative. If the objective and not the mask drives the profile, converted decoders such as Gemma Encoder need input-level adversarial training despite looking like encoders. If the dimensionality minimum does not predict the best layer, SMAAT's selection rule is a heuristic, and the sweep should replace it.

Research Program

The first stage is measurement. For every ETTIN encoder and decoder at several sizes, we compute layer-wise intrinsic dimensionality with the twoNN estimator used by SMAAT, a nearest-neighbour ratio method, on pooled hidden states from SST-2, MNLI, QNLI, QQP and RTE inputs. We add two conditions that pull mask and objective apart. The first is a mask-only condition: a decoder with its causal mask replaced by a bidirectional one, fine-tuned as in the Gemma Encoder recipe with dropout 0.10, without further pretraining. The second is an objective-switch condition: ETTIN decoders given continued masked-language-model pretraining. The ETTIN paper reports this experiment; if those checkpoints are not public, we replicate it at the two smallest sizes. We also re-measure the profile at several points during fine-tuning, because SMAAT fixes its layer from a single profile taken before training and never checks whether the minimum drifts.

The second stage is intervention. On each backbone we run adversarial training with a fixed attack budget at every layer, from the embeddings to the last block. The perturbation is a few projected gradient ascent steps on the hidden state, with the same norm ball, step count and fine-tuning budget for every layer. This sweep is the ground truth. From it we measure the gap between the dimensionality-predicted layer and the best layer. We also measure how much robustness is lost by using the predicted layer instead of the best one, and whether recomputing the minimum during training closes any remaining gap.

The third stage is the controlled architecture comparison. Each ETTIN encoder, with perturbation at its best layer, is compared against its paired decoder at its best layer and against the converted decoder.

Baselines

The naive reference point is vanilla fine-tuning of each backbone with no adversarial component, using the same data, epochs and hyperparameter search. All robustness gains are reported relative to it.

The conventional method is embedding-level adversarial training. We implement this as projected gradient ascent on embeddings, plus DeBERTa's scale-invariant variant SiFT, which normalizes embeddings before perturbing them (DeBERTa). It is the natural competitor because it is the default practice. AdvGLUE already shows that related embedding methods such as SMART and FreeLB give only marginal gains (Adversarial GLUE). It is also the layer-0 point of our sweep, so it gets identical budgets.

The most direct competitor is SMAAT as published: one static profile before training, then perturbation at the chosen layer. SMAAT reports a 28.8% gain in average robust accuracy over the best prior defense on YELP with BERT, and a 25–33% reduction in GPU training time. Our proposal beats it if dimensionality re-estimated during training, or the sweep, finds a better layer on a meaningful share of backbones. It also beats it if we show that SMAAT's rule fails on the mask-only or objective-switch conditions.

CreAT perturbs the input but adds a loss that pushes the encoder's hidden states away from their clean values, to defeat attacks that fool only the classifier head (Toward Adversarial Training on Contextualized Language Representation). It is the strongest alternative explanation for why input-level training underperforms, and it reports raising AdvGLUE from 59.1 to 61.1. We run it on the same ETTIN backbones with the same tuning budget, alone and combined with late-layer perturbation. This tests whether its extra loss is redundant once the perturbation sits at the right layer.

ROSE skips adversarial examples entirely. It masks fragile parameter updates during fine-tuning and reports AdvGLUE gains of 8.04% for RoBERTa-base and 4.29% for RoBERTa-large over vanilla fine-tuning (ROSE). We run it with its released code (jiangllan/ROSE) as the cheap, attack-agnostic competitor.

The strongest reported AdvGLUE number in the file is GenerAT's 80.1% average accuracy on DeBERTa-v3-large (GenerAT). GenerAT uses a different, larger backbone and a token-level generator, so we treat it as an external reference ceiling and not a matched comparison. We will not claim to beat it unless we rerun it on our backbones.

Two ablations isolate the key ingredient. One perturbs at a random layer, and the other at the layer of maximum dimensionality. If either matches the minimum-dimensionality layer, the geometric story does not explain the effect.

Why not just…?

Why not just sweep the perturbation layer and skip the dimensionality theory? This is the most serious alternative, and the proposal adopts it as its ground truth. The sweep costs one full adversarial training run per layer. The dimensionality rule costs one forward pass. The rule is worth keeping only if it lands within about one layer of the sweep's optimum and loses little robustness, and stage two measures exactly that. If the rule fails, our headline becomes "sweep, don't estimate", which is still a useful negative result against SMAAT's selection procedure.

Why not just use CreAT or GenerAT and stop worrying about layers? Both still perturb at or near the input. GenerAT also needs a coupled masked-language generator and a perturbed-token detector, which is far more machinery. If late-layer perturbation plus vanilla loss matches CreAT on the same backbone at lower cost, the extra objective is unnecessary. If CreAT still adds gains on top of late-layer perturbation, then the "lazy attack" and on-manifold explanations describe different failures. The combined run settles which is true.

Why not just take a larger decoder, or convert one to bidirectional attention? Scale alone is weak evidence of robustness: ChatGPT averages 70.1% on AdvGLUE per GenerAT, and ELECTRA-Large falls from 93.16 GLUE to 41.69 AdvGLUE. Converted decoders are cheap to obtain, but nobody has checked whether their geometry behaves like an encoder's. The mask-only condition tests this directly. If converted decoders inherit the encoder profile and robustness, that is good news for practitioners, and we will report it as such.

Why not just use ROSE, which avoids the adversarial inner loop? ROSE is cheaper, but it never builds a worst-case margin. We compare against it at matched wall-clock time as well as matched epochs. If ROSE equals late-layer training under equal compute, the practical case for layer-targeted training weakens, and we will say so.

Proposed Experiments and Decisive Checks

Robustness is measured on AdvGLUE across SST-2, QQP, MNLI, QNLI and RTE, using the benchmark's average accuracy. Because AdvGLUE's examples were filtered for transfer against particular models, we also attack each trained model directly with word-substitution and embedding attacks on YELP and AGNEWS, as SMAAT does, and report robust accuracy. Clean GLUE accuracy measures the cost of each defense, and GPU-hours measure its compute. Results are averaged over three seeds with confidence intervals.

Three checks decide the proposal. The first asks whether the dimensionality profile of the mask-only converted decoder sits closer to its paired encoder or its paired decoder; that tells us whether mask or objective drives the reversal. The second asks whether, across all backbones, the predicted layer's robustness falls within one seed-standard-deviation of the sweep optimum; that tells us whether the rule can replace the sweep. The third asks whether, at each matched ETTIN size, the encoder at its best layer beats its paired decoder at its best layer on AdvGLUE by more than seed noise; that tells us whether bidirectional attention buys robustness beyond clean accuracy.

A positive answer to all three gives a cheap, architecture-aware recipe for adversarial training. A negative answer on any one tells practitioners which part of current practice to stop trusting.