arXiv:2611.22941cs.LGNov 2026

Manuscript Offprint

arXiv:2611.22941

A Transformer-Derived Iterative Preconditioner

Patrick Lutz, Themistoklis Haris, Aditya Gangrade, Venkatesh Saligrama

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Transformers trained on in-context prediction problems can learn known numerical algorithms, e.g., gradient descent. We go further, showing that their internal computations can reveal new algorithms with provable guarantees. A softmax-attention transformer trained to solve linear systems Xw=yXw=y implicitly improves matrix conditioning. Tracing XX⊤XX^{\top} reveals an iterative preconditioning primitive, which we develop into RAPID, a standalone algorithm requiring no learned components.

RAPID is an anytime preconditioner for symmetric positive definite (SPD) matrices, using randomized mixing and sparse local corrections to improve conditioning. Proof-of-concept experiments on synthetic and real-world problems consistently improve conditioning and reduce conjugate gradient iterations needed to reach a target accuracy. For a Haar-mixing idealization, we prove convergence to any fixed target condition number regardless of spectral distribution, with only logarithmic dependence on initial conditioning. Together, these results show how a transformer can discover a broadly applicable numerical algorithm.

1 Introduction

Transformers can learn from examples in their input at test time without updating their parameters, a capability known as in-context learning (Brown et al., 2020; Garg et al., 2022). Studies of in-context linear regression have shown that transformers can implement familiar numerical algorithms, including gradient descent, preconditioned gradient descent, and Newton-like methods (Akyürek et al., 2023; Von Oswald et al., 2023; Ahn et al., 2023; Fu et al., 2024). We ask:

Can studying learned transformer computations lead to new, general-purpose numerical algorithms that work independently of the transformer and beyond its training distribution?

We answer affirmatively by uncovering a new preconditioning primitive in a trained transformer’s computations and developing it into a standalone numerical algorithm.

The resulting algorithm: RAPID. Preconditioning is often crucial for efficiently solving symmetric positive definite (SPD) systems Ax=bAx=b. Conjugate gradient (CG) avoids direct factorization, but its convergence depends strongly on the spectrum of AA (Hestenes and Stiefel, 1952; Saad, 2003). Preconditioners improve convergence by transforming the system into an equivalent, better-conditioned one (Benzi, 2002; Wathen, 2015). Classical approaches often construct approximate factorizations, inverses, or surrogate operators (Meijerink and van der Vorst, 1981; Benzi et al., 1996).

We introduce RAPID (Randomized Anytime Preconditioning by Iterative Dynamics), which improves global conditioning through simple local corrections. Its key idea is to repeatedly randomize the coordinate system, exposing different matrix interactions that can be corrected locally. Specifically, RAPID alternates two steps. First, random orthogonal mixing redistributes matrix interactions without changing the spectrum. Second, each row selects its smallest off-diagonal entry and applies a sparse correction that acts to weaken the selected coupling. Repeating these steps allows local corrections to progressively improve global conditioning without explicitly computing eigenvectors or matrix inverses.

RAPID accumulates these transformations into a preconditioning factor PtP_{t}, yielding At=PtAPt⊤A_{t}=P_{t}AP_{t}^{\top}. Each iteration produces a valid preconditioner, making RAPID an anytime algorithm. Fast structured mixing and sparse corrections enable efficient, highly parallel dense implementations. The underlying update is derived from the trained transformer’s internal computation, as described next.

Algorithm discovery. We train a softmax-attention transformer on in-context linear systems Xw=yXw=y, where XX need not be SPD. Layerwise orthogonal symmetry interventions (Lutz et al., 2026) allow us to trace the evolution of the Gram matrix Gℓ=XℓXℓ⊤G_{\ell}=X_{\ell}X_{\ell}^{\top} during prediction. We observe that its conditioning improves and identify a simple learned congruence update responsible for this effect. Crucially, this update depends only on GℓG_{\ell}, allowing RAPID to operate directly on arbitrary SPD matrices without the cost of forming a Gram matrix.

The connection to RAPID follows naturally: the symmetry intervention introduces random rotations, while learned attention applies local corrections that tend to weaken strong matrix interactions. The residual update applies the same row transformation to examples and labels, inducing the congruence update. To obtain an efficient algorithm, RAPID takes the low-temperature limit of softmax to select sparse off-diagonal row-min corrections and replaces dense rotations with fast structured mixing (Yu et al., 2016). The resulting algorithm requires no learned components.

Results and guarantees. We evaluate RAPID on four synthetic spectral families and 3131 SuiteSparse SPD matrices, well beyond the transformer’s training distribution. RAPID substantially improves conditioning across all four families and, remarkably, on every SuiteSparse matrix at every tested step count. In contrast, randomized Nyström preconditioning is more sensitive to spectral structure. These improvements also translate into substantially fewer conjugate gradient (CG) iterations to reach a fixed accuracy. Progressive gains with additional RAPID steps illustrate its anytime nature.

Theoretically, we prove that an idealized version of RAPID, using Haar mixing and block-restricted row-min corrections, reaches any fixed target condition number in O(dlog⁡dlog⁡κ(A))O(d\log d\log\kappa(A)) expected iterations. This holds for any SPD matrix AA, regardless of its eigenvalue distribution. At this iteration scale, RAPID’s per-step cost of O(d2log⁡d)O(d^{2}\log d) corresponds to near-cubic setup complexity, comparable to classical dense factorization. Unlike direct factorization, however, RAPID can stop early to balance setup cost against preconditioner quality. Although the iteration-complexity guarantee remains limited to an idealized variant, experiments show that its assumptions do not accelerate conditioning on tested spectra, suggesting they facilitate the proof rather than the algorithm’s effectiveness.

Contributions. We make three core contributions:

  • We discover a new preconditioning primitive in a trained transformer: a solution-preserving update to the linear system Xw=yXw=y that improves the conditioning of the Gram matrix XX⊤XX^{\top}.
  • We develop this mechanism into RAPID, a standalone anytime preconditioner for arbitrary SPD matrices, requiring no learned components and using efficient, parallelizable iterations.
  • We establish theoretical and empirical evidence of RAPID’s effectiveness: an idealized variant provably reaches any fixed target condition number for arbitrary SPD matrices, while dense experiments demonstrate broad conditioning gains and substantially faster CG convergence.