Low-Precision Stochastic Gradient Langevin Dynamics

Ruqi Zhang, Andrew Gordon Wilson, Christopher De Sa

TL;DR

This paper presents the first comprehensive study of low-precision Stochastic Gradient Langevin Dynamics (SGLD), demonstrating that Bayesian sampling can be significantly accelerated using 8-bit representations without sacrificing performance. The authors show that SGLD is inherently more robust to quantization noise than SGD and introduce a novel variance-corrected quantization function to prevent catastrophic divergence when using low-precision gradient accumulators.

What Problem Does This Paper Address?

While low-precision arithmetic (like 8-bit training) has revolutionized standard deep learning optimization, low-precision sampling has remained largely unexplored. Sampling methods like SGLD are essential for Bayesian deep learning because they capture model uncertainty and improve generalization by exploring the parameter space rather than converging to a single point. However, storing and processing multiple full-precision model samples incurs massive memory and computational costs.

Directly applying standard quantization techniques to SGLD introduces a major hurdle: when using low-precision gradient accumulators, the algorithm arbitrarily diverges from the target distribution at small stepsizes. Since small stepsizes are precisely what SGLD requires to minimize asymptotic bias, this represents a fundamental incompatibility that the authors set out to solve.

Methods

The authors analyze two main paradigms for low-precision SGLD:

  1. SGLDLP-F (Full-Precision Accumulators): Maintains a high-precision weight buffer to accumulate updates, only quantizing the weights during forward and backward propagation.
  2. SGLDLP-L (Low-Precision Accumulators): Keeps weights entirely in low precision to maximize hardware efficiency and speed.

To fix the divergence issue inherent to SGLDLP-L, the authors identify that standard stochastic rounding injects unwanted extra variance into each update step. They propose a new Variance-Corrected Quantization function ($Q^{vc}$). Instead of quantizing a continuous Gaussian sample, $Q^{vc}$ directly samples from a discrete weight space grid designed to preserve both the exact target mean and variance of the continuous SGLD update step.

Datasets

The authors evaluated their approaches across a variety of standard machine learning benchmarks:

  • MNIST: Used for baseline verification via logistic regression and a two-layer Multilayer Perceptron (MLP).
  • CIFAR-10 & CIFAR-100: Evaluated using a ResNet-18 architecture.
  • IMDB: A sentiment classification dataset evaluated using a two-layer LSTM.
  • ImageNet: Large-scale image classification evaluated using ResNet-18.

Key Insights and Ideas

  • Sampling Loves Noise: SGLD is naturally more robust to quantization errors than SGD. Because SGLD already injects Gaussian noise to explore the posterior distribution, it naturally counteracts and tolerates the noise introduced by rounding numbers to lower precisions.
  • The "Half-Bit" Advantage: Mathematically, the authors prove that on non-quadratic energy functions, SGLD's convergence error scales at a rate of $O(\Delta_W^2)$ relative to the quantization gap, whereas SGD scales at $O(\Delta_W)$. Asymptotically, this means SGLD requires roughly half the number of bits as SGD to achieve the same level of accuracy.
  • The Small Stepsize Paradox: In low-precision optimization, smaller stepsizes usually help convergence. In naive low-precision SGLD, however, a smaller stepsize amplifies the relative variance error from quantization, causing the distribution to completely blow up.

Key Results

  • Divergence Fixed: In toy experiments on a standard Gaussian distribution, the naive low-precision accumulator method completely fails as the stepsize decreases. In contrast, the proposed variance-corrected method (VC SGLDLP-L) perfectly tracks the true distribution.
Figure 1. Low-precision SGLD with varying stepsizes on a Gaussian distribution. Variance-corrected SGLD with low-precision gradient accumulators (VC SGLDLP-L) and SGLD with full-precision gradient accumulators (SGLDLP-F) converge to the true distribution, whereas na¨ıve SGLDLP-L diverges and the divergence increases as the stepsize decreases.
  • 8-Bit Sufficiency: Across CIFAR and IMDB datasets, 8-bit SGLD (using either fixed-point or block floating-point representations) achieved performance comparable to full-precision SGLD, consistently outperforming low-precision SGD counterparts. For instance, on CIFAR-100, VC SGLDLP-L outperformed SGDLP-L by 2.24%.
  • Preserved Calibration: Low-precision SGD typically suffers from severe overconfidence, leading to high Expected Calibration Error (ECE). Low-precision SGLD maintains excellent calibration, matching or even improving upon full-precision uncertainty estimates.

Limitations and Future Work

  • Scale Challenges with Low-Precision Accumulators: While the full-precision accumulator variant (SGLDLP-F) succeeded on the large-scale ImageNet dataset, the authors could not achieve stable, reasonable results using fully low-precision accumulators on ImageNet, citing difficulties with hyperparameter tuning.
  • Theoretical Gap: The current theoretical convergence bound for the variance-corrected method shows a looser dependency on the quantization gap than what is observed in practice. The authors note that tightening this theoretical bound remains an open task for future work.

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