Linear Transformers Implicitly Discover Unified Numerical Algorithms

Patrick Lutz, Aditya Gangrade, Hadi Daneshmand, Venkatesh Saligrama

Abstract

Recent research into the in-context learning (ICL) capabilities of transformers has often suggested that these models solve mathematical problems by implicitly performing Gradient Descent (GD). However, this study demonstrates that when trained on matrix completion tasks, linear transformers discover a more sophisticated, second-order numerical algorithm named EAGLE (Emergent Algorithm for Global Low-rank Estimation). This algorithm is unified across various hardware constraints, exhibiting second-order convergence and outperforming classical methods like Gradient Descent and Conjugate Gradient in distributed and compute-limited environments.

Introduction

While transformers have revolutionized natural language processing, their internal mechanics for solving mathematical problems—specifically through in-context learning—remain a subject of intense debate. Previous literature primarily focused on simple regression tasks, suggesting that transformers act as implicit first-order optimizers. This paper expands the scope of this inquiry by investigating masked-block completion, a fundamental task in recommendation systems and kernel methods, where a model must fill in missing entries of a low-rank matrix.

The researchers sought to determine if changing "hardware" constraints—such as limiting communication between processors or restricting available memory—would force the transformer to adapt its internal logic. Their findings reveal that the model does not merely settle for simple heuristics but instead "invents" a robust, resource-adaptive numerical solver.

Methodology

Architectural Regimes

The study utilized a linear, attention-only transformer trained on millions of synthetic matrix completion tasks. To observe how the model adapts to real-world constraints, the researchers tested three distinct regimes:

  1. Unconstrained (Centralized): The model has full visibility of all data points.
  2. Distributed: This regime simulates multiple machines where each attention head only accesses a portion of the data, mimicking restricted inter-machine communication.
  3. Compute-limited: This uses a low-rank attention bottleneck to simulate hardware with restricted memory or processing power.

Algebraic Unrolling

To decipher the transformer's learned logic, the authors employed a technique called algebraic unrolling. By simplifying and quantizing the trained weights, they were able to extract a clear, two-line iterative update rule from the model's internal activations. This process proved highly accurate, with the extracted algorithm reproducing the transformer's activations with an error of less than $6 \times 10^{-4}$.

The Discovery of EAGLE

The most significant finding was the emergence of EAGLE. Regardless of the architectural regime (centralized, distributed, or sketched), the transformer converged on this same underlying algorithm.

Beyond Gradient Descent

Unlike the first-order logic of Gradient Descent, EAGLE achieves second-order convergence. This means the algorithm doesn't just move linearly toward a solution; it accelerates toward it. The researchers identified a structural relationship between EAGLE and the Newton-Schulz method for matrix inversion. Essentially, the transformer learns to "condition" the data—making it numerically easier to solve—as it passes through successive layers.

Resource Adaptivity

In compute-limited scenarios, the transformer demonstrated remarkable flexibility. Rather than simply losing accuracy, it discovered how to utilize random sketches (projections) to maintain performance. This allowed the model to slash computational costs from $O(n^2d)$ to $O(nrd)$ without a significant drop in precision.

Experimental Results

The performance of EAGLE was evaluated against standard numerical methods across several data distributions, including Gaussian, Student-t, and noisy variants.

  • Iteration Efficiency: In centralized settings, EAGLE required approximately 100x fewer iterations than the Conjugate Gradient (CG) method when processing ill-conditioned matrices (where the condition number $\kappa = 10^4$).
  • Distributed Performance: EAGLE significantly reduced communication complexity in distributed settings. It remained accurate even when data diversity across machines was low—a scenario where standard Gradient Descent typically fails.
  • Wall-Clock Speed: In the compute-limited "sketched" regime, EAGLE reached high accuracy ($10^{-6}$ error) in roughly one-third of the time required by standard stochastic methods.

Conclusion and Future Work

This research proves that linear transformers are capable of discovering unified, high-order numerical algorithms that are both efficient and adaptive to hardware constraints. However, several questions remain. The numerical stability of EAGLE has not yet been tested for extremely "stiff" problems (condition numbers exceeding $10^8$). Furthermore, while this study focused on linear transformers, the potential for standard transformers with non-linear activations (like ReLU or GeLU) to discover even more complex algorithms remains an open and promising frontier for future research.

Summary updated

BibTeX
@inproceedings{lutz2025linear,
  author = {Patrick Lutz and Aditya Gangrade and Hadi Daneshmand and Venkatesh Saligrama},
  title = {{Linear Transformers Implicitly Discover Unified Numerical Algorithms}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=XxR70zr9Sf},
}
Figure