stat.MLFeb 5, 2025

Why Transformers Struggle with Distribution-Independent In-Context Learning

Authors: Omar Naim, Jerome Bolte, Nicholas Asher

Organizations: Institut de Recherche en Informatique de Toulouse; University of Toulouse; Toulouse, France · Toulouse School of Economics; University of Toulouse Capitole; Toulouse, France · Institut de Recherche en Informatique de Toulouse; Centre Nationale de la Recherche Scientifique; Toulouse, France

Abstract

With in-context learning (ICL), transformer models adapt to new tasks from illustrative examples at inference time without updating their parameters. A common interpretation is that transformers implement implicit learning algorithms in their forward pass. We test this interpretation and ICL capability under distribution shift in noiseless polynomial regression, where the context uniquely determines the target function. Models that are near-perfect in distribution exhibit sharp performance degradation under shifts in the input or target-function distribution. This behavior persists across polynomial degrees and multiple training interventions, and in higher-dimensional nonlinear regression. We identify two architectural mechanisms that explain this breakdown: output saturation at finite boundary values linked to final normalization, and attention concentration on a small subset of the context, which can limit context-dependent adaptation required for ICL. Controlled experiments, architectural ablations, targeted interventions, and theoretical analysis provide strong evidence for both mechanisms and their consequence: strong in-distribution ICL does not imply distribution-independent ICL, which calls for caution when using ICL instead of explicit retraining or adaptation under distribution shift.

Figures & tables

Appendix figures & tables24 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

Mar 19, 2026

Transformers Learn Robust In-Context Regression under Distributional Uncertainty

Recent work has shown that Transformers can perform in-context learning for linear regression under restrictive assumptions, including i.i.d. data, Gaussian noise, and Gaussian regression coefficients. However, real-world data often violate these assumptions: the distributions of inputs, noise, and coefficients are typically unknown, non-Gaussian, and may exhibit dependency across the prompt. This raises a fundamental question: can Transformers learn effectively in-context under realistic distributional uncertainty? We study in-context learning for noisy linear regression under a broad range of distributional shifts, including non-Gaussian coefficients, heavy-tailed noise, and non-i.i.d. prompts. We compare Transformers against classical baselines that are optimal or suboptimal under the corresponding maximum-likelihood criteria. Across all settings, Transformers consistently match or outperform these baselines, demonstrating robust in-context adaptation beyond classical estimators.
Oct 27, 2025

Optimal In-context Adaptivity and Distributional Robustness of Transformers

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.
Feb 19, 2026

Bigger Is Safer: Provable Robustness in In-Context Learning Scales with Capacity

In-context learning (ICL) allows large language models to adapt to new tasks from a few examples without updating their parameters. Existing theories explain ICL by assuming the test task distribution matches pretraining -- an assumption that breaks down under adversarial distribution shifts. We introduce a distributionally robust meta-learning framework that provides worst-case guarantees for ICL under Wasserstein-based distribution shifts. Focusing on linear self-attention Transformers, we derive a non-asymptotic bound connecting adversarial perturbation strength (ρρ), model capacity (mm), and the number of in-context examples (NN). The analysis reveals that the maximum safe perturbation radius scales as ρmax⁡∝mρ_{\max} \propto \sqrt{m}, while maintaining performance under adversarial shift requires additional in-context examples with Nρ−N0∝ρ2N_ρ- N_0 \propto ρ^2. Experiments on synthetic tasks confirm these scaling laws, and experiments on 21 real pretrained models (0.1B--7B parameters, 5 families) provide qualitative evidence consistent with the theory's predictions, while revealing that ICL capability is a prerequisite for robustness. These findings advance the theoretical understanding of ICL under adversarial conditions and formalize the sense in which larger models are safer under distributional shift.