SPFQ: A Stochastic Algorithm and Its Error Analysis for Neural Network Quantization

Jinjie Zhang, Rayan Saab · Submission to ICLR 2024 · Rejected

TL;DR

The authors introduce Stochastic Path Following Quantization (SPFQ), a post-training quantization algorithm that pairs greedy coordinate updates with stochastic rounding to compress deep neural networks. By injecting zero-mean randomness into the quantizer, the paper provides the first end-to-end, multi-layer theoretical error bounds for path-following quantization, proving that relative quantization error decays linearly as network width increases, even with as few as $O(\log \log N)$ bits per weight.

What Problem Does This Paper Address?

Quantization reduces the memory footprint and compute demands of deep neural networks (DNNs) by replacing high-precision floating-point weights with low-bit integers. While post-training quantization (PTQ) is fast and does not require retraining, rigorous theoretical guarantees on quantization error have historically been restricted to single isolated layers.

Extending error analysis to deep, multi-layer networks has been a longstanding theoretical roadblock. Deterministic rounding of weights alters intermediate activations; once these perturbations propagate through multiple non-linear activations (like ReLU), the resulting statistical dependencies become mathematically intractable.

Methods

The authors tackle this challenge by introducing SPFQ (Stochastic Path Following Quantization):

  • Stochastic Rounding Quantizer ($\mathcal{Q}_{\text{StocQ}}$): Instead of deterministically snapping a scalar to its nearest grid point, SPFQ rounds probabilistically such that the expected quantized value equals the unquantized target ($\mathbb{E}[\mathcal{Q}(z)] = z$).
  • Two-Phase Algorithmic Pipeline: SPFQ decomposes layer-wise quantization into two decoupled steps:
  • Data Alignment Phase: Identifies a set of real-valued "virtual weights" $\widetilde{w}$ so that the output under perturbed inputs $\widetilde{X}$ closely mimics the unquantized forward pass $X w$ ($\widetilde{X}\widetilde{w} \approx Xw$). This can be solved either perfectly via an $\ell_\infty$-norm minimization linear program or approximately via an $r$-th order greedy sequential projection costing only $O(r m N)$.
  • Quantization Phase: Quantizes $\widetilde{w}$ using greedy stochastic path-following.
  • Convex Order Analysis: Because stochastic rounding errors have conditional mean zero, the authors control error accumulation across layers using the mathematical framework of convex stochastic ordering ($\le_{\text{cx}}$) and Gaussian concentration, bounding error propagation through successive Lipschitz activations.

Datasets

  • Evaluated on ILSVRC-2012 (ImageNet) validation set (1,000 classes, 50,000 validation images) using standard center-cropped $224 \times 224$ inputs.
  • Tested on standard pretrained models from PyTorch torchvision: VGG-16, ResNet-18, and ResNet-50.
  • No new datasets were introduced.

Key Insights and Ideas

  • Randomness restores analytical tractability: In deterministic PTQ, downstream activation distributions are unpredictable. By making the quantizer itself stochastic and conditionally unbiased, error vectors behave like martingales. Their variances can be bounded recursively through orthogonal projections, regardless of activation non-linearities.
  • Over-parametrization actively suppresses error: For random Gaussian networks of depth $L$, the expected relative squared error at the network output satisfies: $$\frac{\|\Phi(X) - \widetilde{\Phi}(X)\|_F^2}{\mathbb{E}_\Phi\|\Phi(X)\|_F^2} \lesssim \frac{m (\log N_{\max})^{L+1}}{N_{\min}}$$ where $N_{\min}$ is the minimum layer width and $m$ is the calibration batch size. Wider networks are inherently more robust to post-training quantization.

  • $\mathbf{O(\log\log N)}$ bits prevent overflow: To preserve infinite-alphabet guarantees on a finite integer grid, the internal values of the quantizer must not exceed the alphabet boundary. The authors prove that an alphabet size $K \gtrsim \log N$ suffices—meaning each weight requires only $b \approx \log_2(K) \gtrsim \log \log N$ bits to match infinite-precision theoretical guarantees.

Key Results

On the ImageNet classification benchmark (using approximate alignment with $r=1$ and small calibration batches):

  • 6-bit Quantization: Drops top-1 accuracy by only 0.35% on VGG-16 ($71.59\% \to 71.24\%$), 0.33% on ResNet-18 ($69.76\% \to 69.43\%$), and 0.47% on ResNet-50 ($76.13\% \to 75.66\%$).
  • 5-bit Quantization: Drops top-1 accuracy by 0.51% (VGG-16), 0.97% (ResNet-18), and 1.08% (ResNet-50).
  • Comparison to Deterministic GPFQ: While deterministic GPFQ retains an advantage at very low bit-widths ($b=3, 4$) and small batch sizes, SPFQ closes the gap as batch size $m$ grows and matches or slightly outperforms deterministic GPFQ at 6 bits.

Limitations and Future Work

  • Low-bit degradation: Pure stochastic rounding exhibits higher empirical variance than deterministic nearest-neighbor rounding at 3-bit or 4-bit regimes when calibration batch size $m$ is small.
  • Computational trade-offs: Perfect data alignment eliminates alignment error entirely, but requires solving an $\ell_\infty$ linear program ($O(m^2 N)$ complexity), which is substantially slower than the linear-time approximate alignment heuristic.
  • Distributional assumptions: While the worst-case absolute error bounds require minimal assumptions, the relative error guarantees rely on independent Gaussian weight distributions to rule out adversarial weight alignments.

Summary updated

Abstract

Quantization is a widely used compression method that effectively reduces redundancies in over-parameterized neural networks. However, existing quantization techniques for deep neural networks often lack a comprehensive error analysis due to the presence of non-convex loss functions and nonlinear activations. In this paper, we propose a fast stochastic algorithm for quantizing the weights of fully trained neural networks. Our approach leverages a greedy path-following mechanism in combination with a stochastic quantizer. Its computational complexity scales only linearly with the number of weights in the network, thereby enabling the efficient quantization of large networks. Importantly, we establish, for the first time, full-network error bounds, under an infinite alphabet condition and minimal assumptions on the weights and input data. As an application of this result, we prove that when quantizing a multi-layer network having Gaussian weights, the relative square quantization error exhibits a linear decay as the degree of over-parametrization increases. Furthermore, we demonstrate that it is possible to achieve error bounds equivalent to those obtained in the infinite alphabet case, using on the order of a mere $\log\log N$ bits per weight, where $N$ represents the largest number of neurons in a layer.
BibTeX
@misc{zhang2023spfq,
  author = {Jinjie Zhang and Rayan Saab},
  title = {{SPFQ: A Stochastic Algorithm and Its Error Analysis for Neural Network Quantization}},
  year = {2023},
  eprint = {2309.10975},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2309.10975},
}

Loading related content...

Figure