Fast Approximation of the Gauss-Newton Hessian Matrix for the Multilayer Perceptron

Chao Chen, Severin Reiz, Chenhan D. Yu, Hans‐Joachim Bungartz, George Biros

Abstract

We introduce a fast algorithm for entry-wise evaluation of the Gauss-Newton Hessian (GNH) matrix for the fully-connected feed-forward neural network. The algorithm utilizes a precomputation step and an importance-based sampling step to reduce the cost of computing a matrix entry from $O(Nn)$ to $O(n+d/\epsilon^2)$, where $N$ is the number of parameters, $n$ is the number of data points, and $d$ is the output dimension. This efficiency enables the construction of hierarchical-matrix ($\mathcal{H}$-matrix) approximations, significantly reducing memory and computational requirements for second-order optimization tasks.

Introduction

Second-order optimization methods, which utilize the Hessian matrix, offer superior convergence properties compared to first-order methods like SGD. However, for a network with $N$ parameters, the $N \times N$ Hessian is often too large to store or compute. For $N=10^6$, the Hessian contains $10^{12}$ entries. Standard computation of a single column requires $O(Nn)$ work, making direct access to the matrix entries computationally prohibitive. This paper addresses the "entry-wise evaluation" problem, proposing a method to quickly access specific parts of the GNH matrix without full computation.

Methodology

Precomputation and Fast Sampling

The proposed approach tames the GNH through a two-stage process. First, a precomputation step exploits the layer-by-layer structure of the MLP to store intermediate matrices representing a compressed Jacobian. This reduces storage requirements from $O(N^2)$ to $O(nN)$. Second, a fast Monte Carlo sampling algorithm uses importance sampling to estimate entries $H_{km}$ by drawing a small number of samples based on the precomputed values. This reduces the cost per entry to $O(n + d/\epsilon^2)$, making the sampling step independent of the number of parameters $N$.

Algorithmic comparison between gradient evaluation and GNH matrix-vector multiplication.

Hierarchical Matrix Approximation

By enabling cheap entry-wise access, the authors construct an $\mathcal{H}$-matrix approximation using the Geometry-Oblivious Fast Multipole Method (GOFMM). This method treats the GNH as a tree structure where "near" parameters (defined by algebraic distance within the GNH itself) are stored densely, while "far" parameters are approximated as low-rank blocks. This allows for efficient storage and factorization, reducing memory footprint to $O(N r_o)$ and factorization work to $O(N r_o^2)$.

Visualization of the hierarchical matrix structure (b) and (c) compared to a standard block structure (a).

Key Results

The method was evaluated on MNIST and CIFAR-10 datasets with networks up to 1.6M parameters.

  • Massive Memory Savings: For a 1.6M parameter network, the precomputation required only 423 MB, compared to the 10.8 TB required for a full GNH—a 25,000x reduction.
  • High Accuracy: The $\mathcal{H}$-matrix approximation achieved high precision (up to 4 digits) and outperformed standard methods like K-FAC and Randomized SVD (RSVD) on autoencoder tasks where the Hessian spectrum decays slowly.

Conclusion

This work demonstrates that the $N$-dependency in Hessian evaluation can be broken, allowing for advanced linear algebra tools to be applied to deep learning. Future work includes extending this framework to Convolutional Neural Networks (CNNs) and integrating the approximation into full training loops to evaluate real-world speedups.

Summary updated

Abstract

We introduce a fast algorithm for entry-wise evaluation of the Gauss-Newton Hessian (GNH) matrix for the fully-connected feed-forward neural network. The algorithm has a precomputation step and a sampling step. While it generally requires $O(Nn)$ work to compute an entry (and the entire column) in the GNH matrix for a neural network with $N$ parameters and $n$ data points, our fast sampling algorithm reduces the cost to $O(n+d/ε^2)$ work, where $d$ is the output dimension of the network and $ε$ is a prescribed accuracy (independent of $N$). One application of our algorithm is constructing the hierarchical-matrix (H-matrix) approximation of the GNH matrix for solving linear systems and eigenvalue problems. It generally requires $O(N^2)$ memory and $O(N^3)$ work to store and factorize the GNH matrix, respectively. The H-matrix approximation requires only $O(N r_o)$ memory footprint and $O(N r_o^2)$ work to be factorized, where $r_o \ll N$ is the maximum rank of off-diagonal blocks in the GNH matrix. We demonstrate the performance of our fast algorithm and the H-matrix approximation on classification and autoencoder neural networks.
BibTeX
@misc{chen2019fast,
  author = {Chao Chen and Severin Reiz and Chenhan D. Yu and Hans‐Joachim Bungartz and George Biros},
  title = {{Fast Approximation of the Gauss-Newton Hessian Matrix for the Multilayer Perceptron}},
  year = {2019},
  eprint = {1910.12184},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.12184},
}
Figure