Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Low-precision sampling

When running simulations for a dynamic system on a computer, the impact of round-off errors on number representations (e.g., floating-point representations) can not be naïvely presumed to be negligible. It has been observed that a large deviation can occur between numerical behavior and the theoretical behaviour Guihéneuf, 2015. In Bayesian literature, the same question arises: how does the rounding error from computer simulation affect the convergence property of a Markov chain? Roberts et al. (1998) shows a rather alarming example that a well-behaved Markov chain (with Feller continuity and geometrical ergodicity) becomes transient (i.e., will not converge to any target distribution) after adding an arbitrarily small roundoff error. Hoffman (2021) also warned that roundoff errors can severely degrade the performance of the Metropolis-Hastings sampling algorithm. To sum up, a common wisdom for conventional MCMC practice is to utilize high-precision numerical representations to limit the negative impact of roundoff errors. However, in this chapter, we will embrace the low-precision representations in the era of SG-MCMC samplers.

Low-Precision Deep Neural Network

The rise of large-scale deep neural networks (DNNs) and large language models (LLMs) has led to significant computational and memory costs of model training and inference. To improve efficiency, low-precision deep learning Hubara et al., 2016Jacob et al., 2018Rastegari et al., 2016Zhang et al., 2018Zhou et al., 2016Li et al., 2017 — which uses fewer bits to represent values of model parameters, activations, and gradients, and thus can substantially lower resource demands — has emerged as a promising direction. Precision formats such as 16-bit (FP16), 8-bit (INT8), 4-bit, and even binary (1-bit) offer memory reduction, energy savings, and speedup in inference, enabling deployment on edge devices and platforms, and specialized accelerators. On the other hand, well-designed low-precision optimization algorithms can maintain the model utility, such that the performance degradation from full-precision models to low-precision models is tolerable.

Modern foundations of low-precision deep learning include Gupta et al. (2015), which leverages 16-bit wide fixed-point arithmetic and stochastic rounding to accelerate the training speed of DNNs, and Vanhoucke et al. (2011), which discusses the possibility of running DNN inference on x86 CPUs rather than GPUs using 8-bit fixed-point arithmetic. In general, there are two directions for achieving lower precision representations of DNN models: quantization-aware training (QAT) and post-training quantization (PTQ). The former simulates quantization during the training process, allowing the model to learn a robust solution that accounts for quantization errors induced by rounding; the latter, on the other hand, applies quantization to off-the-shelf pre-trained models. It is arguably true that QAT outperforms PTQ in terms of better accuracy, but incurs greater computational costs of model training. Other worth mentioning techniques of low-precision models are, but not limited to, non-uniform quantization and mixed precision training. Opposite to conventional quantization methods that map floating point values to an evenly spaced quantized target space, non-uniform quantization chooses an unevenly spaced quantized target space that can allocate more quantization levels where the values are dense. This unevenly spaced quantized target space can be of logarithmic scale Miyashita et al., 2016, or adaptively learned from the training process Zhang et al., 2018. Mixed-precision methods Dong et al., 2019Micikevicius et al., 2017 assign different bit-widths to different layers of the neural networks or different computation steps of the training, leveraging the fact that different components of DNNs have varying sensitivities to quantization error. Theoretical investigations related to low-precision training are available in Li et al. (2017)Sa et al. (2018)Sakr et al. (2019)Markov et al. (2023).

Inevitably, low-precision optimization achieves better efficiency at the expense of performance sacrifice. One natural way to mitigate performance degradation caused by quantization error is low-precision Bayesian sampling. We argue that posterior sampling is particularly suited for low-precision arithmetic because of its inherent robustness to system noise. In particular: (1) Bayesian posterior explores plausible weight space instead of converging to a single point, thus it should not require precise weights and be tolerant to non-full-precision models; and (2) it allows us to perform model averaging during inference using an ensemble of models sampled from the posterior, which compensates for the performance drop caused by coarse representations of individual models Zhu et al., 2019.

Low-Precision SG-MCMC

Preliminary

The Bayesian counterpart of QAT directly samples low-precision models (i.e., low-precision weights of the neural network) from a target distribution (typically, a Bayesian posterior distribution). A straightforward idea is to adapt existing Monte Carlo sampling algorithms for low-precision sampling tasks. In the regime of deep learning, where the training data sets are usually massive, the SG-MCMC sampling algorithm (see Chapter Stochastic Gradient MCMC) is the most suitable choice since it can avoid a full scan of the data set when calculating the likelihood terms.

Now we briefly recall two seminal SG-MCMC algorithms, the SGLD and SGHMC. Given a dataset D\mathcal D, a statistical model with parameters θRP\theta\in \mathbb{R}^P, and a prior p(θ)p(\theta), we aim to sample from the posterior p(θD)exp(U(θ))p(\theta| \mathcal D)\propto \exp( -U(\theta )), where the energy function is defined as

U(θ)=(x,y)Dlogp(x,yθ)logp(θ).U(\theta) = -\sum_{(x,y)\in\mathcal D}\log p(x,y|\theta)-\log p(\theta).

Stochastic Gradient Langevin Dynamics (SGLD) updates the parameter in the (k+1)(k+1)-th step following the rule

θk+1=θkαU~(θk)+2αξk+1,\begin{align} \theta_{k+1} = \theta_{k} -\alpha\nabla\tilde{U}(\theta_{k}) + \sqrt{2\alpha}\xi_{k+1}, \end{align}

where α\alpha is the stepsize, ξk+1\xi_{k+1} is standard Gaussian noise, and the stochastic gradient U~\nabla\tilde U is an unbiased estimator of U\nabla U based on a subset of the dataset D\mathcal D. The use of stochastic gradients helps reduce the computational cost. Compared to the Stochastic Gradient Descent (SGD) update, the only difference is that SGLD adds an additional Gaussian perturbation at each step, enabling SGLD to characterize the full distribution rather than converge to a single point. Due to this close connection, it is convenient to implement SGLD on existing deep learning tasks for which SGD is the default learning algorithm.

Stochastic Gradient HMC Chen et al., 2014 is derived by replacing U\nabla U with a noisy gradient U~+ξ\nabla \tilde U+\xi in the Hamiltonian Monte Carlo, and boils down to the unadjusted underdamped Langevin algorithm with stochastic gradient, where the underdamped Langevin dynamics can be defined as

dvt=γvtdtuU(θt)dt+2γudBtdθt=vtdt,\begin{split} \,\mathrm{d} v_t &= -\gamma v_t \,\mathrm{d} t - u \nabla U(\theta_t) \,\mathrm{d} t + \sqrt{2\gamma u} \,\mathrm{d} \mathbf{B}_t \\ \,\mathrm{d} \theta_t &= v_t\,\mathrm{d} t, \end{split}

where uu, γ\gamma denote the hyperparameters of the inverse mass and friction, respectively. Furthermore, Cheng et al. (2018) proposed the following discretization of underdamped Langevin dynamics (3) with stochastic gradient:

vk+1=vkeγηuγ1(1eγη)U~(θk)+ξkvθk+1=θk+γ1(1eγη)vk+uγ2(γη+eγη1)U~(θk)+ξkθ,\begin{align} v_{k+1} &= v_{k}e^{-\gamma\eta} - u\gamma^{-1}(1-e^{-\gamma\eta}){\nabla \tilde U}(\theta_k) + \xi_{k}^{v} \\ \nonumber \theta_{k+1} &= \theta_k + \gamma^{-1}(1-e^{-\gamma\eta}) v_k+u\gamma^{-2}(\gamma\eta+e^{-\gamma\eta}-1){\nabla \tilde U}(\theta_k)+\mathbf{\xi}_{k}^{\theta}, \end{align}

where ξkv\mathbf{\xi}_{k}^{v}, ξkθ\mathbf{\xi}_{k}^{\theta} are normal distributed in RP\mathbb{R}^P satisfying that :

Eξkv(ξkv)=u(1e2γη)I,Eξkθ(ξkθ)=uγ2(2γη+4eγηe2γη3)I,Eξkθ(ξkv)=uγ1(12eγη+e2γη)I.\begin{align} \nonumber \mathbb{E} \mathbf{\xi}_k^{v}(\mathbf{\xi}_k^{v})^\intercal &= u(1-e^{-2\gamma\eta}) \cdot \mathbf{I},\\ \mathbb{E}\mathbf{\xi}_k^{\theta}(\mathbf{\xi}_k^{\theta})^\intercal &= u\gamma^{-2}(2\gamma\eta+4e^{-\gamma\eta}-e^{-2\gamma\eta}-3) \cdot \mathbf{I}, \\ \nonumber \mathbb{E} \mathbf{\xi}_k^{\theta}(\mathbf{\xi}_k^{v})^\intercal &= u\gamma^{-1}(1-2e^{-\gamma\eta}+e^{-2\gamma\eta}) \cdot \mathbf{I}. \end{align}

Before formally introducing the low-precision SG-MCMC algorithms, we review the basic concepts of low-precision training. To represent numbers, e.g., the weights of a DNN, in low-precision, one simple way is to use fixed-point representation, which has been utilized in both theory and practice Gupta et al., 2015Li et al., 2017Yang et al., 2019. Specifically, suppose that we use WW bits to represent a number, where FF of those WW bits are used to represent the fractional part. Then, there is a gap between consecutive representable numbers, Δ=2F\Delta=2^{-F}, which is called* quantization gap*. In addition, the representable numbers also have a lower bound L=2WF1L= -2^{W-F-1} and an upper bound U=2WF12FU = 2^{W-F-1}-2^{-F}. Therefore, when the number of bits (i.e., WW and FF) decreases, the accuracy and range of number representation decreases. This chapter will use this type of number representation in our theoretical analysis and empirical demonstration, following existing literature Li et al., 2017Yang et al., 2019.

Another popular number representation is floating point, where each number is decomposed into its own sign, exponent, and significand (or mantissa). Between fixed point and floating point,* block floating point* allows numbers within a block to share a common exponent Song et al., 2018. This chapter will also present some deep learning experiments using block floating point for deep learning experiments since it has been shown to be more favourable for deep models Yang et al., 2019.

Given the low-precision number representations, we also need a quantization function (or a quantizer) QQ which converts a real-valued number into a low-precision number. Popular choices include deterministic rounding and* stochastic rounding*. More specifically, the deterministic rounding function QdQ^d quantizes a number to its nearest representable neighbour, i.e.,

Qd(θ)=sign(θ)clip(ΔθΔ+12,L,U),Q^d(\theta) = \text{sign}(\theta)\cdot \text{clip}\left(\Delta\left\lfloor\frac{|{\theta}|}{\Delta}+\frac{1}{2}\right\rfloor, L, U\right),

where clip(x,L,U)=max[min(x,U),L]\text{clip}(x,L,U) = \max[\min(x,U),L] and the above operator is applied to the whole vector elementwisely. On the other hand, stochastic rounding QsQ^s quantizes a number to one of its representable neighbours based on a probabilistic rule:

Qs(θ)={clip(ΔθΔ,L,U),w.p. θΔθΔclip(ΔθΔ,L,U),w.p. 1(θΔθΔ).\begin{align*} Q^s(\theta) = \begin{cases} \text{clip}\left(\Delta\left\lfloor\frac{\theta}{\Delta}\right\rfloor, L, U\right), &\text{w.p. } \left\lceil\frac{\theta}{\Delta}\right\rceil - \frac{\theta}{\Delta} \\ \text{clip}\left(\Delta\left\lceil\frac{\theta}{\Delta}\right\rceil, L, U\right), &\text{w.p. } 1-\left(\left\lceil\frac{\theta}{\Delta}\right\rceil - \frac{\theta}{\Delta}\right). \end{cases} \end{align*}

A key design property of QsQ^s is that E[Qs(θ)]=θ\mathbb{E}\left[Q^s(\theta)\right]=\theta, meaning the quantized number is unbiased. QsQ^s is generally preferred over QdQ^d in practice since it can preserve gradient information, especially when the scale of the gradient update is smaller than the quantization gap (which is always quantized to 0 if QdQ_d is implemented) Gupta et al., 2015Wang et al., 2018. In what follows, we utilize stochastic rounding as our quantizer, and when necessary, QWQ_W and ΔW\Delta_W denote the weights’ quantizer and quantization gap, QGQ_G and ΔG\Delta_G denote gradients’ quantizer and quantization gap.

To perform a gradient update in low-precision presentations, there are two common strategies depending on whether we keep an additional copy of full-precision weights. The SGD with Full-precision gradient accumulators (SGDLP-F) algorithm uses a full-precision weight buffer to accumulate gradient updates and only quantizes weights before computing gradients. Particularly, it updates the weights as follows,

θk+1=θkαQG(U~(QW(θk))),\theta_{k+1} = \theta_{k} - \alpha Q_G\left(\nabla\tilde{U}(Q_W\left(\theta_{k})\right)\right),

where θk+1\theta_{k+1} and θk\theta_k are full-precision during the update, and the gradient computation is quantized for forward and backward propagation Courbariaux et al., 2015Li et al., 2017.

Gradient accumulators need to be frequently updated during training. Hence, to further reduce the computational costs, low-precision gradient accumulators represent them in low-precision format, and SGD with low-precision gradient accumulators (SGDLP-L) performs the update as follows,

θk+1=QW(θkαQG(U~(θk))),\begin{align} \theta_{k+1} = Q_W\left(\theta_{k} - \alpha Q_G\left(\nabla\tilde{U}(\theta_{k})\right)\right), \end{align}

where θ\theta is always represented in low precision. In comparison, low-precision gradient accumulators are cheaper and faster due to having all numbers in low precision, whereas full-precision gradient accumulators better preserve small gradient updates, leading to better performance in general Courbariaux et al., 2015Li et al., 2017.

Low-Precision Stochastic Gradient Langevin Dynamics

In this section, we combine the low-precision rounding and the SGLD update (2). As shown in Equation (2), the update of a full-precision SGLD is simply a full-precision SGD update plus a Gaussian noise. Therefore, the low-precision counterpart of SGLD is naturally the low-precision SGLD training with an additional Gaussian noise in each step. Given the SGDLP-F, we can do low-precision SGLD with full-precision gradient accumulators (SGLDLP-F) as follows:

θk+1=θkαQG(U~(QW(θk)))+2αξk+1.\begin{align} \theta_{k+1} = \theta_{k} - \alpha Q_G\left(\nabla\tilde{U}(Q_W\left(\theta_{k})\right)\right) + \sqrt{2\alpha}\xi_{k+1}. \end{align}

Despite this small change, the Gaussian noise turns out to help counteract the rounding noise introduced by quantization, which makes SGLDLP-F more robust to inaccurate number representation and converges better than SGDLP-F as shown in Theorem 1.

To facilitate the theoretical analysis, we assume that the target distribution is smooth and strongly log-concave, and the energy function has a Lipschitz Hessian, i.e.,  θ,θRP\forall~ \theta,\theta'\in \mathbb{R}^P,

U(θ)U(θ)U(θ)(θθ)(m/2)θθ22,U(θ)U(θ)2Mθθ2,2U(θ)2U(θ)2Ψθθ2,E[U~(θ)U(θ)22]κ2.\begin{split} &U(\theta) - U(\theta') - \nabla U(\theta')^\intercal (\theta - \theta') \ge (m/2) \left\lVert \theta - \theta' \right\rVert_2^2, \\ &\left\lVert \nabla U(\theta) - \nabla U(\theta') \right\rVert_2 \le M \left\lVert \theta - \theta' \right\rVert_2, \\ &\| \nabla^2 U(\theta) - \nabla^2 U(\theta') \|_2 \le \Psi \| \theta - \theta' \|_2,\\ &\mathbb{E}\left[\| \nabla\tilde{U}(\theta) - \nabla U(\theta) \|_2^2 \right]\le \kappa^2. \end{split}

These assumptions are commonly used in the literature Dalalyan & Karagulyan, 2019Yang et al., 2019Zhang et al., 2022Wang et al., 2024.

This theorem shows that SGLDLP-F converges to the accuracy floor at

min(ΨΔW2P4m,MΔWP2m)\min\left( \frac{ \Psi \Delta_W^2 P }{4m}, \frac{M \Delta_W \sqrt{P}}{2 m} \right)

given a large iteration number KK and small stepsize α\alpha. Furthermore, if Ψ=0\Psi=0 (i.e., the energy function is quadratic), then SGLDLP-F indeed converges to the target distribution asymptotically. This is comparable to the optimization result that SGDLP-F converges to the optimum asymptotically on a quadratic lossLi et al., 2017. This theorem also recovers the bound of full-precision SGLD (i.e., ΔW=0\Delta_W=0) presented by Dalalyan & Karagulyan (2019). In general, when the energy function is not exactly quadratic, the convergence of SGLDLP-F to the target distribution has a O(ΔW2)\mathcal{O}(\Delta_W^2) rate, but SGDLP-F to the global optimum has a O(ΔW)\mathcal{O}(\Delta_W) rate Yang et al., 2019. Because ΔW=2F\Delta_W = 2^{-F} where FF is the number of fractional bits, it implies that to achieve the same convergence accuracy, SGLD only needs half the number of fractional bits as SGD needs. This advantage of SGLD over SGD fits into the literature of comparing sampling and optimization convergence bounds Ma et al., 2019Talwar, 2019.

To further reduce the computational costs, we can utilize low-precision gradient accumulators and mimic the update of SGDLP-L in Equation (9). Naturally, this leads to the following update rule of SGLD with low-precision gradient accumulators (SGLDLP-L),

θk+1=QW(θkαQG(U~(θk))+2αξk+1).\begin{align} \theta_{k+1} = Q_W\left(\theta_{k} - \alpha Q_G\left(\nabla\tilde{U}(\theta_{k})\right) + \sqrt{2\alpha }\xi_{k+1}\right). \end{align}

Unfortunately, unlike the convergence behaviour of SGLDLP-F, SGLDLP-L may diverge arbitrarily far away from the target distribution with a small stepsize.

Note that an α1\alpha^{-1} factor appears in one term on the right-hand side upper bound; this theorem implies that as the stepsize α\alpha of SGLDLP-L decreases, W2W_2 distance between the actual sampling distribution and the target distribution may increase. To empirically verify it, we run SGLDLP-L on a standard Gaussian distribution in Figure Figure 1 with the stepsize α=0.001\alpha=0.001 and 0.0001. The experiment uses 8-bit fixed-point, and 3 out of 8 bits are used to represent the fractional part. The simulations clearly demonstrate that SGLDLP-L diverges farther away from the target distribution under a smaller stepsize, whereas SGLDLP-F samples always successfully resemble the target distribution, aligning with the result in Theorem 1.

Low-precision SGLD with varying stepsizes on a normal 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"ive SGLDLP-L diverges and the divergence increases as the stepsize decreases.

(a)

Low-precision SGLD with varying stepsizes on a normal 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"ive SGLDLP-L diverges and the divergence increases as the stepsize decreases.

(b)

Low-precision SGLD with varying stepsizes on a normal 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"ive SGLDLP-L diverges and the divergence increases as the stepsize decreases.

(c)

Low-precision SGLD with varying stepsizes on a normal 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"ive SGLDLP-L diverges and the divergence increases as the stepsize decreases.

(d)

Low-precision SGLD with varying stepsizes on a normal 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"ive SGLDLP-L diverges and the divergence increases as the stepsize decreases.

(e)

Low-precision SGLD with varying stepsizes on a normal 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"ive SGLDLP-L diverges and the divergence increases as the stepsize decreases.

(f)

Figure 1:Low-precision SGLD with varying stepsizes on a normal 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"ive SGLDLP-L diverges and the divergence increases as the stepsize decreases.

One possible remedy is to choose a stepsize that minimizes the right handed side of (15). However, this is not feasible in practice since the constants (such as MM and mm) are general unknown. Moreover, enabling a small stepsize in SGLD is usually desirable, since a smaller stepsize helps reduce the asymptotic bias of the posterior approximation Welling & Teh, 2011.

One key reason causing the divergence of SGLDLP-L is that the variance of each dimension of θk+1\theta_{k+1} becomes larger due to using low-precision gradient accumulators. More precisely, given the stochastic gradient U~\nabla\tilde{U}, the update of full-precision SGLD is equivalent to sampling from a Gaussian distribution

θk+1,iN(θk,iαU~(θk)i,2α),for each dimension i=1,,P.\theta_{k+1,i}\sim\mathcal{N}\left(\theta_{k,i} - \alpha \nabla\tilde{U}(\theta_{k})_i, 2\alpha \right), \text{for each dimension } i=1,\ldots, P.

Note that both the weight quantizer QWQ_W and the gradient quantizer QGQ_G are unbiased stochastic rounding, hence SGLDLP-L satisfies

Eθk+1,i=EQW(θk,iαQG(U~(θk))i+2αξk+1,i)=θk,iαU~(θk)i,\begin{align*} \mathbb{E}\theta_{k+1,i} &= \mathbb{E} Q_W\left(\theta_{k,i} - \alpha Q_G\left(\nabla\tilde{U}(\theta_{k})\right)_i + \sqrt{2\alpha }\xi_{k+1,i}\right) =\theta_{k,i} - \alpha \nabla\tilde{U}(\theta_{k})_i, \end{align*}

which shares the same mean as θk+1\theta_{k+1} in full-precision. But on the other hand, the variance of θk+1,i\theta_{k+1,i} is now larger than needed. Let’s ignore the variance caused by QGQ_G and the stochastic gradient (since they are present and have been shown to work well in SGLDLP-F), then the variance of θk+1,i\theta_{k+1,i} is

Var(θk+1,i)=E[Var[QW(θk,iαU(θk)i+2αξk+1,i)|ξk+1,i]]+Var[E[QW(θk,iαU(θk)i+2αξk+1,i)|ξk+1,i]]=ΔW24χk+1,i+2α,\begin{align*} &\mbox{Var}(\theta_{k+1,i})\\ &=\mathbb{E}\left[\mbox{Var}\left[Q_W\left(\theta_{k,i} - \alpha \nabla U(\theta_{k})_i + \sqrt{2\alpha }\xi_{k+1,i}\right)\middle|\xi_{k+1,i}\right]\right]\\ &\hspace{0em}+ \mbox{Var}\left[\mathbb{E}\left[Q_W\left(\theta_{k,i} - \alpha \nabla U(\theta_{k})_i + \sqrt{2\alpha }\xi_{k+1,i}\right)\middle|\xi_{k+1,i}\right]\right]\\ &=\frac{ \Delta_W^2}{4} \chi_{k+1,i} + 2\alpha, \end{align*}

for some χk+1,i[0,1]\chi_{k+1,i}\in [0,1]. This result shows that the variance of the SGLDLP-L update is larger than the ideal variance value 2α2\alpha. Figure Figure 1 also reflects this, as the naïve SGLDLP-L estimates the mean correctly but the variance wrongly.

To correct the inflated variance and enable SGLD with low-precision gradient accumulators, Zhang et al. (2022) introduced a new variance-corrected quantization function QvcQ^{\text{vc}}. The main idea of QvcQ^{\text{vc}} is to directly sample from the discrete low-precision space instead of quantizing a real-valued Gaussian sample. To begin with, if we want a sample over {ΔW,ΔW,0}\{\Delta_W,-\Delta_W,0\} with mean μ0\mu\ge 0 and variance vΔW2/4v\le\Delta^2_W /4, we could sample it with the following categorical distribution,

Cat(μ,v)={ΔW,w.p.v+μ2+μΔW2ΔW2ΔW,w.p.v+μ2μΔW2ΔW2 0,otherwise\begin{align} \text{Cat}(\mu,v)= \begin{cases} \Delta_W, & w.p. \frac{v+\mu^2+\mu\Delta_W}{2\Delta_W^2}\\ -\Delta_W, & w.p. \frac{v+\mu^2-\mu\Delta_W}{2\Delta_W^2} \text{\hspace{1em} }\\ 0, & \text{otherwise} \end{cases} \end{align}

providing that the probability values are valid (i.e., non-negative and smaller than 1). To use this categorical distribution to preserve the correct mean and variance for quantized θk+1\theta_{k+1}, we consider two cases: (i) when the ideal variance 2α2\alpha is larger than the largest possible stochastic rounding variance, i.e., ΔW2/4\Delta_W^2/4, QvcQ^{\text{vc}} first adds a small Gaussian noise and uses the sampler in Equation (19) to make up the remaining variance; (ii) Otherwise, QvcQ^{\text{vc}} directly samples from Equation (19) to achieve the target variance. The full description of QvcQ^{\text{vc}} is described in Algorithm 1. It is not difficult to see that the use of Cat(,)\text{Cat}(\cdot,\cdot) sampler is valid in Algorithm 1, with the sampling probabilities being nonnegative. This variance-corrected quantizer leads to the following SGLDLP-L algorithm, named VC SGLDLP-L:

θk+1=Qvc(θkαQG(U~(θk)),2α,ΔW).\theta_{k+1} = Q^{\text{vc}}\left(\theta_{k} - \alpha Q_G\left(\nabla\tilde{U}(\theta_{k})\right), 2\alpha, \Delta_W\right).

The variance-corrected quantizer QvcQ^{\text{vc}} always guarantees the correct mean, E(θk+1,i)=θk,iαU~(θk)i\mathbb{E}(\theta_{k+1,i})= \theta_{k,i} - \alpha\nabla\tilde U(\theta_k)_i, and further ensures the variance Var(θk+1,i)\mbox{Var}(\theta_{k+1,i}) matches the ideal value 2α2\alpha most of the time except when v=2α<vsv=2\alpha<v_s, where vsv_s is defined in Algorithm 1. We argue that v=2α<vsv=2\alpha<v_s rarely happens in practice since the stepsize is often very small. Although QvcQ^{\text{vc}} only preserves the correctness of the first two moments (i.e., mean and variance), it is sufficient to achieve satisfactory performance in both theory and practice, as shown by Theorem 3 and later numerical evidence.

As shown by this theorem, when the stepsize α0\alpha \rightarrow 0, the distance between the sampling distribution of VC SGLDLP-L and the target distribution no longer diverges to infinity. Instead, under proper choices of α\alpha and KK, VC SGLDLP-L converges to the target distribution in O(ΔW)\mathcal{O}(\sqrt{\Delta_W}), which matches the convergence rate of SGD with low-precision gradient accumulators to the optimum Li et al., 2017Yang et al., 2019.

Numerical Experiments

Now we present some numerical results for these Langevin-based low-precision sampling algorithms. We evaluate the generalization accuracy and uncertainty estimation of SGLDLP-F and variance-corrected VC SGLDLP-L on the ResNet-18 model on the CIFAR datasets Krizhevsky et al., 2009Krizhevsky & Hinton, 2009. We use the same quantization for weights, gradients, activations, and backpropagation errors unless otherwise stated. By default, SGLD algorithms collect samples from the approximated posterior of the model’s weights and predict labels for test data via Bayesian model averaging. The comparison baseline is the performance of low-precision SGD, which is commonly used for frequentist low-precision deep learning Sun et al., 2019Sun et al., 2020. We use SGDFP, SGDLP-F, and SGDLP-L to denote full-precision SGD, low-precision SGD with full-precision gradient accumulators, and low-precision SGD with low-precision gradient accumulators, respectively. Both fixed-point and block-floating-point (BFP) low-precision formats are implemented. The numerical results are provided in Table 1, which reports average performance over 3 runs with the standard error.

Table 1:Test Error and ECE on CIFAR dataset with the ResNet-18 model.

Test Errors (%)

ECE

\downarrow

(%)

CIFAR-10

CIFAR-100

CIFAR-10

CIFAR-100

32-bit Floating Point

SGLDFP

4.65

±

0.06

22.58

±

0.18

1.11

3.92

SGDFP

4.71

±

0.02

22.64

±

0.13

2.53

4.97

8-bit Fixed Point

VC SGLDLP-L

7.13

±

0.01

26.62

±

0.16

0.60

3.19

SGDLP-L

8.53

±

0.08

28.86

±

0.10

3.40

10.38

SGLDLP-F

5.12

±

0.06

23.30

±

0.09

1.12

4.42

SGDLP-F

5.20

±

0.14

23.84

±

0.12

3.05

6.80

8-bit BFP

VC SGLDLP-L

5.51

±

0.01

25.22

±

0.18

0.60

5.82

SGDLP-L

5.86

±

0.18

26.19

±

0.11

4.23

12.97

SGLDLP-F

4.58

±

0.07

22.59

±

0.18

1.19

3.78

SGDLP-F

4.75

±

0.05

22.90

±

0.13

2.76

5.20

  1. Fixed Point: We use 8-bit fixed point for weights and gradients but keep the activations full-precision since low-precision activations significantly harm the empirical performance. The results show that SGLDLP-F is better than SGDLP-F, and VC SGLDLP-L significantly outperforms SGDLP-L. Moreover, the improvement of SGLD over SGD gets larger under more low-precision arithmetic: on CIFAR-100, VC SGLDLP-L outperforms SGDLP-L by 2.24% and SGLDLP-F outperforms SGDLP-F by 0.54%, but SGLDFP outperforms SGDFP merely by 0.06%. This suggests that SGLD is particularly suitable for low-precision deep learning because of its natural robustness against system noise.

  2. Block Floating Point: BFP is often preferred over fixed point on deep models since it causes less quantization error induced by overflow and underflow Song et al., 2018. Following the block design in Yang et al. (2019), we use small-block for ResNet experiments. Also, the QvcQ^{\text{vc}} function can naturally generalize to BFP with only a minor modification (see Zhang et al. (2022) for the detailed algorithm of QvcQ^{\text{vc}} with BFP). With BFP, the results of all low-precision methods improve over fixed-point counterparts. Specifically, SGLDLP-F performs as well as SGLDFP with all numbers quantized to 8-bit except gradient accumulators. Similar to the fixed-point case, SGLDFP-F and VC SGLDLP-L outperform low-precision SGD results. Overall, these results suggest the universal applicability of low-precision SGLD with different computer number formats.

  3. Expected Calibration Error: Besides accuracies, Table 1 also reports the results of expected calibration error (ECE, which measures how well a model’s predicted probabilities match its actual empirical accuracy) Guo et al., 2017 to demonstrate the uncertainty estimation of low-precision SGLD. The summarized results indicate that SGLDLP-F and VC SGLDLP-L achieve almost the same or even lower ECE than full-precision SGLD. It proves that SGLD retains the capability to provide well-calibrated predictions while using low-precision representations. VC SGLDLP-L sometimes gives lower ECE than SGLDLP-F, which may be due to the regularization effect of low-precision arithmetic. On the other hand, the ECE of low-precision SGD increases significantly compared to its full-precision counterpart, implying that the quantization error makes the standard DNNs more overconfident, which might lead to wrong decisions for corner cases in real-world applications.

Low-Precision Stochastic Gradient Hamiltonian Monte Carlo

In this section, we combine low-precision arithmetic with SGHMC algorithm (4). Recall that SGHMC is equivalent to a discretized underdamped Langevin algorithm with stochastic gradient. The stationary distribution of underdamped Langevin dynamics is defined on the augmented probability space: π(θ,v)exp(U(θ)v22/2u)\pi(\theta,v)\propto \exp( - U(\theta)-\|v\|_2^2/2u). Therefore, our theoretical investigation will investigate the 2-Wasserstein distance[1] between the distribution of (θK,vK)(\theta_K,v_K) and π(θ,v)\pi(\theta,v).

Adopting the update rule in equations (4), we introduce low-precision SGHMC with full gradient accumulators (SGHMCLP-F) as follows:

vk+1=vkeγηuγ1(1eγη)QG(U~(QW(θk)))+ξkvθk+1=θk+γ1(1eγη)vk+uγ2(γη+eγη1)QG(U~(QW(θk)))+ξkθ,\begin{align} v_{k+1} &= v_ke^{-\gamma\eta} - u\gamma^{-1}(1-e^{-\gamma\eta})Q_G({\nabla \tilde U}(Q_W(\theta_k)))+\mathbf{\xi}_k^v \\ \nonumber \theta_{k+1} &= \theta_k + \gamma^{-1}(1-e^{-\gamma\eta})v_k + u\gamma^{-2}(\gamma\eta+e^{-\gamma\eta}-1)Q_G(\nabla \tilde{U}(Q_W(\theta_k)))+\mathbf{\xi}_k^\theta, \end{align}

where the distributions of ξv\xi^v and ξθ\xi^\theta follow (5). SGHMCLP-F keeps full-precision parameters vkv_k, θk\theta_k at each iteration and quantizes them to low-precision representations before taking the gradient. Following the previous section, we still assume strong convexity of U(θ)U(\theta). In addition, we denote θ=argminθU(θ)\theta^*=\arg\min_\theta U(\theta) and ρ=M/m\rho= M/m, and assume ΔG=ΔW=Δ\Delta_G=\Delta_W=\Delta for the simplicity of analysis presented in the following sections.

Theorem 1 implies that under strongly log-concave target distributions, the low-precision SGLDLP-F also achieves ϵ\epsilon accuracy within O~(ϵ2log(ϵ1)(Δ2+1))\tilde{\mathcal{O}}\left(\epsilon^{-2}\log(\epsilon^{-1})(\Delta^2+1)\right) iterations with learning rate of order ϵ2/(Δ2+1)\epsilon^2/(\Delta^2+1). Thus, under strong convexity, SGHMCLP-F achieves no better convergence speed than SGLDLP-F. This is not surprising, since the quantization applied to the gradients in the full-precision gradient accumulator algorithm is equivalent to adding extra noise to the stochastic gradients. Theoretically, as shown by Cheng et al. (2018), for a strongly log-concave target distribution, SGHMC doesn’t exhibit any advantage over the overdamped Langevin algorithm, especially when stochastic gradients are used.

To reduce the computation cost, the SGHMC with low-precision gradient accumulators (SGHMCLP-L) can be trivially implemented as

vk+1=QW(vkeγηuγ1(1eγη)QG(U~(θk))+ξkv),θk+1=QW(θk+γ1(1eγη)vk+uγ2(γη+eγη1)QG(U~(θk))+ξkθ).\begin{align} v_{k+1} &= Q_W\left(v_{k}e^{-\gamma\eta}-u\gamma^{-1}(1-e^{-\gamma \eta})Q_G(\nabla \tilde{U}(\theta_k))+\mathbf\xi_k^v\right), \\ \nonumber \theta_{k+1} &= Q_W\left(\theta_k+\gamma^{-1}(1-e^{-\gamma\eta})v_k+u\gamma^{-2}(\gamma\eta+e^{-\gamma\eta}-1)Q_G(\nabla \tilde{U}(\theta_k))+\mathbf\xi_k^\theta\right). \end{align}

Similar to SGLDLP-L, SGHMCLP-L has intrinsic flaws. It directly quantizes the weights after each update, hence a small stepsize update is often quantized to zero update of θ\theta and vv, resulting in the sample distribution converging to a Dirac distribution at the initial point. In such cases, ensuring convergence becomes challenging. Wang et al. (2024) investigated the convergence of SGHMCLP-L under 2-Wasserstein distance, exhibiting that the naïve SGHMCLP-L has a much worse convergence upper bound than SGHMCLP-F. To remedy this, we adapt the variance correction quantizer (Algorithm 1) to SGHMCLP-L. Let Vvhmc=u(1e2γη)\mathbb{V}_{v}^{hmc} = u(1-e^{-2\gamma\eta}) and Vθhmc=uγ2(2γη+4eγηe2γη3)\mathbb{V}_{\theta}^{hmc} = u\gamma^{-2}(2\gamma\eta+4e^{-\gamma\eta}-e^{-2\gamma\eta}-3), which are the desired variances induced from the underdamped Langevin dynamics (4). The VC SGHMCLP-L can be done as follows:

vk+1=Qvc(vkeγηuγ1(1eγη)QG(U~(θk)),Vvhmc,Δ),θk+1=Qvc(θk+γ1(1eγη)vk+uγ2(γη+eγη1)QG(U~(θk)),Vθhmc,Δ).\begin{align} v_{k+1} &= Q^{\text{vc}}\left(v_ke^{-\gamma\eta}-u\gamma^{-1}(1-e^{-\gamma\eta})Q_G(\nabla \tilde{U}(\theta_k)), \mathbb{V}_v^{hmc}, \Delta\right), \\ \nonumber\theta_{k+1} &= Q^{\text{vc}}\left(\theta_k+\gamma^{-1}(1-e^{-\gamma\eta})v_k + u\gamma^{-2}(\gamma\eta+e^{-\gamma\eta}-1)Q_G(\nabla \tilde{U}(\theta_k)), \mathbb{V}_{\theta}^{hmc}, \Delta\right). \end{align}

Next, we present the convergence result for VC SGHMCLP-L under a strongly log-concave target distribution.

Theorem 5 shows that the variance-corrected quantization function resolves the overdispersion problem for the naïve SGHMCLP-L algorithm. The W2W_2 distance between the sample distribution and target distribution can be arbitrarily close to O~(Δ)\tilde{\mathcal{O}}(\sqrt{\Delta}). This convergence rate of VC SGHMCLP-L is the same as that of VC SGLDLP-L (see the discussion after Theorem 3).

Advantage of LP Stochastic Gradient HMC under Non-Convexity

So far, we have introduced the low-precision SGLD and SGHMC algorithms and explored their theoretical convergence behaviour. The theorems in previous sections don’t showcase any advantage of low-precision SGHMC over low-precision SGLDLP for strongly log-concave distributions. This doesn’t align with the common understanding of SGHMC performance. Cheng et al. (2018)Gao et al. (2022) showed that for both strongly log-concave and non-log-concave target distributions, SGHMC converges to the target faster than the best-known convergence rate of SGLD in the 2-Wasserstein distance. Beyond this, SGHMC is analogous to stochastic gradient methods augmented with momentum, which is shown to have more robust updates w.r.t. gradient estimation noise Liu et al., 2020. Since the quantization-induced stochastic error in low-precision updates acts as extra gradient noise, we expect that low-precision SGHMC can perform better than low-precision SGLD under certain scenarios beyond strong convexity of U(θ)U(\theta).

Wang et al. (2024) explored the convergence of low-precision SGHMC and SGLD under non-log-concave distributions. Instead of assuming U(θ)U(θ)U(θ)(θθ)(m/2)θθ22U(\theta) - U(\theta') - \nabla U(\theta')^\intercal (\theta - \theta') \ge (m/2) \left\lVert \theta - \theta' \right\rVert_2^2, the dissipative condition is considered:

U(θ),θmθ2b,for any  θRP.\langle \nabla U(\theta), \theta \rangle \geq m \left\lVert \theta \right\rVert^2 - b, \quad \mbox{for any}\; \theta \in \mathbb{R}^P.

Such an assumption is commonly used Raginsky et al., 2017Zou et al., 2019Gao et al., 2022 in the analysis of sampling from non-log-concave distributions. The theorem below summarizes the theoretical findings of Wang et al. (2024), which emphasize how the convergence rate depends on the quantization gap Δ\Delta.

Note that Δ<1\Delta<1 in general, thus Theorem 6 suggests that HMC-based low-precision sampling algorithms have better dependence on the quantization error than SGLD-based algorithms for non-log-concave distributions.

Numerical Experiments

Similarly to the experiment settings for low-precision SGLD, we consider image tasks CIFAR-10 and CIFAR-100 on the ResNet-18. The simulation results are summarized in Table 1. Together with Table 1, it shows that across all evaluation metrics, the low-precision SGHMC has either a better or comparable performance with its SGLD counterpart.

Table 2:Test Error and ECE on CIFAR dataset with the ResNet-18 model.

Test Errors (%)

ECE

\downarrow

(%)

CIFAR-10

CIFAR-100

CIFAR-10

CIFAR-100

32-bit Floating Point

SGHMCFP

4.78

±

0.08

22.37

±

0.04

0.72

1.52

8-bit Fixed Point

VC SGHMCLP-L

6.60

±

0.06

26.43

±

0.19

0.70

2.44

SGHMCLP-F

5.08

±

0.08

23.54

±

0.10

1.11

1.92

8-bit BFP

VC SGHMCLP-L

5.15

±

0.08

24.45

±

0.16

0.67

5.02

SGHMCLP-F

4.93

±

0.09

22.39

±

0.11

1.12

3.65

Post-Training Low-Precision Sampling

The previous section focuses on training low-precision Bayesian DNN models directly by SG-MCMC from scratch. In contrast, it is feasible first to train a full-precision (Bayesian) DNN and then obtain a low-precision Bayesian DNN model via additional processing, such as fine-tuning, over the pre-trained model. More relevant content about model compression with quantization can be found in Chapter Bayesian compression: with quantization

Quantized Pre-Trained Bayesian models

To convert a pre-trained Bayesian DNN to its low-precision counterpart, one common approach is to quantize the sampled weights yielded by the full-precision posterior sampling (e.g., from SG-MCMC algorithms). In simple words, let θ(1),,θ(T),\theta^{(1)},\dots,\theta^{(T)},\dots be the posterior samples in RP\mathbb{R}^P, then a post-training quantization technique is applied to each sample.

This process seems trivial, but there are multiple factors that need to be considered.

Sampling Thinning

Sample thinning refers to the selection of a subset from the original posterior samples. That is, only a proportion of samples will be quantized and used for low-precision Bayesian model average-based inferences, for the sake of computational efficiency. One would also avoid samples from the burn-in period of posterior sampling to reduce the sampling bias. One common way is to include one sample every other ff samples (where ff denotes the thinning frequency), skipping the first bb samples (where bb denotes the burn-in period length).

To determine the best thinned sample set, one needs to assess the quality of the samples, say how well the empirical distribution determined by this sample set resembles the true posterior distribution. To this end, we employ the Kernel Stein Discrepancy Gorham & Mackey, 2017. KSD is a distance measure between two distributions, where the target distribution is continuously differentiable with an intractable normalization constant. Given a kernel function k(,)k(\cdot,\cdot), we define the Stein Kernel as

kp(θ,ϑ)=θ,ϑk(θ,ϑ)θU(θ),ϑk(θ,ϑ)ϑU(ϑ),θk(θ,ϑ)+θU(θ),ϑU(ϑ)k(θ,ϑ).\begin{split} k_p(\theta,\vartheta) =& \langle\nabla_\theta, \nabla_\vartheta k(\theta,\vartheta)\rangle- \langle \nabla_\theta U(\theta) , \nabla_\vartheta k(\theta,\vartheta)\rangle \\ &- \langle \nabla_\vartheta U(\vartheta) , \nabla_\theta k(\theta,\vartheta)\rangle+ \langle \nabla_\theta U(\theta) , \nabla_\vartheta U(\vartheta) \rangle k(\theta,\vartheta). \end{split}

Then, the KSD between (the empirical distribution of) a sample θ(1),,θ(T)\theta^{(1)},\dots, \theta^{(T)} and the target distribution is

S(θ(1),,θ(T))=1T2i,j=1Tkp(θ(i),θ(j)).\mathbb S(\theta^{(1)},\dots, \theta^{(T)}) = \frac{1}{T^2}\sum_{i,j=1}^Tk_p(\theta^{(i)},\theta^{(j)}).

KSD can be used to search for the optimal choices of bb and ff or the whole subset Riabiz et al., 2022. However, it is worth mentioning that the computation of the Stein Kernel scales up quickly with the dimension dd, thus it could be very expensive for huge models.

Calibration of Quantization Range and Gap

If training low-precision (Bayesian) DNNs from scratch (e.g., Section Low-Precision SG-MCMC), one usually needs to determine the quantization scheme (e.g., the quantization gap Δ\Delta in the quantization functions QdQ^d or QsQ^s) beforehand. In contrast, when a pre-trained model is available (e.g., a full-precision posterior sample θ(t)\theta^{(t)}), we have direct access to the distribution of its weight values; we can use a representative dataset to approximate the distribution of activations along the forward propagation. This information can help us choose an appropriate quantization scheme to quantize this θ(t)\theta^{(t)} that fits the computational / memory budgets and has a small impact on its predictive performance. Note that in Section Low-Precision SG-MCMC, we only consider a rounding mechanism that maps a high-precision (e.g., full floating-point value) to its near low-bit fixed-point values. But in general, any mapping from real values to a discrete space can be used. For example, an uniform quantization Jacob et al., 2018 with WW-bit quantization is defined as

Qu(θ)=clip(θ,a,b)ass+a, with s=(ba)/(2W1),\begin{split} Q^u(\theta) = \left\lfloor\frac{\mbox{clip}(\theta,a,b)-a}{s}\right\rceil s + a, \mbox{ with } s = (b-a)/(2^W-1), \end{split}

where \lfloor\cdot\rceil denotes rounding to the nearest integer. Then aa and bb, which denote the quantization range, can be set as the minimum and maximum values among entries of the pre-trained model θ(t)\theta^{(t)}.

Parameter Fine-tuning

Although a quantized network Q(θ(t))Q(\theta^{(t)}) for some quantization function QQ is ready for inference, it may suffer significant performance drops. In such a case, one can first fine-tune the model θ(t)\theta^{(t)} for a small number of gradient descent steps to compensate for the performance drops caused by quantization, then apply quantization to the fine-tuned model.

Let f(x;θ)f(x;\theta) be the neural network model parameterized by the weight vector θ\theta, then the empirical loss is defined as

L(θ)=(x,y)Dlogp(x,yθ):=(x,y)Dl(y,f(x;θ)),\mathcal L(\theta) = -\sum_{(x,y)\in\mathcal D}\log p(x,y|\theta) := \sum_{(x,y)\in\mathcal D}l(y, f(x;\theta)),

for some loss function l(,)l(\cdot,\cdot). Instead of running fine-tuning gradient descent on L(θ)\mathcal {L}(\theta), we design a new neural network model fq(;θ)f^q(\cdot;\theta) which approximates f(;θ)f(\cdot;\theta) with quantization applied on weights and activations. For example, Jacob et al. (2018)Ferianc et al. (2021) insert simulated quantization modules after weights input and every tensor product operation. Therefore, running gradient descent on Lq=l(y,fq(x;θ))\mathcal L^q = \sum l(y, f^q(x;\theta)) initialized from θ(t)\theta^{(t)}, leads to a nearby model whose after-quantization performance is acceptable.

Quantize Pre-trained Variational Bayesian DNNs

If a pre-trained variational Bayesian neural network model (refer to Book Part %s for details) is given, one may additionally quantize the variational parameters Ferianc et al., 2021Subedar et al., 2021. Suppose that the variational posterior distribution of one weight entry θ(i)\theta_{(i)} is N(μ,σ2)\mbox{N}(\mu,\sigma^2), then given a quantization function QQ, the quantized posterior sample of θ(i)\theta_{(i)} is generated by Q(Q(μ)+Q(σ)ξ)Q(Q(\mu)+Q(\sigma)\xi) where ξ\xi is a standard Gaussian variable. To accommodate performance degradation induced by quantization, one can also incorporate additional fine-tuning for the variational parameters Ferianc et al., 2021, similarly to the procedure discussed in the above paragraph.

Low-Bit Sub-Distribution

As discussed earlier, a pre-trained full-precision model can provide valuable insights into the distribution of weight values and inform the design of a quantization scheme. The SG-MCMC algorithms in Section Low-Precision SG-MCMC yield posterior samples whose entries belong to an equally spaced discrete space S={0,±Δ,±2Δ,}\mathcal S=\{0, \pm\Delta, \pm2\Delta,\dots\}. When a pre-trained model is available, one can train a flexible discrete space S\mathcal S from which the posterior samples are drawn. The elements in S\mathcal S can be full floating-point values; thus, model weights of a neural network achieve low-bit representation by sharing the same full precision values in S\mathcal S. This can be viewed as a generalization of sparse DNN, which encourages network weights to share a common value of 0.

Given a pre-trained DNN model θ\theta, a straightforward method is to implement a clustering algorithm over the entries of θ\theta and obtain the cluster centers S={q1,,qM}\mathcal S=\{q_1, \dots, q_M\}. Then we would like to restrict the posterior samples to S\mathcal S. To accomplish this, we can adapt the mean-field variational Bayes (refer to Chapter Introduction to variational inference for details) and define the discrete variational distribution as

q(θ)=i=1Pm=1Mpim1(θ(i)=qm),θ=(θ(1),,θ(P))q(\theta) = \prod_{i=1}^P \sum_{m=1}^M p_{im}\mathbf{1}(\theta_{(i)}=q_m), \quad \theta=(\theta_{(1)},\dots,\theta_{(P)})

where variational parameters satisfy mpim=1\sum_m p_{im}=1. To facilitate the training of variational inference, we can introduce parametric modelling for pimp_{im} (e.g., pimp_{im} relates to θ(i)qm|\theta_{(i)}-q_m|, where θ(i)\theta_{(i)} is the pre-trained weight). To enhance the model performance, we can also allow q1,,qMq_1,\dots, q_M to update in the variational training procedure Dong et al., 2022.

It is worth mentioning that no actual low-precision sampling happens in the variational training process since variational inference boils down to an optimization problem for the variational parameters. Once these parameters are learned, the (approximate) posterior samples are easily drawn from (37).

Conclusions and Discussions

This chapter introduced low-precision sampling algorithms that are useful for modern Bayesian deep learning applications, including SG-MCMC-based direct low-precision samplers and post-training low-precision sampling techniques. These low-precision methods are crucial for deploying large models on resource-constrained hardware and improving Bayesian inference speed.

As discussed in the introduction section, one main reason for pursuing low-precision arithmetics is to reduce the memory and computation costs for DNN training or DNN inference. Beyond this, the low-precision representation is also helpful to reduce communication cost for scenarios where frequent information transfer among several parties is required, but only with limited bandwidth. One such emerging research field is federated learning (FL) Kairouz & McMahan, 2021. Federated learning is a learning paradigm where multiple parties (e.g., hospitals or edge devices) collaboratively train a global model while keeping the local training data private and decentralized. In a federated SGLD algorithm, each party computes the gradient based on its local data, and all local gradients are shared and aggregated via communication. The aggregated gradient is then used in the SGLD update (2) of the global model. Low-precision representations can be used to compress the gradient communications. Vono et al. (2022) utilized a stochastic rounding mechanism and studied how quantization error impacts the convergence of the global Bayesian model.

The theorems and algorithms in this chapter are mostly depicted regarding the theme that quantization of the weight parameter θ\theta suffices. However, neural networks have a multilayer structure, and quantization can be employed on each layer along the forward propagation process (i.e., online conversion of activation values to low-precision representations). In addition, normalization layers, such as Batch Normalization and Layer Normalization, are often sensitive to quantization error and may require different techniques (e.g., BatchNorm folding) to mitigate the impact of quantization. These issues are less explored and discussed in the field of Bayesian low-precision DNNs. Interested readers may refer to Gholami et al. (2022)Kim et al. (2023).

Footnotes
  1. The 2-Wasserstein distance between two probability measures μ\mu and ν\nu is defined as W2(μ,ν)=(γΓ(μ,ν)xy2dγ(x,y))1/2W_2(\mu,\nu)=\left(\int_{\gamma\Gamma(\mu,\nu)}\|x-y\|^2d\gamma(x,y)\right)^{1/2}, where Γ(μ,ν)\Gamma(\mu,\nu) denotes the set of joint distributions whose marginals are exactly μ\mu and ν\nu.

References
  1. Guihéneuf, P.-A. (2015). Dynamical properties of spatial discretizations of a generic homeomorphism. Ergodic Theory and Dynamical Systems, 35(5), 1474–1523.
  2. Roberts, G. O., Rosenthal, J. S., & Schwartz, P. O. (1998). Convergence properties of perturbed Markov chains. Journal of Applied Probability, 35(1), 1–11.
  3. Hoffman, M. D. (2021). Roundoff Error in Metropolis-Hastings Accept-Reject Steps. Third Symposium on Advances in Approximate Bayesian Inference.
  4. Hubara, I., Courbariaux, M., Soudry, D., El-Yaniv, R., & Bengio, Y. (2016). Binarized Neural Networks. In D. Lee, M. Sugiyama, U. Luxburg, I. Guyon, & R. Garnett (Eds.), Advances in Neural Information Processing Systems (Vol. 29). Curran Associates, Inc.
  5. Jacob, B., Kligys, S., Chen, B., Zhu, M., Tang, M., Howard, A., Adam, H., & Kalenichenko, D. (2018). Quantization and training of neural networks for efficient integer-arithmetic-only inference. Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 2704–2713.
  6. Rastegari, M., Ordonez, V., Redmon, J., & Farhadi, A. (2016). XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks. In B. Leibe, J. Matas, N. Sebe, & M. Welling (Eds.), Computer Vision – ECCV 2016 (pp. 525–542). Springer International Publishing.
  7. Zhang, D., Yang, J., Ye, D., & Hua, G. (2018). Lq-nets: Learned quantization for highly accurate and compact deep neural networks. Proceedings of the European Conference on Computer Vision (ECCV), 365–382.
  8. Zhou, S., Wu, Y., Ni, Z., Zhou, X., Wen, H., & Zou, Y. (2016). DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients.
  9. Li, H., De, S., Xu, Z., Studer, C., Samet, H., & Goldstein, T. (2017). Training Quantized Nets: A Deeper Understanding. In I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, & R. Garnett (Eds.), Advances in Neural Information Processing Systems (Vol. 30). Curran Associates, Inc.
  10. Gupta, S., Agrawal, A., Gopalakrishnan, K., & Narayanan, P. (2015). Deep Learning with Limited Numerical Precision. In F. Bach & D. Blei (Eds.), Proceedings of the 32nd International Conference on Machine Learning (Vol. 37, pp. 1737–1746). PMLR.
  11. Vanhoucke, V., Senior, A., & Mao, M. Z. (2011). Improving the speed of neural networks on CPUs. Deep Learning and Unsupervised Feature Learning Workshop, NIPS 2011.
  12. Miyashita, D., Lee, E. H., & Murmann, B. (2016). Convolutional Neural Networks using Logarithmic Data Representation.
  13. Dong, Z., Yao, Z., Gholami, A., Mahoney, M. W., & Keutzer, K. (2019). Hawq: Hessian aware quantization of neural networks with mixed-precision. Proceedings of the IEEE/CVF International Conference on Computer Vision, 293–302.
  14. Micikevicius, P., Narang, S., Alben, J., Diamos, G., Elsen, E., Garcia, D., Ginsburg, B., Houston, M., Kuchaiev, O., Venkatesh, G., & Wu, H. (2017). Mixed Precision Training.
  15. Sa, C. D., Leszczynski, M., Zhang, J., Marzoev, A., Aberger, C. R., Olukotun, K., & Ré, C. (2018). High-Accuracy Low-Precision Training.