One Adversarially Trained Adapter, Shared Across Many Tasks

Adversarial training makes a neural network harder to fool with tiny, deliberately crafted input changes. It works by attacking the model during training and learning from those attacks. The cost is high. Each training step first runs a multi-step attack, which takes roughly $2N+2$ forward and backward passes for an $N$-step attack instead of 2. That makes it 10 to 20 times more expensive than ordinary training. Modern deployments make this worse. A frozen pretrained backbone is typically specialized to many tasks by small add-on modules called low-rank adapters (LoRA): each is a pair of thin matrices whose product is added to a frozen weight matrix. Making each of $T$ task adapters robust would mean paying the adversarial premium $T$ times, again every time a task is added.

This note proposes paying it once. We train a single "robustness adapter" adversarially on the frozen backbone. During that training, the attacked model is the backbone combined with a randomly sampled, already-trained clean task adapter, so the robustness adapter learns to work alongside task adapters it has never been tuned with. At deployment the robustness adapter is simply added to whatever task adapter is in use, including adapters for tasks that did not exist when it was trained. The central claim is testable. Robustness learned against a population of task adapters transfers to held-out task adapters under full white-box attack. It should recover most of the robust accuracy of per-task adversarial LoRA at about $1/T$ of the adversarial compute. The claim also needs a specific failure mode to be absent: the multi-task setting must not collapse to its weakest task.

Core Claim and What Is New

Let $\theta_0$ be frozen backbone weights, $\Delta_t$ a clean LoRA adapter for task $t$ trained with ordinary fine-tuning, and $\phi$ the shared robustness adapter. We train $\phi$ with

$$\min_{\phi}\; \mathbb{E}_{t \sim \mathcal{S}}\, \mathbb{E}_{(x,y)\sim \mathcal{D}_t} \Big[ \max_{\|\delta\|_\infty \le \epsilon} \mathcal{L}_t\big(f_{\theta_0 + \Delta_t + \phi}(x+\delta),\, y\big) + \beta\, \mathcal{L}_t\big(f_{\theta_0 + \Delta_t + \phi}(x),\, y\big) \Big],$$

where $\mathcal{S}$ is a set of training-pool tasks, $\epsilon$ the perturbation budget, and $\beta$ weights a clean-accuracy term. The $\Delta_t$ are held fixed; only $\phi$ is updated. The adversarial compute is one run, independent of $T$. Adding a new task costs only clean LoRA training.

The closest prior work does something different in each case:

  • PISTOLE merges a clean and an adversarially fine-tuned full CLIP checkpoint post hoc. It reports roughly 5% higher mean clean accuracy and 5.8% higher robust accuracy than adversarial fine-tuning, and runs 8–11× faster than retraining. But it presupposes both full checkpoints already exist and addresses one task, not a growing set.
  • AutoLoRa uses a LoRA branch trained on clean data to stabilize adversarial fine-tuning of the full feature extractor. It then discards the branch, so the expensive adversarial update still falls on the whole backbone, once per task.
  • Robustness Tokens is the method we most directly build on. It trains 10 learnable tokens on a frozen ViT for about 200 steps. This recovers DINOv2-Giant ImageNet accuracy under white-box attack from 0.3% to 63.1% and ADE20K attacked mIoU from 4.7 to 23.3. However, the tokens are trained against the unmodified backbone, and the paper's own caveat is that they rely on staying secret. Our module is trained against adapted backbones and is evaluated with the attacker assumed to know every weight.

What is new here is training against a distribution of task adapters and requiring transfer to unseen ones.

Two further papers shape the design. Adversarial Robustness in Multi-Task Learning: Promises and Illusions found a "one bad apple" effect: the robustness of a shared encoder is set by its most fragile task. It also found that reweighting task losses can fake robustness through gradient masking, meaning the defense hides useful gradients from the attacker rather than truly widening margins. This paper both motivates the work and constrains it: our adapter is shared across tasks, so it could inherit exactly that collapse, and our evaluation must use that paper's adaptive multi-task attack. Det-AdvProp reports that robustness learned in pretraining washes out during downstream fine-tuning. This is the evidence that the obvious cheap alternative (robust backbone plus clean adapters) may fail, and we test it directly.

Research Program

Stage 1: build the adapter pool. On a frozen CLIP ViT-B/16, train clean LoRA adapters for the seven-task vision battery used by L-LoRA: Stanford Cars, DTD, EuroSAT, GTSRB, RESISC45, SUN397 and SVHN.

Stage 2: train the robustness adapter with held-out tasks. For each held-out task, train $\phi$ on the remaining six with the objective above, using PGD attacks inside training. The inner attack at each step targets the sampled task. As a variant, we also target the task with the currently highest loss, a direct counter to the one-bad-apple effect.

Stage 3: compare placements. We compare two ways of attaching $\phi$: as additive low-rank weight updates on attention and MLP layers, and as prepended tokens in the style of Robustness Tokens. Composition is plain addition of adapters. A partially linearized version following L-LoRA serves as an ablation, in case adapter interference, not robustness, is the bottleneck.

Stage 4: dense multi-task extension. Repeat the recipe on PASCAL-Context with a Swin backbone. Its four dense tasks (semantic segmentation, human parts, surface normals, saliency) are exactly where the one-bad-apple collapse was observed.

Analysis. Beyond accuracy, we measure clean-versus-adversarial feature cosine similarity per layer, the diagnostic Robustness Tokens used. The question is whether $\phi$ restores clean features in a way that is independent of which task adapter is present, which is the proposed mechanism for transfer.

Baselines

Naive reference points. The first is clean task LoRA with no defense, the lower bound. The second is per-task adversarial LoRA: PGD adversarial training of each task's adapter separately. This is the accuracy upper reference and the compute ceiling, since its adversarial cost grows linearly in $T$. All adversarial runs use the same attack steps, $\epsilon$, number of optimizer steps, and hyperparameter search budget per run. Compute is reported as total forward-backward passes, so the roughly $T$-fold difference is explicit. On this battery the file gives no reported robust accuracy: no reported result found on Lacuna for per-task adversarial LoRA on the L-LoRA vision tasks. We therefore run it ourselves.

Strongest existing method. This is Robustness Tokens, trained per its recipe on the bare backbone and then used unchanged with each task adapter. Its reported ImageNet result, 0.3% to 63.1% attacked accuracy on DINOv2-Giant with clean accuracy 85.2% against 85.6% undefended, is the strongest figure in the file for a single cheap robustness module on a frozen transformer. It is also the most direct competitor for "train once, use everywhere." We give it the same compute as our method. We also train a stronger version of it for each task individually.

Merging baseline. Following PISTOLE, we merge each per-task adversarial adapter with its clean adapter, using both naive averaging and PISTOLE-style masking on the adapter weights. This checks whether merging recovers clean accuracy better than our composition does, at whatever extra cost it carries.

Key ablation. The ablation that isolates our main ingredient trains $\phi$ with the identical budget but against the backbone alone ($\Delta_t=0$). The only difference from our method is then whether task adapters appear during adversarial training.

What counts as success. We beat the strongest method if, on held-out tasks under AutoAttack, our composed model:

  • exceeds Robustness Tokens composed with task adapters in robust accuracy, at equal or better clean accuracy;
  • recovers at least most of the per-task adversarial LoRA robust-accuracy gain over the undefended model;
  • does so at roughly $1/T$ of its adversarial compute.

Why not just…?

Why not just start from an adversarially pretrained backbone and train ordinary clean adapters on it? This costs nothing extra per task. It is the most serious cheap alternative. Det-AdvProp reports that pretrained robustness erodes under downstream fine-tuning, but that was full-network fine-tuning. A low-rank adapter changes far less, so erosion may be mild. We include this as a baseline, with a robust backbone of the same architecture where one is available. If clean adapters on a robust backbone match our held-out robust accuracy, the shared-adapter idea is unnecessary, and we will report that.

Why not just use Robustness Tokens as they are? They are already task-agnostic and cheap. The open question is whether tokens trained against the unmodified backbone still correct features once LoRA has changed the internal weights. For tasks that only read frozen features, they may transfer perfectly. The key ablation settles it: if training against sampled adapters adds nothing over training against the bare backbone, the simpler method wins and our contribution reduces to an evaluation result.

Why not just adversarially train each task's adapter separately, or merge per-task robust and clean adapters as PISTOLE does? These likely give the best per-task numbers, and we treat them as the ceiling. Their adversarial cost scales with $T$ and recurs with every new task. The proposal only matters if the accuracy gap to this ceiling is small, and the experiments report that gap directly.

Why not just add a defensive prompt? Improving Adversarial Robustness in Vision-Language Models with Architecture and Prompt Design raised LLaVA-7B attacked COCO accuracy from 12.54% to 91.46% with one sentence. That result applies to instruction-following models, not to vision encoders serving classification and dense tasks. The research file also notes that an adaptive attacker who includes the prompt in the attack may bypass it. It is out of scope for our backbones.

Decisive Checks

All robust numbers use AutoAttack as standardized by RobustBench at $\ell_\infty$, $\epsilon=8/255$. The attacker knows $\phi$ and every task adapter. On PASCAL-Context we additionally use the weighted multi-task gradient attack from Promises and Illusions, because it was twice as effective as PGD on surface normals. Clean metrics are top-1 accuracy, mIoU, and the multi-task relative gain $\Delta m$, for which TADFormer reports +4.24% clean on PASCAL-Context as a reference.

Three results decide the proposal:

  1. Transfer. On held-out tasks, how does robust accuracy change as the training pool grows from one task to six? Rising transfer supports the population-training mechanism. Flat transfer means $\phi$ is just a generic Robustness-Token-like corrector.
  2. One bad apple. On PASCAL-Context, adding the fragile segmentation adapter to the pool should not drag down robustness on the other tasks. We compare against a pool without it.
  3. Gradient masking. Robust accuracy under the black-box Square Attack must not exceed white-box accuracy. If it does, the "robustness" is gradient masking and the claim fails regardless of the headline numbers.