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

Jinjie Zhang, Rayan Saab

Abstract

Quantization is a critical technique for compressing over-parameterized neural networks, yet providing rigorous error analysis for deep, multi-layer architectures remains a significant challenge due to non-convex loss functions and non-linear activations. This paper introduces Stochastic Path Following Quantization (SPFQ), a fast post-training algorithm that leverages a greedy path-following mechanism and a stochastic quantizer. We establish the first full-network error bounds under minimal assumptions, demonstrating that quantization error decays linearly as network over-parametrization increases. Furthermore, we show that achieving near-optimal error bounds requires only $O(\log \log N)$ bits per weight, where $N$ is the number of neurons per layer.

Introduction

As deep neural networks (DNNs) continue to grow in scale, their deployment on resource-constrained edge devices is limited by memory and computational overhead. Quantization—the process of mapping high-precision weights (e.g., 32-bit float) to a discrete, finite alphabet (e.g., 4-bit or 6-bit integers)—is a standard solution.

Despite its empirical success, a theoretical gap persists. Most existing error analyses are restricted to single layers or shallow networks. Tracking error propagation through deep architectures is mathematically difficult because non-linear activations, such as ReLU, render the statistical distribution of signals across layers intractable. SPFQ bridges this gap by providing a framework that accounts for the cumulative error across the entire network.

The SPFQ Algorithm

SPFQ builds upon the Greedy Path Following Quantization (GPFQ) framework but introduces a critical element of randomness to facilitate theoretical analysis and improve performance.

1. Stochastic Quantizer

Unlike deterministic quantizers that round weights to the nearest available value, SPFQ employs a stochastic rounding mechanism. This randomness allows the use of the Convex Order mathematical framework to bound the error. By treating the quantization process as a stochastic approximation, the authors can bypass the complexities of tracking exact signal distributions through non-linearities.

2. Two-Phase Pipeline

The algorithm operates in two distinct phases:

  • Phase I (Data Alignment): The algorithm identifies a "virtual" weight vector that ensures the output of the quantized layer aligns as closely as possible with the original layer's output given the input data.
  • Phase II (Quantization): These virtual weights are then mapped to the finite alphabet using the stochastic quantizer.

3. Computational Efficiency

SPFQ is a post-training quantization (PTQ) method, meaning it does not require retraining the model. Its computational complexity scales linearly with the number of weights ($O(w)$), making it highly efficient for massive modern architectures.

Theoretical Insights

The Blessing of Over-parametrization

A primary contribution of this work is the proof that quantization error actually benefits from network width. The authors demonstrate that the relative square quantization error exhibits a linear decay ($1/N$) as the number of neurons in a layer increases. This suggests that larger, more over-parameterized networks are inherently more robust to quantization noise.

Log-Log Bit Scaling

The paper establishes that to achieve error bounds equivalent to an infinite alphabet (continuous weights), one only needs a bit-depth on the order of $\log \log N$. For a layer with 1,000 neurons, this implies that very low bit-widths are sufficient to maintain high fidelity. This provides a theoretical justification for the success of 4-bit and 5-bit quantization in large-scale models like LLMs and CNNs.

Experimental Results

The researchers evaluated SPFQ on the ImageNet (ILSVRC-2012) dataset using VGG-16, ResNet-18, and ResNet-50 architectures.

  • High Fidelity: At 6-bit quantization, SPFQ achieved less than a 0.5% drop in Top-1 accuracy across all tested models.
  • Low Bit-Width Performance: At 4 bits, the accuracy degradation remained minimal, with VGG-16 losing approximately 1.1% and ResNet-18 losing approximately 2.4%.
  • Batch Size Scaling: The performance of the stochastic algorithm improves with the batch size ($m$) used for the quantization process. As $m$ increases, the gap between SPFQ and deterministic methods closes, with SPFQ often outperforming counterparts at higher bit-widths.

Conclusion and Future Work

SPFQ provides a robust theoretical foundation for understanding why deep network quantization works. By introducing stochasticity, the authors developed a tractable error analysis for full-network architectures.

Future research directions include extending these proofs to a wider variety of activation functions (e.g., GeLU, Swish) and addressing the simultaneous quantization of both weights and activations. Additionally, refining the hyperparameter tuning for the quantization alphabet step-size could further automate the deployment of SPFQ across diverse hardware targets.

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},
}
Figure