Introduction
In modern machine learning and scientific computing, tuning models often relies on evaluating functions of massive matrices. For example, computing the Jacobian of a neural network with millions of parameters or evaluating log-determinants in Gaussian Processes involves matrices so large they cannot be stored in memory, let alone decomposed using standard operations.
To handle this, practitioners rely on "matrix-free" methods like the Lanczos or Arnoldi iterations. These algorithms only require computing matrix-vector products ($Av$) to evaluate matrix-function-vector products, such as $f(A)v$. However, to train these models using gradient-based optimization, we need the exact derivatives of these operations. Until now, researchers had to choose between two sub-optimal paths: incredibly slow and memory-intensive naive backpropagation through the iterative algorithm, or using simplified matrix approximations (like diagonal approximations) that discard crucial correlation information.
This paper introduces a breakthrough solution: deriving previously unknown "adjoint systems" for the Lanczos and Arnoldi iterations. This enables exact, reverse-mode automatic differentiation that is as fast and memory-efficient as the forward pass itself.
Methods: The Adjoint Approach
Rather than treating the iterative algorithm as a sequence of steps to be recorded for automatic differentiation, the authors treat the entire decomposition as a set of mathematical constraints. By applying the Adjoint Method, they derive a set of dual equations that, when solved, provide the exact gradients of the output with respect to the inputs.
Key highlights of this approach include:
- Matrix-Free Gradients: The backward pass uses the exact same matrix-vector product interface as the forward pass.
- Linear Complexity: The time and memory requirements scale linearly with the number of iterations, perfectly matching the efficiency of the forward pass.
- Numerical Stability: The authors demonstrate that "reorthogonalization"—a technique to maintain algorithmic stability—is just as critical for the gradients as it is for the values, and they provide a robust implementation.
These methods are implemented in a JAX-based library called matfree, requiring no problem-specific code optimization from the user.
Applications and Datasets
The methodology is validated across several distinct and challenging domains:
- Gaussian Processes (GPs): Evaluated on UCI regression datasets (Protein, Elevators, Kin40k, KEGG).
- Partial Differential Equations (PDEs): Tested on a custom 128x128 grid simulating wave equations, similar to the WaveBench benchmark.
- Bayesian Neural Networks (BNNs): Applied to a pre-trained Visual Attention Network (VAN) with 4.1 million parameters on ImageNet, using places365 for out-of-distribution testing.
Key Results and Insights
Lanczos and Arnoldi iterations have been the workhorses of numerical linear algebra for decades. This paper provides the missing differentiation theory needed to fully integrate them into modern deep learning frameworks.
Speed and Memory Efficiency The adjoint method is orders of magnitude faster and more memory-efficient than naive backpropagation. When benchmarked on a sparse matrix with roughly 12,000 rows (from the SuiteSparse collection), naive backpropagation crashed due to memory limits at around 100 iterations. In contrast, the adjoint method continued to scale linearly, matching the forward pass.
Performance Breakthroughs * Outperforming Specialized Solvers: For certain physics-informed ML tasks, using a differentiable Arnoldi iteration to compute matrix exponentials outperformed highly optimized ODE solvers like Diffrax. * Unlocking Laplace Approximations: In Bayesian Deep Learning, calculating the log-determinant of the Hessian is a notorious bottleneck. On a 4-million parameter network, the Lanczos-based approach achieved a significantly higher marginal likelihood (-154,475) compared to the standard diagonal approximation (-876,444), proving that capturing full matrix structure leads to vastly superior model calibration. * Matching State-of-the-Art: For GPs, the method matched the accuracy of GPyTorch while providing a cleaner, more general implementation natively in JAX.
Limitations and Future Work
While a significant leap forward, the authors acknowledge a few areas for future improvement:
- Memory Constraints: Although the massive matrix $A$ is never stored, the orthogonal basis $Q$ generated during the iterations is stored in memory. For extremely high-dimensional problems or very high iteration counts, this could eventually become a bottleneck.
- Real-Valued Limitation: The current derivation focuses on real-valued matrices. Many physics applications, such as quantum mechanics, require complex-valued arithmetic.
- Partial Reorthogonalization: The current implementation relies on "full" reorthogonalization. Deriving adjoints for "partial" reorthogonalization remains a mathematically complex but promising direction for future research.
Summary updated