English

Optimal In-context Adaptivity and Distributional Robustness of Transformers

Machine Learning 2026-05-08 v3 Machine Learning Statistics Theory Statistics Theory

Abstract

We study in-context learning problems where a Transformer is pretrained on tasks drawn from a mixture distribution π=αAλαπα\pi=\sum_{\alpha\in\mathcal{A}} \lambda_{\alpha} \pi_{\alpha}, called the pretraining prior, in which each mixture component πα\pi_{\alpha} is a distribution on tasks of a specific difficulty level indexed by α\alpha. Our goal is to understand the performance of the pretrained Transformer when evaluated on a different test distribution μ\mu, consisting of tasks of fixed difficulty βA\beta\in\mathcal{A}, and with potential distribution shift relative to πβ\pi_\beta, subject to the chi-squared divergence χ2(μ,πβ)\chi^2(\mu,\pi_{\beta}) being at most κ\kappa. 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 β\beta, uniformly over test distributions μ\mu 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 μ\mu, the convergence rate of its expected risk over μ\mu could not be faster than that of our pretrained Transformers, thereby providing a more appropriate optimality guarantee than minimax lower bounds.

Keywords

Cite

@article{arxiv.2510.23254,
  title  = {Optimal In-context Adaptivity and Distributional Robustness of Transformers},
  author = {Tianyi Ma and Tengyao Wang and Richard J. Samworth},
  journal= {arXiv preprint arXiv:2510.23254},
  year   = {2026}
}

Comments

47 pages, 4 figures