Auto-Differentiating Linear Algebra

Matthias W. Seeger, Asmus Hetzel, Zhenwen Dai, Neil D. LawrencearXiv 2017

Abstract

Development systems for deep learning (DL), such as Theano, Torch, TensorFlow, or MXNet, are easy-to-use tools for creating complex neural network models. Since gradient computations are automatically baked in, and execution is mapped to high performance hardware, these models can be trained end-to-end on large amounts of data. However, it is currently not easy to implement many basic machine learning primitives in these systems (such as Gaussian processes, least squares estimation, principal components analysis, Kalman smoothing), mainly because they lack efficient support of linear algebra primitives as differentiable operators. We detail how a number of matrix decompositions (Cholesky, LQ, symmetric eigen) can be implemented as differentiable operators. We have implemented these primitives in MXNet, running on CPU and GPU in single and double precision. We sketch use cases of these new operators, learning Gaussian process and Bayesian linear regression models, where we demonstrate very substantial reductions in implementation complexity and running time compared to previous codes. Our MXNet extension allows end-to-end learning of hybrid models, which combine deep neural networks (DNNs) with Bayesian concepts, with applications in advanced Gaussian process models, scalable Bayesian optimization, and Bayesian active learning.

Introduction

The rapid advancement of Deep Learning Development Systems (DLDS) has streamlined the creation of complex neural architectures. By providing automatic differentiation and high-performance hardware acceleration, frameworks like MXNet and TensorFlow allow researchers to focus on model design rather than low-level optimization. However, a significant gap remains: "classical" machine learning algorithms—such as Gaussian Processes (GPs), Principal Component Analysis (PCA), and Kalman filtering—rely on matrix decompositions that have historically been poorly supported in these frameworks.

In many existing systems, these operations were either missing or implemented as high-level wrappers that lacked efficient backward passes (gradients). This deficiency forced researchers to choose between the statistical rigor of classical methods and the scalability of deep learning. This work addresses this gap by treating linear algebra primitives as "first-class citizens" within the MXNet framework, enabling the development of hybrid models that leverage the strengths of both paradigms.

Technical Implementation

The core contribution of this work is the integration of highly optimized, differentiable linear algebra operators directly into the C++ core of MXNet.

Differentiable Decompositions

We derived and implemented "pullback" (backward pass) formulas for several critical decompositions:

  • Cholesky (potrf): Essential for Gaussian Process inference and sampling.
  • LQ (gelqf): Utilized for Bayesian linear regression; chosen for its superior numerical stability compared to standard Cholesky approaches when dealing with ill-conditioned matrices.
  • Symmetric Eigendecomposition (syevd) and SVD (gesvd): Critical for PCA and spectral analysis.

Efficiency and Optimization

To ensure these operators are practical for large-scale scientific computing, we focused on three key architectural optimizations:

  1. In-Place Operations: By leveraging the in-place capabilities of underlying libraries like BLAS/LAPACK (for CPU) and cuSOLVER (for GPU), we minimize unnecessary memory allocations and data movement.
  2. Gradient Re-use: A major efficiency gain is achieved by passing the results of the forward pass (such as a Cholesky factor $L$) directly to the backward pass, avoiding redundant and expensive re-computations.
  3. Low-Level Integration: By implementing these operators at the C++ level rather than through Python wrappers, we avoid interpreter overhead and allow the MXNet engine's scheduler to manage memory and execution order optimally.

Experimental Evaluation

The implementation was evaluated using several standard benchmarks, including the Power Plant regression dataset (~9,500 samples), MNIST, and various regression tasks (Naval1, Naval2, and Kin8nm).

Computational Performance

On Intel CPUs using MKL, the MXNet operators demonstrated a 3x speedup over TensorFlow’s equivalent implementations. On GPUs, the performance gains remained consistent across various matrix sizes, proving the scalability of the C++/cuSOLVER integration.

Memory Efficiency

Memory management is often the primary bottleneck in large-scale linear algebra. In a Sparse GP task, the MXNet implementation required only 310 MB of memory, representing a 90% reduction compared to the 2.8 GB used by GPy, a popular specialized Gaussian Process library.

Scalability and Accuracy

For Sparse GPs, the GPU-accelerated implementation was 10x faster than the GPy reference code running on a CPU. Furthermore, the "Stochastic Variational Deep GP" (SV-DGP) model enabled by these operators outperformed several generative baselines, such as GANs and VAEs, in terms of log-likelihood on the MNIST test set.

Hybrid Modeling and Future Work

The integration of these primitives allows for "hybrid modeling," where neural networks and Bayesian components are trained end-to-end via backpropagation. For instance, a deep neural network can serve as a feature extractor for a Gaussian Process, with gradients flowing through the entire pipeline to optimize both the network weights and the GP hyperparameters simultaneously.

Despite these advances, certain numerical constraints remain. The derivatives for eigendecompositions and SVD are only well-defined when eigenvalues or singular values are distinct; we currently use a small epsilon approximation to guard against division by zero in near-singular cases. Additionally, the LQ decomposition derivative currently requires the input matrix to have full rank. Future work will focus on expanding operator coverage to include QR decompositions and support for complex-valued linear algebra.

Conclusion

By adding a targeted set of differentiable linear algebra primitives to MXNet, we have bridged the gap between classical statistical modeling and modern deep learning. This allows for more robust, statistically grounded models that do not sacrifice the performance, memory efficiency, or flexibility of modern deep learning frameworks.

Summary updated

BibTeX
@misc{seeger2017auto,
  author = {Matthias W. Seeger and Asmus Hetzel and Zhenwen Dai and Neil D. Lawrence},
  title = {{Auto-Differentiating Linear Algebra}},
  year = {2017},
  eprint = {1710.08717},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1710.08717},
}
Figure