NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

'hessQuik': Fast Hessian computation of composite functions

Elizabeth Newman, Lars RuthottoJ. Open Source Softw 2022 · DBLP

TL;DR

hessQuik is a lightweight PyTorch library designed to compute second-order derivatives (Hessians) of composite functions—like neural networks—significantly faster than standard automatic differentiation. By using analytical formulas and a smart heuristic to switch between forward and backward modes, it provides a GPU-accelerated way to access the "curvature" of models, which is essential for physics-informed machine learning and optimization.

What Problem Does This Paper Address?

In the world of deep learning, first-order derivatives (gradients) are the bread and butter of training. Automatic Differentiation (AD) has made computing these gradients incredibly easy. However, many emerging fields—such as Physics-Informed Neural Networks (PINNs), generative modeling, and adversarial learning—require second-order derivatives, or Hessians.

The problem is that standard AD is notoriously inefficient at computing Hessians. It often encounters computational bottlenecks, leading researchers to rely on approximations that can result in sub-optimal model performance. Deriving these second-order formulas by hand is a tedious, error-prone process. hessQuik bridges this gap by providing a user-friendly, high-performance library that computes these derivatives analytically and efficiently.

Methods

The core of hessQuik is the implementation of the chain rule for second-order derivatives across "layers" of a composite function.

Key technical features include:

  • Analytical Implementation: Rather than relying on the overhead of general-purpose AD for the second derivative, the authors implemented the exact mathematical formulas for the Hessian of common layers.
  • Dual Modes (Forward & Backward): Similar to how AD has forward and reverse modes, hessQuik implements both.
  • Forward Mode: Builds the gradient and Hessian during the forward pass.
  • Backward Mode: Propagates information from the output layer back to the input.
  • Automatic Heuristic: The library automatically selects the most efficient mode based on the dimensions of the problem. If the number of input features ($n_0$) is less than the number of output features ($n_\ell$), it chooses forward mode; otherwise, it uses backward mode.
  • Supported Layers: It comes out-of-the-box with support for standard affine layers (singleLayer), residual layers (residualLayer), and Input Convex Neural Network layers (ICNNLayer).

Datasets

As this is a software and methodology paper, the authors did not use standard image or text datasets. Instead, they evaluated performance using a synthetic benchmark:

  • Architecture: A Residual Neural Network (ResNet) with a fixed width of 16 and a depth of 4.
  • Variations: They varied the input dimension ($d = 2^k$ for $k=0$ to $10$) and the number of output features to test scaling.
  • Environment: Tests were conducted on Google Colab Pro using an Intel Xeon CPU and an NVIDIA Tesla P100 GPU.

Key Insights and Ideas

  • The Efficiency of "AD-Free" Math: By bypassing the standard AD graph for the second-order step and using direct matrix/tensor products (like mode-k products), hessQuik achieves much better scaling.
  • Dimension Matters: The "aha moment" in their efficiency testing is the realization that the cost of Hessians is highly sensitive to the ratio of input to output features. Their automated switching logic ensures the user always gets the fastest path without needing to be an optimization expert.
  • GPU Parallelization: The analytical formulas for Hessians are highly structured, making them perfect candidates for GPU acceleration, which the library leverages via PyTorch.

Key Results

The authors compared hessQuik against two standard approaches: PytorchAD (standard automatic differentiation) and PytorchHessian (PyTorch's built-in Hessian function).

  • Scaling with Inputs: For models with a scalar output, hessQuik scaled significantly better as the number of input features increased compared to both AD-based methods.
  • Scaling with Outputs: While PytorchAD saw a significant spike in computation time as the number of output features increased, hessQuik timings remained relatively constant.
  • GPU Speedup: The library showed "noticeable acceleration" on the GPU, particularly for networks with larger dimensions, making it viable for complex, real-world models.

Limitations and Future Work

While hessQuik is powerful, it is currently a "lightweight" library. Its primary limitation is the scope of supported layers; while it covers the most popular ones (dense, residual, convex), users with highly custom or exotic architectures might need to implement the analytical derivatives for their specific layers themselves.

The authors frame hessQuik as an extensible framework and hope the community will contribute new layer types. Future work likely involves expanding the library of supported functions and further optimizing the tensor operations for next-generation GPU architectures.

Summary updated

BibTeX
@article{newman2022hessquik,
  author = {Elizabeth Newman and Lars Ruthotto and Elizabeth Newman},
  title = {{'hessQuik': Fast Hessian computation of composite functions}},
  journal = {J. Open Source Softw.},
  year = {2022},
  doi = {10.21105/joss.04171},
}

Loading related content...

Figure