Transformers Learn to Achieve Second-Order Convergence Rates for In-Context Linear Regression

Deqing Fu, Tian-Qi Chen, Robin Jia, Vatsal Sharan
10/1/2023

No official code found. Best implementation: DeqingFu/transformers-icl-second-order (20 stars, last commit 2024-11-19).

Abstract

Transformers excel at in-context learning (ICL) -- learning from demonstrations without parameter updates -- but how they do so remains a mystery. Recent work suggests that Transformers may internally run Gradient Descent (GD), a first-order optimization method, to perform ICL. In this paper, we instead demonstrate that Transformers learn to approximate second-order optimization methods for ICL. For in-context linear regression, Transformers share a similar convergence rate as Iterative Newton's Method, both exponentially faster than GD. Empirically, predictions from successive Transformer layers closely match different iterations of Newton's Method linearly, with each middle layer roughly computing 3 iterations; thus, Transformers and Newton's method converge at roughly the same rate. In contrast, Gradient Descent converges exponentially more slowly. We also show that Transformers can learn in-context on ill-conditioned data, a setting where Gradient Descent struggles but Iterative Newton succeeds. Finally, to corroborate our empirical findings, we prove that Transformers can implement $k$ iterations of Newton's method with $k + \mathcal{O}(1)$ layers.

View on arXivView PDF

Code Implementations(1)

Official repository for our paper, Transformers Learn Higher-Order Optimization Methods for In-Context Learning: A Study with Linear Models.

203PythonJan 2, 20241 years ago

Cite this paper

@article{fu2023transformers,
  title  = {Transformers Learn to Achieve Second-Order Convergence Rates for In-Context Linear Regression},
  author = {Deqing Fu and Tian-Qi Chen and Robin Jia and Vatsal Sharan},
  year   = {2023},
  eprint = {2310.17086},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2310.17086},
  journal = {NEURIPS 2023 2023}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2310.17086.svg)](https://codeofpaper.com/paper/2310.17086)

Discussion