Introduction
Machine learning relies heavily on large-scale linear algebra. Operations like matrix inversions, eigendecompositions, and trace estimations are at the heart of Gaussian processes, normalizing flows, and principal component analysis (PCA).
Often, the massive matrices involved in these computations aren't just random noise; they possess underlying algebraic structures (e.g., a low-rank matrix added to a diagonal matrix). If this structure is known, mathematical shortcuts—like the Woodbury matrix identity—can be used to solve problems in linear time instead of cubic time. However, implementing these structure-aware routines is currently a tedious, manual process. Existing libraries either force researchers to write custom code for every new structure, fall back to generic (and slower) iterative solvers, or lack modern machine learning necessities like GPU acceleration and automatic differentiation.
CoLA (Compositional Linear Algebra) is a new framework designed to solve this problem. It automates efficient numerical linear algebra for machine learning by exploiting compositional matrix structures (like Kronecker products or block diagonals). By combining a LinearOperator abstraction with multiple dispatch rules, CoLA automatically selects the fastest algorithms while providing crucial ML features like GPU acceleration, low-precision support, and memory-efficient automatic differentiation.
The CoLA Framework
CoLA is built on a few core technical pillars, supporting both PyTorch and JAX:
- The
LinearOperatorAbstraction: Instead of storing massive dense matrices in memory, CoLA represents matrices implicitly as functions that perform Matrix-Vector Multiplies (MVMs). - Compositional Dispatch Rules: Using the programming paradigm of multiple dispatch, CoLA automatically routes operations to the most efficient algorithm based on the matrix's structure. For example, if you ask it to invert a matrix that is a
Sumof aLowRankandDiagonaloperator, the dispatcher automatically applies the Woodbury formula. If it's aKroneckerproduct, it splits the solve across the product.
- Exploiting Implicit Structure: For matrices that are massive sums (common in ML datasets), CoLA uses Stochastic Variance Reduced Gradient (SVRG) to solve linear systems exponentially faster than standard stochastic methods. It also introduces a novel "doubly stochastic" estimator for computing matrix diagonals and traces.
- Memory-Efficient Autodiff: Standard autodiff engines blow up in memory when backpropagating through iterative solvers (like Conjugate Gradients) because they save every step of the loop. CoLA implements custom Vector-Jacobian Products (VJPs) based on the analytical derivatives of the final linear algebra operations, bypassing the need to unroll the solver.
Key Insights
- Automation of Math is a Catalyst: Just as automatic differentiation freed researchers to invent new neural network architectures rather than manually calculating gradients, automating structure-aware linear algebra frees researchers to prototype complex models without worrying about the underlying solver implementations.
- The Power of Composition: You don't need to hardcode a solver for every possible matrix type. By defining rules for base cases and compositional operators (like
Sum,Product,Kronecker), CoLA recursively breaks down complex matrices into fast, specialized solves. - Memory-Free Backprop: By using custom VJP rules, the memory required to backpropagate through a linear solve becomes constant $O(1)$ with respect to the number of solver iterations. This makes training models with deep, iterative linear algebra layers practically feasible.
- SVRG Shines in Linear Algebra: Treating a linear solve as an optimization problem over a finite sum allows the use of SVRG. For large sums, this drastically outperforms classical deterministic Krylov methods (like Lanczos or Conjugate Gradients).
Experimental Results
The authors evaluated CoLA across a wide variety of domains, including UCI Machine Learning datasets, high-energy physics citation graphs, and discretized grids for solving PDEs.
- Algorithmic Speedups: Exploiting Kronecker structure in multi-task Gaussian Processes and product structures in PDEs yielded orders-of-magnitude runtime speedups compared to dense or generic iterative methods.
- Massive Memory Savings: In backpropagation experiments, standard unrolled autodiff memory consumption grew linearly to over 100MB for 10,000 Conjugate Gradient iterations. CoLA's custom VJP rules kept memory usage near zero (constant).
- Competitive with Specialized Packages: Despite being a general-purpose framework, CoLA matched or beat highly specialized packages like
sklearn(for PCA and Ridge Regression) andGPyTorch(for Gaussian Process inference), while offering the flexibility to run on both CPUs and GPUs. - Variance Reduction: CoLA's novel doubly stochastic diagonal estimator converges significantly faster ($O(1/\sqrt{nm})$) than the standard Hutchinson estimator when applied to sum-structured matrices.
Limitations and Future Work
While highly competitive, the authors note that for certain specific operations, CoLA's Python/JAX-based iterative implementations (like GMRES) can sometimes lag slightly behind highly-optimized, low-level Fortran libraries (like ARPACK used by SciPy) due to algorithmic constants and overhead.
Looking forward, the framework is designed to be highly extensible. Users can easily add new linear operators or entirely new algebraic operations without altering the core library. The authors hope CoLA will serve as a bridge, bringing fast, scalable linear algebra techniques to disparate communities across machine learning and the physical sciences.
Summary updated