MetaRepICL: In-Context Learning as Kernel Regression on Learned Representations
MetaRepICL: In-Context Learning as Kernel Regression on Learned Representations
Question
A transformer performing in-context learning (ICL) takes a sequence of pairs followed by a query and produces a prediction --- all without updating its weights. Recent theory has shown that single-layer linear attention implements one step of gradient descent on a least-squares objective, and by extension, that a depth- linear-attention transformer implements steps of preconditioned gradient descent, which converges to the kernel ridge regression (KRR) solution.
We ask whether this connection extends to trained transformers with softmax attention operating on learned representations.
Approach
The project has two aims:
Aim 1: Constructive mapping (linear attention). We build an explicit transformer architecture whose layers exactly implement conjugate gradient (CG) iterations for solving the KRR normal equations , where is the kernel matrix over support representations. The construction uses:
- Attention heads that compute kernel matrix-vector products via query-key-value projections over support tokens
- Aggregator tokens that compute global reductions (residual norms, step sizes)
- MLP blocks that perform the per-token CG state updates ()
This demonstrates that a linear-attention transformer of depth can represent -step CG --- which converges at a rate determined by the condition number of --- and therefore approximates KRR to arbitrary precision given sufficient depth.
Aim 2: Softmax extension. Softmax attention computes , which induces an exponential kernel rather than a linear one. We study whether the softmax-attention ICL prediction matches KRR under this exponential kernel, measuring operator-norm proximity on the support set.
Current findings
- The constructive CG mapping works: a hand-wired linear-attention stack converges to the KRR solution at the expected CG rate on synthetic tasks.
- Width matters: under a rank- random projection (simulating finite head dimension), prediction error approaches the oracle as increases, tracking the effective dimension .
- The softmax-kernel alignment holds for in-distribution tasks but degrades on out-of-distribution prompts, suggesting the learned kernel specializes to the training distribution.
Takeaway
The connection between ICL and kernel regression is not merely an analogy: for linear attention, it is an exact correspondence mediated by conjugate gradient. The softmax case introduces an exponential kernel that the transformer approximates but does not exactly implement. Understanding this gap --- when it is small and when it blows up --- is key to predicting where ICL will succeed and where it will fail silently.