cs.LGSep 29, 2026

Theory on Attention Dynamics for Out-of-Distribution In-Context Learning

Authors: Junze Deng, Daouda Sow, Sen Lin, Yingbin Liang

Organizations: Ohio State University Ohio, USA · University of Houston Houston, USA

Abstract

Transformers have demonstrated remarkable in-context learning (ICL) capabilities, enabling them to perform new tasks without additional fine-tuning. However, their performance often deteriorates when encountering out-of-distribution (OOD) inputs that deviate from the training distribution, and the underlying theory remains poorly understood. To fill this gap, we characterize the OOD error under the input distribution shift through the interplay between the dynamics of the so-called αα-type and ββ-type attention weights, which represent the transformer's confidence in identifying the correct and incorrect features, respectively. Our results indicate that the OOD error for each feature depends on all pairwise interactions between the training features and OOD features, and under certain cases the transformer performs no better than random guessing. To improve the OOD generalization performance, we next investigate the impact of model finetuning with the OOD data, and particularly, characterize the model forgetting performance on the source domain. Interestingly, the performance on the source domain may not always degrade after finetuning, which highly depends on the nature of the feature shift: finetuning on OOD domain keeps enhancing the confidence of identifying correct features from the original distribution, while the interference from other incorrect features may either increase or decrease. Extensive experiments on both synthetic and real data are conducted to corroborate the theoretical insights.

Figures & tables

Appendix figures & tables3 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. At the Edge of Understanding: Sparse Autoencoders Trace The Limits of Transformer Generalization

    Jun 24, 2026Praneet Suresh, Jack Stanley, Sonia Joseph +2Distribution Shift RobustnessTransformer Interpretability

  2. Fine-Tuning Without Forgetting In-Context Learning: A Theoretical Analysis of Linear Attention Models

    Feb 26, 2026Chungpa Lee, Jy-yong Sohn, Kangwook LeeLLM Fine-TuningIn-Context Learning

  3. The Effect of Training Task Diversity on In-Context Learning through the Lens of Low-Dimensional Subspaces

    Jun 5, 2026Soo Min Kwon, Alec S. Xu, Can Yaras +3OOD GeneralizationTransformer Attention