Understanding and Relaxing the Limitations of Transformers for Linear Algebra

Andres Potapczynski, Alex Ali, Andrew Gordon WilsonICLR 2026

TL;DR

Standard Transformers are surprisingly poor at basic linear algebra, often acting as "statistical interpolators" that memorize data distributions rather than learning actual algorithms. This paper introduces RangeFormer, a redesigned architecture that uses learnable projections, linear attention, and diverse structured data to solve matrix operations at scales up to $1000 \times 1000$ while generalizing to real-world engineering problems.

What Problem Does This Paper Address?

Linear algebra—operations like matrix inversion, eigendecomposition, and calculating determinants—is the "engine room" of modern science and engineering. If Transformers are to become truly general-purpose intelligent systems, they must be able to perform these operations internally.

However, current approaches have two massive flaws:

  1. Prohibitive Scaling: Most models flatten an $N \times N$ matrix into a sequence of $N^2$ tokens. This leads to a staggering $O(N^4)$ computational complexity, making it impossible to process even modest $100 \times 100$ matrices on high-end hardware.
  2. Lack of Generalization: When trained on standard Gaussian random matrices, Transformers fail on simple "out-of-distribution" cases—even something as trivial as an Identity matrix. They don't learn the algorithm for an inverse; they learn to predict the average statistics of their training data.

Methods

The authors propose a sequence of interventions to move Transformers from "memorizers" to "solvers," culminating in the RangeFormer:

  • Range Embedding: Instead of flattening the matrix, they use a learnable projection to embed the matrix into a sequence of $N$ vectors. This reduces memory complexity from $O(N^4)$ to $O(ND + D^2)$.
  • Linear Attention: They replace standard softmax attention with linear alternatives (like Taylor attention), which are better suited for the multiplicative nature of linear algebra.
  • Looping: Inspired by iterative numerical methods (like Conjugate Gradient), they use a "looped" architecture where the same transformer weights are applied repeatedly. This allows the model to "think longer" for harder problems.
  • Diverse Data Mixture: Instead of just Gaussian noise, they train on a rich variety of structured matrices, including Kronecker products, low-rank matrices, and specific eigenvalue decay patterns (Polynomial, Cosine, etc.).
Overview of RangeFormer interventions and performance improvements.

Datasets

  • Synthetic Training Data: A novel mixture of "Einsum" parameterized structured matrices and matrices with four distinct types of diagonal/spectral decay.
  • Matrix Market: A collection of real-world symmetric matrices from structural engineering, fluid flow, and power systems used for out-of-distribution (OOD) evaluation.
  • Downstream Tasks: The model was tested on its ability to support Gaussian Process (GP) learning and randomized Singular Value Decomposition (SVD).

Key Insights and Ideas

  • Statistical Interpolation vs. Algorithm Discovery: The authors found that a Transformer trained only on Gaussian matrices will predict a non-zero maximum eigenvalue even when given a zero matrix. This is because it has never seen a zero matrix and is simply outputting the expected value of its training distribution.
  • The Identity Crisis: Standard models struggle with the Identity matrix because it is a "low probability" event in a Gaussian distribution. RangeFormer overcomes this by seeing a more diverse "spectral diet" during training.
  • Curriculum Learning: To reach the $N=1000$ scale, the authors found that starting with a model trained on $N=100$ and using it as a checkpoint was essential for convergence.

Key Results

  • Scaling Breakthrough: RangeFormer successfully runs on $1000 \times 1000$ matrices, whereas vanilla Transformers (TF) run out of memory on an 80GB A100 GPU at just $N=100$.
  • OOD Performance: On the challenging Matrix Market ensemble, RangeFormer achieved an order of magnitude better relative error than previous state-of-the-art numerical transformers.
  • Downstream Utility:
    • Warm-starting: Using RangeFormer to provide an initial guess for the Conjugate Gradient (CG) algorithm significantly accelerated convergence on real-world matrices.
  • GP Learning: For the first time, a Transformer was used to successfully optimize the marginal likelihood of a Gaussian Process, a task that requires high precision to avoid compounding errors.

Limitations and Future Work

  • Conditioning: While RangeFormer is much more robust, performance still degrades on extremely poorly conditioned matrices (condition numbers $\approx 10^4$).
  • Not a Replacement (Yet): The authors emphasize they aren't trying to replace highly optimized C++ libraries like LAPACK. Instead, they are proving that Transformers can learn these primitives, which is a prerequisite for general intelligence.
  • Future Directions: Exploring how these "neural solvers" can be further integrated into hybrid classical-neural pipelines for massive-scale scientific computing.

Summary updated

BibTeX
@inproceedings{potapczynski2026understanding,
  author = {Andres Potapczynski and Alex Ali and Andrew Gordon Wilson},
  title = {{Understanding and Relaxing the Limitations of Transformers for Linear Algebra}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=GBkRMi3qjD},
}
Figure