Efficient Linear System Solver with Transformers

Max Vladymyrov, Johannes von Oswald, Nolan Andrew Miller, Mark SandlerAI4MATH @ ICML 2024

TL;DR

This paper proposes using linear Transformers to solve systems of linear equations, treating each equation as a distinct token. They introduce a novel "BLOCK" encoding and re-parameterization technique that significantly reduces model parameters and allows Transformers to handle systems of varying sizes, achieving competitive accuracy with classical methods like Conjugate Gradient, especially for smaller systems.

What Problem Does This Paper Address?

Solving systems of linear equations (Ax = b) is a fundamental problem across many scientific and engineering disciplines. While established methods like Gaussian elimination and iterative solvers (e.g., Conjugate Gradient) are widely used, researchers are exploring alternative, potentially more efficient and versatile approaches. The paper investigates whether Transformers, known for their success in sequence processing, can be adapted to tackle this numerical problem effectively, particularly for systems where matrix size can vary.

Methods

The core idea is to represent each linear equation (a_i, x) = b_i as a token. These tokens are then fed into a linear Transformer architecture. To make this work efficiently and allow for generalization across different system sizes, the authors introduce two key innovations:

  1. Permutation-Invariant Tokenization: Each equation is encoded as a separate token, ensuring the Transformer processes the system without being sensitive to the order of equations.
  2. Block-wise Re-parameterization (BLOCK Encoding): A naive approach would lead to model parameters scaling quadratically with the system size. To avoid this, they propose a "BLOCK" re-parameterization of the attention weight matrices. This technique decouples the number of model parameters from the problem dimension (N), allowing the Transformer to handle systems of different sizes. This is contrasted with a "FULL" encoding where all weights are learned independently.

The Transformer takes an initial guess for the solution x_0 as a special query token and outputs the final solution x. The model is trained by minimizing the mean squared error between the predicted and true solutions.

Datasets

The paper does not explicitly mention specific named datasets. Instead, it describes generating batches of linear systems {A, b, x} with varying matrix sizes (N) and condition numbers (specifically, κ = 5 is mentioned for preliminary results) for training and evaluation.

Key Insights and Ideas

  • Transformers as Numerical Solvers: The paper demonstrates that Transformers, beyond their NLP origins, can be effectively repurposed as solvers for fundamental mathematical problems like linear systems.
  • Efficiency through Re-parameterization: The BLOCK encoding is crucial. It shows that by intelligently structuring the attention weights, one can achieve generalization across system sizes without a prohibitive increase in parameters, making the approach computationally feasible.
  • Generalization Beyond Training Size: The BLOCK encoding, by decoupling parameters from problem dimension, enables the model to generalize to system sizes it wasn't explicitly trained on, a significant advantage over fixed-size classical methods or naive Transformer approaches.
  • Competitive Performance: For smaller systems, the Transformer-based solver can be faster than iterative methods like Conjugate Gradient due to GPU-friendly matrix operations and lower overhead.

Key Results

  • Runtime: The proposed "BLOCK LINEAR TR" method is shown to be faster than Conjugate Gradient (CG) for small system sizes (N) on an A100 GPU, despite CG's theoretical asymptotic advantage. This is attributed to GPU optimization and lower overhead.
  • Accuracy: The Transformer-based solver achieves accuracy comparable to 6-8 iterations of the Conjugate Gradient method.
  • Generalization: Models trained on specific sizes (e.g., N=9) or ranges (e.g., N∈[2,9]) demonstrated the ability to generalize to unseen sizes, with fine-tuning further improving performance on larger systems (N∈[10,20]). The "FULL" encoding model, while achieving the best accuracy for its trained size, failed to generalize.

Limitations and Future Work

  • Symmetric Positive Definite Matrices Only: The current approach is limited to solving systems where the matrix A is symmetric and positive definite.
  • Scalability to Very Large/Ill-Conditioned Systems: The paper acknowledges that performance on extremely large systems or highly ill-conditioned matrices requires further investigation.
  • Sparse Matrices: Scaling the approach to handle sparse matrices efficiently is identified as an important future direction.
  • Hybrid Approaches: Integrating Transformer solvers with classical methods (e.g., as a preconditioner) is suggested as a promising avenue to leverage the strengths of both.
  • Architectural Choices and Training Strategies: Further research into these aspects could lead to even more efficient and adaptable solvers.

Summary updated

BibTeX
@inproceedings{vladymyrov2024efficient,
  author = {Max Vladymyrov and Johannes von Oswald and Nolan Andrew Miller and Mark Sandler},
  title = {{Efficient Linear System Solver with Transformers}},
  booktitle = {AI4MATH @ ICML},
  year = {2024},
  url = {https://openreview.net/forum?id=qc2adlhAWF},
}
Figure