Understanding In-Context Learning of Linear Models in Transformers Through an Adversarial Lens
Not on the map. Why?
Abstract (arXiv)
In this work, we make two contributions towards understanding of in-context learning of linear models by transformers. First, we investigate the adversarial robustness of in-context learning in transformers to hijacking attacks -- a type of adversarial attacks in which the adversary's goal is to manipulate the prompt to force the transformer to generate a specific output. We show that both linear transformers and transformers with GPT-2 architectures are vulnerable to such hijacking attacks. However, adversarial robustness to such attacks can be significantly improved through adversarial training -- done either at the pretraining or finetuning stage -- and can generalize to stronger attack models. Our second main contribution is a comparative analysis of adversarial vulnerabilities across transformer models and other algorithms for learning linear models. This reveals two novel findings. First, adversarial attacks transfer poorly between larger transformer models trained from different seeds despite achieving similar in-distribution performance. This suggests that transformers of the same architecture trained according to the same recipe may implement different in-context learning algorithms for the same task. Second, we observe that attacks do not transfer well between classical learning algorithms for linear models (single-step gradient descent and ordinary least squares) and transformers. This suggests that there could be qualitative differences between the in-context learning algorithms that transformers implement and these traditional algorithms.
Key facts. Cited by 8 papers in the map (data through 14 Oct 2026). Builds on 39 of its 47 references that are in the map. First posted on arXiv 7 Nov 2024.
Builds on
39 of 47 references.
References · 39
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2014Explaining and Harnessing Adversarial Examplescited by 7,364
- 2017Towards Deep Learning Models Resistant to Adversarial Attackscited by 6,415
- 2020Transformers are RNNs: Fast Autoregressive Transformers with Linear Attentioncited by 2,022
- 2021Decision Transformer: Reinforcement Learning via Sequence Modelingcited by 1,546
- 2019Theoretically Principled Trade-off between Robustness and Accuracycited by 1,517
- 2022Transformers learn in-context by gradient descentcited by 732
- 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 715
- 2022What learning algorithm is in-context learning? Investigations with linear modelscited by 684
- 2022TabPFN: A Transformer That Solves Small Tabular Classification Problems in a Secondcited by 674
- 2016Delving into Transferable Adversarial Examples and Black-box Attackscited by 536
- 2021Linear Transformers Are Secretly Fast Weight Programmerscited by 502
27 more
- 2016Learning to reinforcement learncited by 377
- 2023Trained Transformers Learn Linear Models In-Contextcited by 337
- 2023Can Generalist Foundation Models Outcompete Special-Purpose Tuning? Case Study in Medicinecited by 329
- 2023Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selectioncited by 298
- 2023Transformers learn to implement preconditioned gradient descent for in-context learningcited by 279
- 2022Visual Prompting via Image Inpaintingcited by 250
- 2024Foundational Challenges in Assuring Alignment and Safety of Large Language Modelscited by 199
- 2023Image Hijacks: Adversarial Images can Control Generative Models at Runtimecited by 172
- 2023What Makes Good Examples for Visual In-Context Learning?cited by 150
- 2023Human-Timescale Adaptation in an Open-Ended Task Spacecited by 138
- 2022General-Purpose In-Context Learning by Meta-Learning Transformerscited by 105
- 2019Recent Advances in Algorithmic High-Dimensional Robust Statisticscited by 101
- 2023How Many Pretraining Tasks Are Needed for In-Context Learning of Linear Regression?cited by 96
- 2018Efficient Algorithms and Lower Bounds for Robust Linear Regressioncited by 76
- 2018Efficient Algorithms for Outlier-Robust Regressioncited by 72
- 2024LLM Processes: Numerical Predictive Distributions Conditioned on Natural Languagecited by 55
- 2020Meta Learning Backpropagation And Improving Itcited by 49
- 2023Hijacking Large Language Models via Adversarial In-Context Learningcited by 45
- 2015Robust Regression via Hard Thresholdingcited by 39
- 2023Generalization to New Sequential Decision Making Tasks with In-Context Learningcited by 39
- 2024Adversarial Robustness Limits via Scaling-Law and Human-Alignment Studiescited by 38
- 2020Optimal Robust Linear Regression in Nearly Linear Timecited by 32
- 2024Linear Transformers are Versatile In-Context Learnerscited by 28
- 2019Adaptive Hard Thresholding for Near-optimal Consistent Robust Regressioncited by 23
- 2023The Double-Edged Sword of Implicit Bias: Generalization vs. Robustness in ReLU Networkscited by 23
- 2024Data Poisoning for In-context Learningcited by 21
- 2024In-Context In-Context Learning with Transformer Neural Processescited by 4
Built on by
Citing papers per year: 2025: 3; 2026: 5.
8 papers.
- 2025Robustness in Large Language Models: A Survey of Mitigation Strategies and Evaluation Metricscited by 12
- 2025How Can Mamba Learn In Context with Outliers and Generalize Provably?cited by 2
- 2026Transformers Learn Robust In-Context Regression under Distributional Uncertaintycited by 1
- 2026Understanding and Improving Continuous Adversarial Training for LLMs via In-context Learning Theorycited by 1
- 2026Transformers Efficiently Perform In-Context Logistic Regression via Normalized Gradient Descentcited by 1
- 2025How Private is Your Attention? Bridging Privacy with In-Context Learningcited by 0
- 2026Taming Visual Neglect: A Variational Information Bottleneck Framework for Adaptive Attention in Multimodal In-Context Learningcited by 0
- 2026Theory on Attention Dynamics for Out-of-Distribution In-Context Learningcited by 0
- 2026Theory on Attention Dynamics for Out-of-Distribution In-Context Learning29 Sep 2026
- 2026Taming Visual Neglect: A Variational Information Bottleneck Framework for Adaptive Attention in Multimodal In-Context Learning14 Jun 2026
- 2026Transformers Efficiently Perform In-Context Logistic Regression via Normalized Gradient Descent7 May 2026
- 2026Understanding and Improving Continuous Adversarial Training for LLMs via In-context Learning Theory14 Apr 2026
- 2026Transformers Learn Robust In-Context Regression under Distributional Uncertainty19 Mar 2026
- 2025How Can Mamba Learn In Context with Outliers and Generalize Provably?1 Oct 2025
- 2025Robustness in Large Language Models: A Survey of Mitigation Strategies and Evaluation Metrics24 May 2025
- 2025How Private is Your Attention? Bridging Privacy with In-Context Learning22 Apr 2025