Enhancing Low-Precision Sampling via Stochastic Gradient Hamiltonian Monte Carlo

Ziyi Wang, Yujie Chen, Qifan Song, Ruqi Zhang

Abstract

Training deep neural networks is increasingly reliant on low-precision arithmetic to manage computational costs. However, Bayesian sampling—essential for uncertainty quantification—is highly sensitive to the quantization noise introduced by these formats. This paper investigates Stochastic Gradient Hamiltonian Monte Carlo (SGHMC) as a robust alternative to standard Langevin dynamics in low-precision settings. We demonstrate that SGHMC's momentum term naturally buffers against quantization errors, leading to a quadratic theoretical speedup in convergence for complex distributions. Empirical evaluations on CIFAR-100 and MNIST confirm that SGHMC maintains superior accuracy and calibration even with 8-bit arithmetic, establishing it as a robust framework for efficient Bayesian deep learning.

Introduction

The demand for efficient deep learning has led to the widespread adoption of low-precision numerical formats (e.g., 8-bit or 4-bit floats). While these formats accelerate standard optimization, their impact on Bayesian inference is less understood. Bayesian sampling methods like Stochastic Gradient Langevin Dynamics (SGLD) are notoriously sensitive to gradient noise, which is exacerbated by the rounding errors (quantization) inherent in low-precision environments. This research addresses whether momentum-based samplers, specifically SGHMC, can provide the necessary robustness to make low-precision Bayesian inference both fast and accurate.

Methods

The study explores Low-Precision SGHMC, adapting Hamiltonian Monte Carlo variants to restricted numerical formats. Three primary implementations are analyzed:

  1. SGHMCLP-F (Full-precision accumulators): Maintains high-precision weight copies, quantizing them only during gradient computation.
  2. SGHMCLP-L (Low-precision accumulators): Stores all variables in low precision. While memory-efficient, this can lead to "overdispersion" where samples spread excessively due to rounding noise.
  3. VC SGHMCLP-L (Variance-Corrected): A novel approach using a specialized quantization function to correct variance, ensuring samples accurately reflect the target distribution.

The authors provide the first rigorous theoretical convergence analysis for these samplers under both strongly log-concave and non-log-concave (multimodal) distributions.

Theoretical Insights: Momentum as a Noise Filter

A key finding is that the momentum term in SGHMC serves as a buffer against quantization noise. While SGLD is easily derailed by the stochastic errors of 8-bit rounding, SGHMC’s momentum smooths these updates, enhancing robustness.

The theoretical analysis reveals significant gains in gradient complexity. For non-log-concave distributions, SGHMC achieves a quadratic improvement over SGLD. To reach a target error level $\epsilon$, SGHMC requires $\tilde{O}(\epsilon^{-2})$ iterations, whereas SGLD requires $\tilde{O}(\epsilon^{-4})$.

Table 1: Comparison of gradient complexity and 2-Wasserstein distance for various samplers under full and low-precision settings.

As shown in the table above, the variance-corrected (VC) versions of the algorithms help mitigate the error bounds in low-precision settings, particularly for complex, non-log-concave targets where the achieved 2-Wasserstein distance is significantly improved.

Empirical Results

The proposed methods were validated on synthetic distributions, MNIST (Logistic regression and MLPs), and CIFAR-10/100 (ResNet-18).

  • Accuracy and Robustness: On CIFAR-10, low-precision SGHMC reduced test error by 1.19% compared to low-precision SGLD. On MNIST, SGHMC remained stable with as few as 2 fractional bits, while SGLD's performance significantly degraded.
  • Calibration: SGHMC consistently achieved lower Expected Calibration Error (ECE), indicating more reliable uncertainty estimates—a primary goal of Bayesian deep learning.
  • Convergence Speed: Empirical evidence confirms that SGHMC reaches lower loss levels in fewer iterations than SGLD across nearly all tested configurations, supporting the theoretical quadratic speedup.

Conclusion and Future Work

SGHMC proves to be a superior framework for low-precision Bayesian sampling, offering both theoretical advantages and practical performance gains. However, challenges remain. Theoretical bounds for non-log-concave distributions still include non-vanishing error terms as iterations increase, and convergence rates remain sensitive to dimensionality. Future research should focus on sharpening these mathematical bounds and measuring actual energy savings on specialized hardware like FPGAs or custom ASICs.

Summary updated

BibTeX
@article{wang2024enhancing,
  author = {Ziyi Wang and Yujie Chen and Qifan Song and Ruqi Zhang},
  title = {{Enhancing Low-Precision Sampling via Stochastic Gradient Hamiltonian Monte Carlo}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2024},
}
Figure