Backpropagation Beyond the Gradient

Felix DangelUndefined 2023

Abstract

Automatic differentiation (AD) is a key enabler of deep learning, allowing practitioners to train sophisticated models using first-order gradient information. However, standard libraries like PyTorch and TensorFlow are specialized for computing mini-batch average gradients, which complicates the extraction of higher-order statistical moments or curvature information like the Hessian. This research presents approaches to simplify experimentation with rich information beyond the gradient. We introduce Hessian backpropagation for sequential models and the BackPACK library, which provides efficient access to per-sample statistics and curvature approximations. Furthermore, we present Cockpit, a diagnostic tool for visualizing training dynamics, and ViViT, a method for efficiently computing curvature noise using low-rank structures. These tools facilitate the development of more efficient deep learning algorithms by making higher-order information as accessible as the gradient.

Introduction: The Gradient Bottleneck

Deep learning's success is deeply intertwined with the efficiency of automatic differentiation. Current frameworks are highly optimized for a single task: computing the average gradient across a mini-batch. While this has powered the field's growth, it has also created a "gradient-only" bottleneck. Researchers wishing to explore second-order optimization or noise-aware training often face significant implementation hurdles, requiring complex and inefficient custom code. This work addresses this gap by making information beyond the average gradient—such as per-sample gradients and curvature—as easy and efficient to access as the gradient itself.

Methodology: Extending Automatic Differentiation

The research introduces four major components to bridge the gap between theoretical second-order methods and practical deep learning.

Hessian Backpropagation (HBP)

HBP extends the modularity of standard backpropagation to second-order derivatives. By passing curvature information backward through network layers, it enables the computation of block-diagonal approximations of the Hessian. This modular approach allows for easy automation and extension to new operations, mirroring the convenience of gradient AD.

BackPACK: Packing More into Backprop

BackPACK is an open-source library built for PyTorch that "hacks" the standard backward pass. It extracts additional quantities—including per-sample gradients, gradient variance, and curvature approximations (e.g., GGN, KFAC)—with minimal computational overhead. It demonstrates that much of this "hidden" data is already computed during standard backprop and simply needs to be captured before aggregation.

Cockpit: Visualizing Training Dynamics

Cockpit is a visual diagnostic tool that utilizes BackPACK’s statistics to provide a "dashboard" for deep learning engineers. It offers various "instruments" (plots) that reveal internal model states, such as gradient histograms and the "Alpha" quantity (tracking optimizer overshooting). This allows for identifying bugs like vanishing gradients or poorly scaled data that are invisible in standard loss curves.

ViViT: Efficient Curvature Analysis

ViViT leverages the low-rank structure of the Generalized Gauss-Newton (GGN) matrix to compute exact eigenvalues, eigenvectors, and curvature noise. By exploiting the "thin" algebraic structure of the GGN, ViViT makes spectral analysis practical for modern, large-scale architectures, addressing the computational prohibitiveness of previous methods.

Experimental Evaluation

The proposed methods were evaluated using the DeepOBS benchmark suite across various datasets, including MNIST, Fashion-MNIST, CIFAR-10, CIFAR-100, and ImageNet.

  • Efficiency: BackPACK extensions typically add less than 10% overhead to the standard backward pass.
  • Scalability: Tools like Cockpit were successfully demonstrated on large-scale models such as VGG16 and ResNet-50 on ImageNet.
  • Diagnostic Power: Cockpit immediately identified common training issues, such as unnormalized input data, through distinct signatures in gradient statistics.

Key Insights

  • Per-Sample Information is "Free": Per-sample gradients are computed internally during backprop; capturing them before they are averaged provides rich statistical data at almost no extra cost.
  • Modularity and Automation: Modular Hessian backpropagation allows for the same level of extensibility as first-order AD, enabling researchers to add new layers without re-deriving complex second-order mathematics.
  • Actionable Curvature: Higher-order information provides actionable insights for hyperparameter tuning. For instance, monitoring curvature noise can guide learning rate adjustments more effectively than monitoring loss alone.

Conclusion and Future Work

This work provides the tools necessary to move beyond simple gradient-based optimization. While initial support focused on sequential models, the framework's modularity allows for expansion to complex architectures. Future research will focus on developing "noise-aware" optimizers that use real-time curvature noise estimates to automatically stabilize training and improve convergence in modern deep learning tasks.

Summary updated

Abstract

Automatic differentiation is a key enabler of deep learning: previously, practitioners were limited to models for which they could manually compute derivatives. Now, they can create sophisticated models with almost no restrictions and train them using first-order, i. e. gradient, information. Popular libraries like PyTorch and TensorFlow compute this gradient efficiently, automatically, and conveniently with a single line of code. Under the hood, reverse-mode automatic differentiation, or gradient backpropagation, powers the gradient computation in these libraries. Their entire design centers around gradient backpropagation. These frameworks are specialized around one specific task—computing the average gradient in a mini-batch. This specialization often complicates the extraction of other information like higher-order statistical moments of the gradient, or higher-order derivatives like the Hessian. It limits practitioners and researchers to methods that rely on the gradient. Arguably, this hampers the field from exploring the potential of higher-order information and there is evidence that focusing solely on the gradient has not lead to significant recent advances in deep learning optimization. To advance algorithmic research and inspire novel ideas, information beyond the batch-averaged gradient must be made available at the same level of computational efficiency, automation, and convenience. This thesis presents approaches to simplify experimentation with rich information beyond the gradient by making it more readily accessible. We present an implementation of these ideas as an extension to the backpropagation procedure in PyTorch. Using this newly accessible information, we demonstrate possible use cases by (i) showing how it can inform our understanding of neural network training by building a diagnostic tool, and (ii) enabling novel methods to efficiently compute and approximate curvature information. First, we extend gradient backpropagation for sequential feedforward models to Hessian backpropagation which enables computing approximate per-layer curvature. This perspective unifies recently proposed block- diagonal curvature approximations. Like gradient backpropagation, the computation of these second-order derivatives is modular, and therefore simple to automate and extend to new operations. Based on the insight that rich information beyond the gradient can be computed efficiently and at the same time, we extend the backpropagation in PyTorch with the BackPACK library. It provides efficient and convenient access to statistical moments of the gradient and approximate curvature information, often at a small overhead compared to computing just the gradient. Next, we showcase the utility of such information to better understand neural network training. We build the Cockpit library that visualizes what is happening inside the model during training through various instruments that rely on BackPACK’s statistics. We show how Cockpit provides a meaningful statistical summary report to the deep learning engineer to identify bugs in their machine learning pipeline, guide hyperparameter tuning, and study deep learning phenomena. Finally, we use BackPACK’s extended automatic differentiation functionality to develop ViViT, an approach to efficiently compute curvature information, in particular curvature noise. It uses the low-rank structure of the generalized Gauss-Newton approximation to the Hessian and addresses shortcomings in existing curvature approximations. Through monitoring curvature noise, we demonstrate how ViViT’s information helps in understanding challenges to make second-order optimization methods work in practice. This work develops new tools to experiment more easily with higher-order information in complex deep learning models. These tools have impacted works on Bayesian applications with Laplace approximations, out-of-distribution generalization, differential privacy, and the design of automatic differentia- tion systems. They constitute one important step towards developing and establishing more efficient deep learning algorithms.
BibTeX
@inproceedings{dangel2023backpropagation,
  author = {Felix Dangel},
  title = {{Backpropagation Beyond the Gradient}},
  booktitle = {Undefined},
  year = {2023},
  url = {https://openreview.net/forum?id=FvyObhEmyp},
}
Figure