Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners

Soichiro Kumano, Hiroshi Kera, Toshihiko Yamasaki
5/20/2025
3 citations
cs.LGcs.CVstat.ML
transformer-attention

Official code: s-kumano/universally-robust-in-context-learner (2 stars, Jupyter Notebook, MIT, last commit 2026-02-13).

Abstract

Adversarial training is one of the most effective defenses against adversarial attacks, but it incurs a high computational cost. In this study, we present the first theoretical analysis suggesting that adversarially pretrained transformers can serve as universally robust foundation models -- models that can adapt robustly to diverse downstream tasks with only lightweight tuning.

Show full abstract

Specifically, we demonstrate that single-layer linear transformers, after adversarial pretraining across a variety of classification tasks, can generalize robustly to unseen classification tasks through in-context learning from clean demonstrations (i.e., without requiring additional adversarial training or examples). This universal robustness stems from the model's ability to adaptively focus on robust features within given tasks. We also identify two open challenges for attaining robustness: the accuracy-robustness trade-off and sample-hungry training. This study initiates the discussion on the utility of universally robust foundation models. While their training is expensive, the investment would prove worthwhile as downstream tasks can obtain adversarial robustness for free. The code is available at https://github.com/s-kumano/universally-robust-in-context-learner.

View on arXivView PDF

Code Implementations(1)

MIT

The official code for "Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners" [S. Kumano et al., ICLR26].

21Jupyter Notebook, PythonMay 20, 20259 months agoMIT

Similar Papers

Cite this paper

@article{kumano2025adversarially,
  title  = {Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners},
  author = {Soichiro Kumano and Hiroshi Kera and Toshihiko Yamasaki},
  year   = {2025},
  eprint = {2505.14042},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2505.14042v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2505.14042.svg)](https://codeofpaper.com/paper/2505.14042)

Discussion