NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-Attention

Arvind V. Mahankali, Tatsunori B. Hashimoto, Tengyu Ma · DOI

Introduction

Large Language Models (LLMs) possess the remarkable ability to perform In-Context Learning (ICL), where they adapt to new tasks provided in a prompt without explicit weight updates. While empirical evidence has suggested that transformers trained on synthetic regression tasks learn to implement algorithms like Gradient Descent (GD), the theoretical justification for why this specific behavior emerges as the optimal solution has remained elusive. This paper provides a formal mathematical proof that for a one-layer transformer with linear self-attention, the global minimum of the training loss is exactly equivalent to performing one step of gradient descent on the in-context examples.

Problem Formulation

The researchers investigate a simplified transformer architecture: a single layer utilizing linear self-attention, omitting softmax and multi-layer perceptron (MLP) components. The model is trained on a "meta-learning" objective: given a sequence of input-output pairs $(x_1, y_1, \dots, x_n, y_n)$ and a query $x_{n+1}$, the model must predict $y_{n+1}$.

The study focuses on linear regression tasks where $y_i = w^\top x_i + \epsilon$. The goal is to understand the relationship between the transformer's weight matrices ($W_K, W_Q, W_V$) and the resulting prediction function when the model is optimized to minimize its prediction error across many such tasks.

The Transformer as an Implicit Optimizer

The core contribution of the paper is the mathematical mapping of the transformer's operations to the steps of an optimization algorithm. By analyzing the expected error (pre-training loss) over the distribution of regression tasks, the authors derive several key theorems regarding the model's global minima.

Theorem 1: Standard Gradient Descent

In the simplest case, where input vectors $x_i$ are sampled from a standard Gaussian distribution (isotropic), the authors prove that the weights minimizing the pre-training loss result in a model that implements exactly one step of Gradient Descent. Specifically, the transformer uses the in-context examples to estimate the gradient of a least-squares objective and updates an initial weight estimate accordingly.

Theorem 2: Pre-conditioned Gradient Descent

When the input features are non-isotropic (i.e., they have a skewed covariance matrix $\Sigma$), the optimal learner adapts. Instead of basic GD, the transformer implements pre-conditioned gradient descent. It effectively uses $\Sigma^{-1}$ as a pre-conditioner to "whiten" the data, accounting for correlations between features to achieve a more accurate prediction. This demonstrates that the transformer architecture is naturally sensitive to the geometry of the data distribution.

Theorem 3: Robustness to Nonlinearity

Perhaps most surprisingly, the paper extends the analysis to nonlinear target functions. Even when the relationship between $x$ and $y$ is generated by a complex function (such as a random neural network), a one-layer linear transformer still converges to a solution that implements a single step of linear gradient descent. This suggests that the model's architecture imposes a strict "inductive bias," forcing it to approximate complex functions through the lens of linear optimization.

Discussion: Architecture as Inductive Bias

The findings suggest that training a transformer is essentially a form of "meta-training" an optimizer. The transformer does not merely memorize patterns; its internal circuitry is mathematically structured to perform iterative optimization. However, this ability is constrained by the architecture. A single linear layer is limited to a single step of GD. This provides a theoretical baseline for understanding how more complex architectures—those with multiple layers and nonlinear attention—might implement more sophisticated algorithms like multi-step GD or Newton's method.

Conclusion and Future Work

This work bridges the gap between the empirical success of ICL and the theoretical understanding of transformer dynamics. By proving that one step of GD is the optimal strategy for a one-layer linear model, the authors provide a foundation for future research into multi-layer and Softmax-based transformers. Understanding how these components interact to perform complex, iterative reasoning remains a primary challenge in the quest to fully decode the "black box" of Large Language Models.

Summary updated

BibTeX
@inproceedings{mahankali2024one,
  author = {Arvind V. Mahankali and Tatsunori B. Hashimoto and Tengyu Ma},
  title = {{One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-Attention}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=8p3fu56lKc},
}
Figure