Automatic Differentiation: Inverse Accumulation Mode

Barak A. Pearlmutter, Jeffrey Mark SiskindarXiv 2024 · DOI

Introduction

Automatic Differentiation (AD) is the foundational technology enabling modern machine learning and scientific computing. Traditionally, AD is categorized into two primary modes: Forward Mode, which is efficient for functions with few inputs and many outputs, and Reverse Mode (backpropagation), which excels when there are many inputs and few outputs. However, high-level numerical algorithms, such as Newton’s method for optimization or root-finding, frequently require the inverse of the Jacobian matrix ($J^{-1}$).

Historically, computing Jacobian-inverse-vector products ($J^{-1}v$) has been computationally expensive, typically requiring the explicit construction of the Jacobian followed by a linear system solve. This paper introduces Inverse Accumulation Mode, a novel AD framework that allows for the calculation of $J^{-1}v$ with the same time complexity as standard gradients, effectively making inverse products a first-class citizen in the AD ecosystem.

Methodology: The Mechanics of Inversion

The authors' approach leverages the fact that computer programs are composed of sequences of elementary basis functions. The Jacobian of a full program is the product of the Jacobians of these individual steps: $J = J_T J_{T-1} \dots J_1$.

Invertible Basis Jacobians and Sparsity

A key technical insight is that the Jacobian of an elementary operation is a "near-identity" matrix. Crucially, the inverse of such a matrix maintains the same sparsity pattern as the original. This "symmetry of sparsity" ensures that inverting a single program step does not lead to computational explosion, allowing for efficient step-by-step inversion.

The Constant-Width Constraint and Lumpification

To maintain invertibility, the computation must adhere to a constant-width property: if a program has $n$ inputs, it must maintain $n$ active variables throughout. Dropping a variable results in a singular (non-invertible) Jacobian. For programs that do not naturally satisfy this, the authors propose lumpification—partitioning the data flow graph into "lumps" or macro-steps where the constant-width property is preserved.

The Four Modes of AD

The paper formalizes a symmetry between four distinct modes of differentiation. Beyond the standard Forward and Reverse modes, the authors define Forward-Inverse and Reverse-Inverse modes.

Comparison of Forward-Inverse and Reverse-Inverse steps, showing the relationship between graph structures and Jacobian matrices.

As shown in the figure above, the Forward-Inverse step ($\bar{\mathbf{y}}^* = \mathbf{J}^{-\top} \bar{\mathbf{x}}^*$) and the Reverse-Inverse step ($\dot{\mathbf{x}}^* = \mathbf{J}^{-1} \dot{\mathbf{y}}^*$) exhibit a structural duality. The Reverse-Inverse mode, in particular, reverses the forward graph structure while applying different edge labels to compute the inverse product directly.

Key Insights and Theoretical Results

The paper establishes several significant theoretical results:

  • Complexity Parity: Jacobian-inverse-vector products can be computed with a time complexity of $O(\text{work}(f))$, matching the efficiency of standard Forward or Reverse AD.
  • ODE Duality: Applying Inverse AD to an Ordinary Differential Equation (ODE) solver yields a new ODE. The authors note an interesting stability trade-off: if the primal ODE is stable, the inverse ODE may be unstable due to eigenvalue inversion.
  • Tape-free Inversion: Similar to forward mode, Forward-Inverse mode can be computed without a "tape" (a record of intermediate values), provided the primal steps themselves are invertible.

Limitations and Future Directions

While promising, Inverse Accumulation Mode faces practical challenges. The requirement for constant-width data flow necessitates complex "lumpification" strategies, the optimal scheduling of which may be NP-hard. Additionally, numerical stability remains a concern when inverting systems with small eigenvalues. Future work involves integrating these methods into mainstream compilers like JAX or PyTorch, which will require sophisticated automatic lump detection and memory management.

Conclusion

Inverse Accumulation Mode bridges the gap between the mathematical ideal of inverse differentiation and practical algorithmic implementation. By demonstrating that $J^{-1}v$ can be computed as efficiently as $Jv$ or $J^T v$, this work paves the way for more efficient second-order optimization and complex scientific simulations.

Summary updated

BibTeX
@misc{pearlmutter2024automatic,
  author = {Barak A. Pearlmutter and Jeffrey Mark Siskind},
  title = {{Automatic Differentiation: Inverse Accumulation Mode}},
  year = {2024},
  eprint = {2411.18786},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.18786},
}
Figure