Low-Precision Stochastic Gradient Langevin Dynamics

Ruqi Zhang, Andrew Gordon Wilson, Christopher De Sa

Introduction

Low-precision arithmetic has revolutionized neural network training by drastically reducing memory and computational requirements. However, its application to Bayesian sampling methods like Stochastic Gradient Langevin Dynamics (SGLD) has remained largely unexplored. Bayesian Deep Learning (BDL) provides state-of-the-art uncertainty estimation and generalization by sampling from the posterior distribution of a neural network's weights, rather than converging to a single point estimate.

While SGLD is highly effective, it is computationally and memory-intensive, requiring the storage of model ensembles and multiple forward passes. Naively applying standard low-precision techniques (like 8-bit quantization) to SGLD—especially when using low-precision gradient accumulators to maximize hardware efficiency—causes the algorithm to diverge arbitrarily far from the target distribution. This paper investigates the root causes of this divergence and introduces a novel variance-corrected quantization method to enable highly accurate, memory-efficient Bayesian deep learning.

Low-Precision Training Regimes

The authors analyze two distinct low-precision training regimes for SGLD:

  1. Full-Precision Gradient Accumulators (SGLDLP-F): In this regime, weights and gradients are quantized, but the gradient updates are accumulated in a full-precision buffer. Mathematical proofs demonstrate that this approach is highly robust to quantization noise.
  2. Low-Precision Gradient Accumulators (SGLDLP-L): Here, all components, including accumulators, are kept in low precision. The authors discovered that standard stochastic rounding fails in this regime because it injects excess variance into the system, disrupting the delicate noise balance required by Langevin dynamics.

The Variance-Corrected Quantization Solution

To resolve the divergence in the fully low-precision regime, the authors introduce a variance-corrected quantization function ($Q^{vc}$). Instead of quantizing a real-valued Gaussian sample—which artificially inflates variance—$Q^{vc}$ directly samples from the discrete weight space. This ensures the quantized updates maintain the exact mean and variance required by SGLD, preventing divergence with minimal computational overhead.

Density plots comparing Naive SGLDLP-L, VC SGLDLP-L, and SGLDLP-F against the true distribution.

Key Insights

  • Inherent Robustness of Sampling: Because SGLD naturally injects noise to explore the weight space, it is inherently more tolerant to the noise introduced by low-precision quantization than standard SGD.
  • Bit Efficiency: Theoretically, on strongly convex functions, SGLD requires only half the number of fractional bits as SGD to achieve the exact same convergence accuracy.
  • The Role of Variance: The failure of naive fully low-precision SGLD with small stepsizes is not due to a biased mean, but rather the inflated variance caused by stochastic rounding. Correcting this variance restores the sampler's integrity.
  • Ensemble Compensation: SGLD averages predictions over an ensemble of models. This group averaging naturally compensates for the coarse, low-precision representations of individual models.

Empirical Results

The methods were rigorously evaluated across various architectures and datasets (MNIST, CIFAR-10/100, IMDB, and ImageNet):

  • Superior Bit Efficiency: On MNIST, SGLD recovered full-precision performance using just 6 bits, whereas SGD required 10 bits for comparable accuracy.
  • Improved Accuracy: On CIFAR-100 using 8-bit fixed-point arithmetic, the variance-corrected low-precision SGLD (VC SGLDLP-L) outperformed its SGD counterpart by a significant 2.24%.
  • Large-Scale Success: On ImageNet (using 8-bit block floating point), low-precision SGLD beat low-precision SGD by 0.76% in top-1 error. This performance gap is actually wider than the gap between the two algorithms in full 32-bit precision.
  • Excellent Calibration: Low-precision SGLD maintains exceptional uncertainty calibration (Expected Calibration Error). Conversely, low-precision SGD becomes significantly more overconfident and poorly calibrated due to quantization noise.

Limitations and Future Work

While empirical results demonstrate that the variance-corrected method works exceptionally well on highly non-convex deep neural networks, the current theoretical proofs assume strongly log-concave distributions. Furthermore, the theoretical convergence bound for VC SGLDLP-L currently only matches SGD, despite empirically outperforming it. Closing this theoretical-empirical gap and scaling fully low-precision gradient accumulators to massive datasets like ImageNet remain exciting avenues for future research.

Summary updated

BibTeX
@inproceedings{zhang2022low,
  author = {Ruqi Zhang and Andrew Gordon Wilson and Christopher De Sa},
  title = {{Low-Precision Stochastic Gradient Langevin Dynamics}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=XhMa8XPHxpw},
}
Figure