The Initialization Determines Whether In-Context Learning Is Gradient Descent
Shifeng Xie, Rui Yuan, Simone Rossi, Thomas Hannagan
TL;DR
This work interrogates the claim that in-context learning in large language models is equivalent to gradient descent, focusing on non-zero prior means in a linear regression setting. It shows that multi-head linear self-attention cannot generally replicate one-step GD when priors have non-zero mean, and identifies the query’s initial guess y_q as the crucial factor for closing the gap. To address this, the paper introduces y_q-LSA, a minimal input-side extension with a trainable initial guess that restores GD-equivalence, supported by theory and synthetic experiments. It also provides proof-of-concept evidence that explicit initial guesses can improve ICL in large language models on semantic similarity tasks. The results offer a principled avenue to enhance ICL via prompting strategies and lay groundwork for extending GD-level analyses to more complex transformer architectures.
Abstract
In-context learning (ICL) in large language models (LLMs) is a striking phenomenon, yet its underlying mechanisms remain only partially understood. Previous work connects linear self-attention (LSA) to gradient descent (GD), this connection has primarily been established under simplified conditions with zero-mean Gaussian priors and zero initialization for GD. However, subsequent studies have challenged this simplified view by highlighting its overly restrictive assumptions, demonstrating instead that under conditions such as multi-layer or nonlinear attention, self-attention performs optimization-like inference, akin to but distinct from GD. We investigate how multi-head LSA approximates GD under more realistic conditions specifically when incorporating non-zero Gaussian prior means in linear regression formulations of ICL. We first extend multi-head LSA embedding matrix by introducing an initial estimation of the query, referred to as the initial guess. We prove an upper bound on the number of heads needed for ICL linear regression setup. Our experiments confirm this result and further observe that a performance gap between one-step GD and multi-head LSA persists. To address this gap, we introduce yq-LSA, a simple generalization of single-head LSA with a trainable initial guess yq. We theoretically establish the capabilities of yq-LSA and provide experimental validation on linear regression tasks, thereby extending the theory that bridges ICL and GD. Finally, inspired by our findings in the case of linear regression, we consider widespread LLMs augmented with initial guess capabilities, and show that their performance is improved on a semantic similarity task.
