In-Context Linear Regression Demystified: Training Dynamics and Mechanistic Interpretability of Multi-Head Softmax Attention
On the map: Mechanistic interpretability → Circuits and mechanistic analysis
Abstract (arXiv)
We study how multi-head softmax attention models are trained to perform in-context learning on linear data. Through extensive empirical experiments and rigorous theoretical analysis, we demystify the emergence of elegant attention patterns: a diagonal and homogeneous pattern in the key-query (KQ) weights, and a last-entry-only and zero-sum pattern in the output-value (OV) weights. Remarkably, these patterns consistently appear from gradient-based training starting from random initialization. Our analysis reveals that such emergent structures enable multi-head attention to approximately implement a debiased gradient descent predictor -- one that outperforms single-head attention and nearly achieves Bayesian optimality up to proportional factor. Furthermore, compared to linear transformers, the softmax attention readily generalizes to sequences longer than those seen during training. We also extend our study to scenarios with anisotropic covariates and multi-task linear regression. In the former, multi-head attention learns to implement a form of pre-conditioned gradient descent. In the latter, we uncover an intriguing regime where the interplay between head number and task number triggers a superposition phenomenon that efficiently resolves multi-task in-context learning. Our results reveal that in-context learning ability emerges from the trained transformer as an aggregated effect of its architecture and the underlying data distribution, paving the way for deeper understanding and broader applications of in-context learning.
Key facts. Cited by 7 papers in the map (data through 14 Oct 2026). Placed in Circuits and mechanistic analysis, one of 13 directions in Mechanistic interpretability. First posted on arXiv 17 Mar 2025.
Builds on
0 of 0 references.
No references here yet.
Built on by
Citing papers per year: 2025: 3; 2026: 4.
7 papers.
- 2025Mechanistic Interpretability of Fine-Tuned Vision Transformers on Distorted Images: Decoding Attention Head Behavior for Transparent and Trustworthy AIcited by 5
- 2025Softmax as Linear Attention in the Large-Prompt Regime: a Measure-based Perspectivecited by 3
- 2026In-Context Learning Operates as Concept Subspace Learningcited by 3
- 2025How Can Mamba Learn In Context with Outliers and Generalize Provably?cited by 2
- 2026Demonstrations, CoT, and Prompting: A Theoretical Analysis of ICLcited by 0
- 2026Transformers Trained via Gradient Descent Can Provably Learn a Class of Teacher Modelscited by 0
- 2026When Does Depth Matter For In-Context Learning? Adaptive Inference in Deep Transformerscited by 0
- 2026When Does Depth Matter For In-Context Learning? Adaptive Inference in Deep Transformers15 Jun 2026
- 2026In-Context Learning Operates as Concept Subspace Learning12 May 2026
- 2026Transformers Trained via Gradient Descent Can Provably Learn a Class of Teacher Models24 Mar 2026
- 2026Demonstrations, CoT, and Prompting: A Theoretical Analysis of ICL20 Mar 2026
- 2025Softmax as Linear Attention in the Large-Prompt Regime: a Measure-based Perspective12 Dec 2025
- 2025How Can Mamba Learn In Context with Outliers and Generalize Provably?1 Oct 2025
- 2025Mechanistic Interpretability of Fine-Tuned Vision Transformers on Distorted Images: Decoding Attention Head Behavior for Transparent and Trustworthy AI24 Mar 2025
Similar, not cited
Close in wording, no citation either way
- 2024Understanding the differences in Foundation Models: Attention, State Space Models, and Recurrent Neural Networks
- 2024Fine-grained Analysis of In-context Linear Estimation: Data, Architecture, and Beyond
- 2026State Rank Dynamics in Linear Attention LLMs
- 2026Induction Heads Interpolate N-Grams
- 2026Underscoring the Problem: Why Softpick Fails at Initialization
- 2026Switching Linear Attention
- 2024From Attention to Activation: Unravelling the Enigmas of Large Language Models
- 2025Localizing Task Recognition and Task Learning in In-Context Learning via Attention Head Analysis