How Transformers Utilize Multi-Head Attention in In-Context Learning? A Case Study on Sparse Linear Regression
Not on the map. Why?
Abstract (arXiv)
Despite the remarkable success of transformer-based models in various real-world tasks, their underlying mechanisms remain poorly understood. Recent studies have suggested that transformers can implement gradient descent as an in-context learner for linear regression problems and have developed various theoretical analyses accordingly. However, these works mostly focus on the expressive power of transformers by designing specific parameter constructions, lacking a comprehensive understanding of their inherent working mechanisms post-training. In this study, we consider a sparse linear regression problem and investigate how a trained multi-head transformer performs in-context learning. We experimentally discover that the utilization of multi-heads exhibits different patterns across layers: multiple heads are utilized and essential in the first layer, while usually only a single head is sufficient for subsequent layers. We provide a theoretical explanation for this observation: the first layer preprocesses the context data, and the following layers execute simple optimization steps based on the preprocessed context. Moreover, we demonstrate that such a preprocess-then-optimize algorithm can significantly outperform naive gradient descent and ridge regression algorithms. Further experimental results support our explanations. Our findings offer insights into the benefits of multi-head attention and contribute to understanding the more intricate mechanisms hidden within trained transformers.
Key facts. Cited by 13 papers in the map (data through 7 Oct 2026). Builds on 52 of its 57 references that are in the map. First posted on arXiv 8 Aug 2024.
Builds on
52 of 57 references.
References · 52
- 2017Attention Is All You Needcited by 59,932
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2023GPT-4 Technical Reportcited by 18,132
- 2022Training language models to follow instructions with human feedbackcited by 15,712
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
- 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
- 2019HuggingFace's Transformers: State-of-the-art Natural Language Processingcited by 2,201
- 2016Understanding intermediate layers using linear classifier probescited by 1,279
- 2016Pruning Filters for Efficient ConvNetscited by 1,129
- 2021An Explanation of In-context Learning as Implicit Bayesian Inferencecited by 915
- 2022Transformers learn in-context by gradient descentcited by 714
- 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 700
38 more
- 2022What learning algorithm is in-context learning? Investigations with linear modelscited by 671
- 2019Benign Overfitting in Linear Regressioncited by 544
- 2024ShortGPT: Layers in Large Language Models are More Redundant Than You Expectcited by 369
- 2023Trained Transformers Learn Linear Models In-Contextcited by 331
- 2023Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selectioncited by 291
- 2023Transformers learn to implement preconditioned gradient descent for in-context learningcited by 274
- 2023Physics of Language Models: Part 3.1, Knowledge Storage and Extractioncited by 264
- 2022Transformers Learn Shortcuts to Automatacited by 260
- 2023Looped Transformers as Programmable Computerscited by 224
- 2023Transformers as Algorithms: Generalization and Stability in In-context Learningcited by 220
- 2024The Unreasonable Ineffectiveness of the Deeper Layerscited by 219
- 2023What Algorithms can Transformers Learn? A Study in Length Generalizationcited by 198
- 2021Thinking Like Transformerscited by 182
- 2023One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-Attentioncited by 168
- 2020Benign overfitting in ridge regressioncited by 152
- 2023Physics of Language Models: Part 3.2, Knowledge Manipulationcited by 142
- 2024How Transformers Learn Causal Structure with Gradient Descentcited by 114
- 2023In-Context Convergence of Transformerscited by 112
- 2020Perturbed Masking: Parameter-free Probing for Analyzing and Interpreting BERTcited by 109
- 2023Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformercited by 101
- 2023Tracr: Compiled Transformers as a Laboratory for Interpretabilitycited by 99
- 2023How Many Pretraining Tasks Are Needed for In-Context Learning of Linear Regression?cited by 93
- 2023How Do Transformers Learn Topic Structure: Towards a Mechanistic Understandingcited by 85
- 2023How Do Transformers Learn In-Context Beyond Simple Functions? A Case Study on Learning with Representationscited by 72
- 2024Training Dynamics of Multi-Head Softmax Attention for In-Context Learning: Emergence, Convergence, and Optimalitycited by 71
- 2023Transformers as Support Vector Machinescited by 67
- 2023Transformers Implement Functional Gradient Descent to Learn Non-Linear Functions In Contextcited by 63
- 2023Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators?cited by 46
- 2023Learning Transformer Programscited by 40
- 2023Memorization Capacity of Multi-Head Attention in Transformerscited by 39
- 2021The Benefits of Implicit Regularization from SGD in Least Squares Problemscited by 32
- 2023Approximation and Estimation Ability of Transformers for Sequence-to-Sequence Functions with Infinite Dimensional Inputcited by 32
- 2024In-Context Learning of a Linear Transformer Block: Benefits of the MLP Component and One-Step GD Initializationcited by 30
- 2023CausalLM is not optimal for in-context learningcited by 26
- 2024How Well Can Transformers Emulate In-context Newton's Method?cited by 23
- 2024What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning Taskscited by 19
- 2023A Mechanism for Sample-Efficient In-Context Learning for Sparse Retrieval Taskscited by 17
- 2024Superiority of Multi-Head Attention in In-Context Linear Regressioncited by 17
50 most cited of 52 All 52 (JSON)
Built on by
Citing papers per year: 2024: 2; 2025: 10; 2026: 1.
13 papers.
Sort:
By area:
- 2025Towards Understanding Fine-Tuning Mechanisms of LLMs via Circuit Analysiscited by 20
- 2025Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidencecited by 13
- 2025Contextualize-then-Aggregate: Circuits for In-Context Learning in Gemma-2 2Bcited by 10
- 2024On the Learn-to-Optimize Capabilities of Transformers in In-Context Sparse Recoverycited by 6
- 2025On the Robustness of Transformers against Context Hijacking for Linear Classificationcited by 4
- 2025Improving Model Representation and Reducing KV Cache via Skip Connections with First Value Headscited by 4
- 2025Transformers versus the EM Algorithm in Multi-class Clusteringcited by 3
- 2025The Initialization Determines Whether In-Context Learning Is Gradient Descentcited by 3
- 2025Multi-Layer Attention is the Amplifier of Demonstration Effectivenesscited by 1
- 2025Towards Theoretical Understanding of Transformer Test-Time Computing: Investigation on In-Context Linear Regressioncited by 1
- 2026Provable and Practical In-Context Policy Optimization for Self-Improvementcited by 1
- 2024Toward generalizable learning of all (linear) first-order methods via memory augmented Transformerscited by 0
- 2026Provable and Practical In-Context Policy Optimization for Self-Improvement2 Mar 2026
- 2025The Initialization Determines Whether In-Context Learning Is Gradient Descent3 Dec 2025
- 2025Improving Model Representation and Reducing KV Cache via Skip Connections with First Value Heads19 Oct 2025
- 2025First Attentions Last: Better Exploiting First Attentions for Efficient Transformer Training16 Oct 2025
- 2025Towards Theoretical Understanding of Transformer Test-Time Computing: Investigation on In-Context Linear Regression11 Aug 2025
- 2025Multi-Layer Attention is the Amplifier of Demonstration Effectiveness1 Aug 2025
- 2025Contextualize-then-Aggregate: Circuits for In-Context Learning in Gemma-2 2B31 Mar 2025
- 2025On the Robustness of Transformers against Context Hijacking for Linear Classification21 Feb 2025
- 2025Towards Understanding Fine-Tuning Mechanisms of LLMs via Circuit Analysis17 Feb 2025
- 2025Transformers versus the EM Algorithm in Multi-class Clustering9 Feb 2025
- 2025Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidence6 Feb 2025
- 2024On the Learn-to-Optimize Capabilities of Transformers in In-Context Sparse Recovery17 Oct 2024
- 2025Towards Understanding Fine-Tuning Mechanisms of LLMs via Circuit Analysiscited by 20
- 2025Contextualize-then-Aggregate: Circuits for In-Context Learning in Gemma-2 2Bcited by 10
- 2024On the Learn-to-Optimize Capabilities of Transformers in In-Context Sparse Recoverycited by 6
- 2025On the Robustness of Transformers against Context Hijacking for Linear Classificationcited by 4
- 2025Transformers versus the EM Algorithm in Multi-class Clusteringcited by 3
- 2025The Initialization Determines Whether In-Context Learning Is Gradient Descentcited by 3
- 2025Multi-Layer Attention is the Amplifier of Demonstration Effectivenesscited by 1
- 2025Towards Theoretical Understanding of Transformer Test-Time Computing: Investigation on In-Context Linear Regressioncited by 1
- 2025First Attentions Last: Better Exploiting First Attentions for Efficient Transformer Trainingcited by 0
- 2025The Initialization Determines Whether In-Context Learning Is Gradient Descent3 Dec 2025
- 2025First Attentions Last: Better Exploiting First Attentions for Efficient Transformer Training16 Oct 2025
- 2025Towards Theoretical Understanding of Transformer Test-Time Computing: Investigation on In-Context Linear Regression11 Aug 2025
- 2025Multi-Layer Attention is the Amplifier of Demonstration Effectiveness1 Aug 2025
- 2025Contextualize-then-Aggregate: Circuits for In-Context Learning in Gemma-2 2B31 Mar 2025
- 2025On the Robustness of Transformers against Context Hijacking for Linear Classification21 Feb 2025
- 2025Towards Understanding Fine-Tuning Mechanisms of LLMs via Circuit Analysis17 Feb 2025
- 2025Transformers versus the EM Algorithm in Multi-class Clustering9 Feb 2025
- 2024On the Learn-to-Optimize Capabilities of Transformers in In-Context Sparse Recovery17 Oct 2024