Transformers Can Implement Preconditioned Richardson Iteration for In-Context Gaussian Kernel Regression

TL;DR

This paper demonstrates that standard softmax-attention transformers can implement preconditioned Richardson iteration for Gaussian kernel ridge regression with prediction guarantees.

cs.LG 🔴 Advanced 2026-05-09 49 views
Mingsong Yan Dongyang Li Charles Kulick Sui Tang
deep learning transformers kernel ridge regression iterative algorithms theoretical analysis

Key Findings

Methodology

The study models the softmax attention transformer as executing preconditioned Richardson iteration on the dual kernel system. It constructs a single-head transformer where softmax normalization produces a row-normalized kernel matrix, serving as a preconditioner, while MLP layers locally approximate scalar operations needed for iterative updates. The architecture’s depth corresponds to iteration count, and width controls approximation accuracy. Theoretical proofs establish that such a transformer approximates the KRR predictor within ε error, with error trajectories matching classical Richardson iteration. Empirical validation on Gaussian process regression tasks confirms the model’s layer-wise predictions align with iterative solver outputs.

Key Results

  • The constructed transformer with depth O(log(1/ε)) and width O(pN/ε) achieves ε-accurate predictions for prompts of length N=40. Error profiles closely follow those of preconditioned Richardson iteration, outperforming gradient descent and conjugate gradient methods in convergence speed and stability.
  • Experiments across multiple Gaussian process datasets show the layer-wise error trajectories of trained GPT-style models match the iterative steps of Richardson iteration, validating the mechanistic interpretation.
  • Ablation studies confirm the importance of softmax normalization and Gaussian kernel; replacing or removing these components significantly degrades the approximation quality.

Significance

This work provides a rigorous theoretical foundation linking softmax-attention transformers to classical numerical algorithms, specifically preconditioned Richardson iteration. It advances understanding of how deep models can perform controlled, convergent iterative computations for nonlinear regression tasks, bridging deep learning and numerical analysis. The results open avenues for designing interpretable, provably convergent transformer architectures for scientific computing, large-scale regression, and beyond, with implications for explainability and robustness in AI systems.

Technical Contribution

The paper introduces a novel interpretation of softmax attention as implementing row-normalized kernel matrix-vector products, with MLP layers approximating scalar arithmetic. It constructs a transformer that performs inexact preconditioned Richardson iteration, with explicit depth and width bounds tied to convergence rate and approximation error. Theoretical analysis provides end-to-end prediction guarantees, and empirical results validate the mechanism’s universality across data distributions. This bridges the gap between classical iterative solvers and modern transformer architectures, offering a new perspective on their computational capabilities.

Novelty

This is the first work to explicitly connect standard softmax-attention transformers with a convergent iterative solver—preconditioned Richardson iteration—for nonlinear kernel regression, providing both a mechanistic explanation and theoretical guarantees. Unlike prior studies limited to linear tasks or kernelized attention, this work demonstrates how the standard architecture can perform controlled numerical computations, fundamentally expanding the understanding of transformer capabilities.

Limitations

  • The theoretical guarantees rely on bounded data assumptions and specific kernel choices, which may limit applicability in more complex, real-world scenarios. The model’s performance in high-dimensional or non-Gaussian settings remains to be tested.
  • The approach focuses on single-head transformers with specific input augmentations; extending to multi-head or more general architectures requires further research.
  • Computational costs grow with the desired accuracy, and the approximation relies on specific smoothness properties of the scalar functions, which may not hold universally.

Future Work

Future directions include extending the mechanism to multi-head transformers, exploring other kernels beyond Gaussian, and analyzing training dynamics to understand how such iterative algorithms emerge during learning. Additionally, applying this framework to large-scale scientific computations and real-world regression tasks could significantly impact AI’s role in scientific discovery and engineering.

AI Executive Summary

Transformers have revolutionized many AI applications, yet their internal mechanisms remain largely opaque. This paper uncovers a fundamental computational principle: standard softmax-attention transformers can implement classical iterative algorithms—specifically, preconditioned Richardson iteration—for solving Gaussian kernel ridge regression problems. Through rigorous theoretical analysis, the authors demonstrate that a carefully constructed single-head transformer, with depth scaling as O(log(1/ε)) and width as O(pN/ε), can approximate the KRR predictor within ε error during its forward pass. The key insight is that softmax normalization produces a row-normalized kernel matrix acting as a preconditioner, while MLP layers locally approximate scalar operations necessary for iterative updates. Empirical experiments on Gaussian process regression datasets validate this mechanism, showing that the layer-wise error trajectories of trained GPT-style models align closely with classical Richardson iteration steps. This mechanistic understanding bridges deep learning and numerical linear algebra, providing a new lens to interpret transformer computations. The findings suggest that standard transformer architectures are capable of performing controlled, convergent numerical algorithms, opening avenues for designing interpretable, provably convergent models for scientific computing and nonlinear regression tasks. Despite these advances, the approach relies on assumptions about data bounds and kernel smoothness, and extending it to more complex settings remains an important future direction. Overall, this work significantly deepens our understanding of the algorithmic capabilities of transformers, with broad implications for AI theory and practice.

Deep Analysis

Background

Recent years have seen transformers dominate NLP and multi-modal tasks, yet their internal algorithms remain elusive. Early work linked transformer layers to optimization steps like gradient descent [von Oswald et al., 2023], but these often focused on linear tasks or simplified attention mechanisms. In kernel methods, attention has been associated with kernel functions or gradient flows [Cheng et al., 2024], but without end-to-end convergence guarantees. Nonlinear regression, especially Gaussian kernel ridge regression (KRR), offers a well-understood mathematical solution, making it an ideal testbed for mechanistic analysis. Prior studies have explored kernelized attention and functional gradient descent, but the precise algorithmic role of softmax attention in implementing iterative solvers for nonlinear problems has remained unclear. This paper advances the field by explicitly connecting the standard softmax attention mechanism to classical iterative algorithms, bridging the gap between deep learning architectures and numerical linear algebra.

Core Problem

The core challenge is whether a standard softmax-attention transformer can implement a convergent solver with prediction guarantees for nonlinear kernel ridge regression. Existing theories mainly address linear tasks or kernelized attention, leaving the role of softmax normalization in nonlinear settings ambiguous. The difficulty lies in interpreting the layered structure as an iterative algorithm, understanding how attention normalization corresponds to preconditioning, and how MLP layers approximate scalar operations. Clarifying this would not only deepen theoretical understanding but also enable the design of more interpretable and reliable models that can perform controlled numerical computations within the deep learning framework.

Innovation

This work’s key innovations include: 1) The mechanistic interpretation of softmax attention as implementing row-normalized kernel matrix-vector products, serving as a preconditioner in Richardson iteration. 2) The construction of a transformer architecture with explicit depth and width bounds that approximates the KRR solution with prediction error ε. 3) The theoretical proof linking layer-wise error trajectories to classical iterative solver steps, validated through empirical experiments. 4) Demonstrating that the combination of softmax normalization and Gaussian kernels is essential for the mechanism’s success, supported by ablation studies. These contributions collectively provide a new understanding of how deep models can perform controlled, convergent numerical algorithms.

Methodology

  • �� Formulate the Gaussian kernel ridge regression as a dual linear system (K + λI)w = y.
  • �� Design a single-head transformer with input preprocessing, including special tokens and feature augmentation.
  • �� Use softmax attention to produce row-normalized kernel matrices, acting as a preconditioner.
  • �� Implement iterative Richardson updates via transformer layers, with MLPs approximating scalar multiplications such as D−1w and D−1y.
  • �� Construct the network with depth O(log(1/ε)) to control convergence, and width O(pN/ε) to ensure accurate scalar approximations.
  • �� Theoretically analyze the error propagation, showing the network’s output converges to the KRR predictor within ε, with explicit bounds on depth and width.

Experiments

The experiments involve training GPT-2 style models on Gaussian process regression datasets with varying input distributions and prompt lengths. The models are evaluated by comparing layer-wise predictions with classical iterative solvers—preconditioned Richardson, conjugate gradient, gradient descent, and Nesterov methods. The primary focus is on whether the layer-wise error trajectories match those of Richardson iteration, which the results confirm. Ablation studies test the importance of softmax normalization and Gaussian kernels, showing that replacing these components weakens the mechanism. The experiments demonstrate the model’s ability to approximate the KRR solution with high accuracy, validating the theoretical claims across diverse data settings.

Results

The trained transformer achieves ε-accuracy with depth O(log(1/ε)) and width O(pN/ε), with error trajectories mirroring Richardson iteration steps. Layer-wise errors decrease smoothly, outperforming gradient-based methods in convergence speed. Ablation experiments reveal that removing softmax normalization or changing the kernel significantly impairs performance. Across multiple distributions, the model’s predictions closely follow classical iterative solver trajectories, confirming the mechanistic interpretation. These results establish that standard softmax attention can realize a convergent numerical solver for nonlinear regression.

Applications

The mechanism enables designing interpretable, provably convergent transformers for scientific computing, large-scale regression, and control tasks. It suggests that deep models can perform controlled numerical algorithms, opening new avenues in AI for physics simulations, inverse problems, and data-driven scientific discovery. The approach could be extended to multi-head architectures and other kernels, broadening its applicability in industry and research.

Limitations & Outlook

The analysis assumes bounded data and specific kernel functions, limiting immediate applicability to more complex, real-world data distributions. Extending the mechanism to high-dimensional, non-Gaussian kernels requires further theoretical development. Computational costs grow with desired accuracy, and the current construction relies on smooth scalar functions approximable by ReLU networks. Future work should address these limitations, explore robustness, and generalize to broader settings.

Plain Language Accessible to non-experts

想象你在厨房里做汤,锅里的食材代表数据点。每次你搅拌(变换器层)时,就像在用一种特别的调味方法,让汤变得更香、更均匀。传统的方法可能是一次性加入所有调料,容易过咸或不均匀。而这项研究发现,变换器就像用一种聪明的调味技巧——每次加入一点点调料,逐步调整,直到汤变得完美。每一层就像是一个调味步骤,慢慢让味道变得更好。这种方法让我们用深度学习模型,像厨师一样,逐步解决复杂的问题,既快又准,未来还能用在很多需要精细计算的场景中。

ELI14 Explained like you're 14

想象你在玩拼图游戏,每次你都试图把拼图拼得更像完整的图片。传统的方法可能是一次拼很多块,容易出错或者花费太多时间。这项研究发现,变换器就像用一种聪明的拼图技巧,每一层都在逐步调整拼图的位置,慢慢接近完整的图片。它用的“技巧”是通过一种特别的“算法”,让每一步都更接近目标,而不是盲目拼凑。这样,变换器可以在很短的时间内,拼出非常接近完美的图片。这个发现让我们知道,深度学习模型其实可以像聪明的拼图高手一样,逐步解决复杂问题,既快又准,未来还能用在很多需要精细计算的场景中。

Glossary

softmax注意力 (Softmax Attention)

一种通过softmax归一化的注意力机制,用于衡量不同token间的相关性,广泛应用于变换器中。

论文中用以实现核矩阵的行归一化,作为预条件器。

核岭回归 (Kernel Ridge Regression)

一种非线性回归方法,利用核函数将数据映射到高维空间,通过正则化求解线性系统。

作为研究的核心任务,模型目标是逼近其解。

预条件Richardson迭代 (Preconditioned Richardson Iteration)

一种线性系统的迭代求解方法,通过引入预条件器加快收敛速度。

被证明在变换器中实现,用于逼近核岭回归解。

高斯核 (Gaussian Kernel)

一种常用的核函数,定义为exp(−∥x−x′∥²/2v²),具有平滑性和局部性。

作为模型中的核函数,影响变换器的机制实现。

变换器深度 (Transformer Depth)

变换器中堆叠的层数,影响模型的表达能力和迭代次数。

与迭代次数对应,控制逼近误差。

Open Questions Unanswered questions from this research

  • 1 如何将该机制推广到多头变换器和不同核函数,仍需理论验证。
  • 2 在高维复杂数据和实际任务中的泛化能力尚未充分研究。

Abstract

Mechanistic accounts of in-context learning (ICL) have identified iterative algorithms for linear regression and related linear prediction tasks, often using linear or ReLU attention variants. For nonlinear ICL, prior work has related softmax and kernelized attention to functional-gradient-type dynamics, but it remains unclear whether a standard transformer with softmax attention can implement a convergent solver with an end-to-end prediction-error guarantee. In this paper, we study in-context kernel ridge regression (KRR) with Gaussian kernels and show that a standard softmax-attention transformer can approximate the KRR predictor during its forward pass by implementing preconditioned Richardson iteration on the associated kernel linear system. Under bounded-data assumptions, we construct a single-head transformer with $O(\log(1/ε))$ blocks and MLP width $O(\sqrt{N/ε})$ that achieves $ε$-accurate prediction for prompts of length $N$. Our construction reveals a functional decomposition within the transformer architecture: softmax attention produces a row-normalized Gaussian-kernel operator needed for cross-token interactions, while ReLU MLP layers act locally to approximate the intra-token scalar arithmetic required by the update. Empirically, we train GPT-2-style transformers on Gaussian-process regression tasks to further test the preconditioned Richardson interpretation. Through linear probing, we compare the transformer's layer-wise predictions with the step-wise outputs of classical KRR solvers and find that its error profiles align most consistently with preconditioned Richardson iteration. Ablation studies further support this interpretation. Together, our theory and experiments identify preconditioned Richardson iteration as a concrete mechanism that softmax-attention transformers can realize for nonlinear in-context Gaussian-kernel regression.

cs.LG cs.AI math.NA math.OC