Matrix-Free Least Squares Solvers: Values, Gradients, and What to Do With Them
Hrittik Roy, Søren Hauberg, Nicholas Krämer
TL;DR
This work recasts least-squares as a differentiable, matrix-free operator by deriving reverse-mode gradients through adjoint methods and implementing an efficient $\texttt{LstSq}$ solver in JAX using $\text{LSMR}$. It then leverages the null-space method to solve constrained neural-network optimization problems by reframing constraints as a sequence of least-squares problems, enabling easy integration with Optax. The authors demonstrate practical benefits: scalable sparsity and equivariance constraints on models with millions of parameters, improved conservativeness for score-based models, and faster, more reliable Gaussian-process calibration via differentiable LS. Overall, the paper provides a pragmatic toolkit that makes differentiable linear algebra accessible for a broad range of ML applications with explicit, data-efficient gradients through LS solvers.
Abstract
This paper argues that the method of least squares has significant unfulfilled potential in modern machine learning, far beyond merely being a tool for fitting linear models. To release its potential, we derive custom gradients that transform the solver into a differentiable operator, like a neural network layer, enabling many diverse applications. Empirically, we demonstrate: (i) scalability by enforcing weight sparsity on a 50 million parameter model; (ii) imposing conservativeness constraints in score-based generative models; and (iii) hyperparameter tuning of Gaussian processes based on predictive performance. By doing this, our work represents the next iteration in developing differentiable linear-algebra tools and making them widely accessible to machine learning practitioners.
