stat.MLOct 27, 2025

Optimal In-context Adaptivity and Distributional Robustness of Transformers

Authors: Tianyi Ma, Tengyao Wang, Richard J. Samworth

Organizations: Statistical Laboratory, University of Cambridge · Department of Statistics, London School of Economics and Political Science

Abstract

We study in-context learning problems where a Transformer is pretrained on tasks drawn from a mixture distribution π=∑α∈Aλαπαπ=\sum_{α\in\mathcal{A}} λ_α π_α, called the pretraining prior, in which each mixture component παπ_α is a distribution on tasks of a specific difficulty level indexed by αα. Our goal is to understand the performance of the pretrained Transformer when evaluated on a different test distribution μμ, consisting of tasks of fixed difficulty β∈Aβ\in\mathcal{A}, and with potential distribution shift relative to πβπ_β, subject to the chi-squared divergence χ2(μ,πβ)χ^2(μ,π_β) being at most κκ. In particular, we consider nonparametric regression problems with random smoothness, and multi-index models with both random smoothness and random effective dimension. We prove that a large Transformer pretrained on sufficient data achieves the optimal rate of convergence corresponding to the difficulty level ββ, uniformly over test distributions μμ in the chi-squared divergence ball. Thus, the pretrained Transformer is able to achieve faster rates of convergence on easier tasks and is robust to distribution shift at test time. Finally, we prove that even if an estimator had access to the test distribution μμ, the convergence rate of its expected risk over μμ could not be faster than that of our pretrained Transformers, thereby providing a more appropriate optimality guarantee than minimax lower bounds.

Figures & tables

Appendix figures & tables2 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. Transformers Learn Robust In-Context Regression under Distributional Uncertainty

    Mar 19, 2026Hoang T. H. Cao, Hai D. V. Trinh, Tho Quan +1In-Context LearningTransformer

  2. Transformers as Cross-Task Learners: Shared Structure Drives Sample Efficiency in In-Context Learning

    Sep 24, 2026Zhongjie Shi, Rongjie Lai, Alexander Cloninger +1TransformerMulti-Task Learning

  3. How Does the Pretraining Distribution Shape In-Context Learning? A Fundamental Trade-Off

    Oct 1, 2025Waïss Azizian, Ali HasanLanguage Model PretrainingOOD Generalization