Transformers Implement Functional Gradient Descent to Learn Non-Linear Functions In Context
Xiang Cheng, Yuxin Chen, Suvrit Sra
TL;DR
This work shows that non-linear Transformers can learn to implement gradient descent in function space by performing functional gradient descent in RKHS via carefully configured attention modules. When the attention nonlinearity matches a generating kernel, the Transformer can converge to Bayes-optimal predictors in in-context learning, with multi-head attention enabling a broad class of composite kernels. The authors provide a constructive RKHS-based mechanism, theoretical results on stationary points under sparsity and full-attention regimes, and extensive simulations demonstrating the learned mechanisms and the dependence of optimality on the chosen nonlinearity. They also discuss the implications for representation power, including kernel composition and the potential for improved guarantees, suggesting practical and theoretical avenues for future research.
Abstract
Many neural network architectures are known to be Turing Complete, and can thus, in principle implement arbitrary algorithms. However, Transformers are unique in that they can implement gradient-based learning algorithms under simple parameter configurations. This paper provides theoretical and empirical evidence that (non-linear) Transformers naturally learn to implement gradient descent in function space, which in turn enable them to learn non-linear functions in context. Our results apply to a broad class of combinations of non-linear architectures and non-linear in-context learning tasks. Additionally, we show that the optimal choice of non-linear activation depends in a natural way on the class of functions that need to be learned.
