Optimal and Approximate Adaptive Stochastic Quantization

Ran Ben-Basat, Yaniv Ben-Itzhak, Michael Mitzenmacher, shay vargaftik

TL;DR

This paper introduces QUIVER, a new family of algorithms that makes Adaptive Stochastic Quantization (ASQ) practical for large-scale machine learning. By reducing the computational complexity from quadratic to linear, the authors enable optimal, unbiased quantization of million-element vectors in under a second—up to four orders of magnitude faster than previous state-of-the-art methods.

What Problem Does This Paper Address?

In machine learning, quantization is the process of reducing the precision of data (like model weights or gradients) to save memory and bandwidth. Stochastic Quantization is a specific flavor where values are rounded randomly to ensure the result is unbiased (the expected value remains the original value). This property is crucial for maintaining accuracy in distributed training.

The "gold standard" for accuracy is Adaptive quantization, where the quantization levels are optimized for a specific input rather than a generic distribution. However, finding these optimal levels is a non-convex problem. Historically, the best way to solve it was via Dynamic Programming (DP) with a runtime of $O(s \cdot d^2)$ and memory of $O(d^2)$, where $d$ is the vector dimension and $s$ is the number of quantization levels. For modern ML models with millions of parameters, this quadratic cost made optimal adaptive quantization "dead on arrival" for real-time use.

Methods

The authors propose QUIVER (and its accelerated variants), which leverages several algorithmic breakthroughs to achieve $O(s \cdot d)$ time and space complexity:

  1. Constant-Time Variance Calculation: They use a preprocessing step with cumulative sum arrays (similar to prefix sums) to calculate the sum of variances between any two quantization points in $O(1)$ time.
  2. The Quadrangle Inequality: The researchers prove that the cost function for this problem satisfies the "quadrangle inequality." This mathematical property allows them to use the SMAWK algorithm, which finds the row minima of a matrix in linear time, effectively slashing the complexity of the Dynamic Programming steps.
  3. Accelerated QUIVER: They derive a closed-form solution for the $s=3$ case, allowing the algorithm to place two quantization values at a time, further halving the number of required iterations.
  4. Approximate QUIVER: For scenarios requiring extreme speed, they introduce a version that discretizes the search space into $m$ bins, resulting in a runtime of $O(d + m \cdot s)$, which is independent of the vector size $d$ after an initial linear pass.

Datasets

The authors evaluated their algorithms using synthetic datasets that mimic the statistical properties of real-world ML data:

  • LogNormal and Normal distributions: Commonly used to model DNN gradients.
  • Exponential and Weibull distributions: Often seen in deep activation layers.
  • Truncated Normal: Used to simulate bounded weights.

The experiments scaled up to vectors with $d = 2^{24}$ (approx. 16 million) entries to demonstrate the efficiency of the linear-time approach.

Key Insights and Ideas

  • Unbiasedness is a Superpower: While biased methods might yield a lower Mean Squared Error (MSE) for a single vector, they fail to scale in distributed settings. For distributed mean estimation (e.g., averaging gradients from many workers), unbiased methods are vastly superior because their errors cancel out as more workers are added.
Comparison of biased and unbiased quantization methods for single vs. distributed estimation.
  • The Quadratic Wall is Breakable: The most significant "aha moment" is realizing that the ASQ problem structure fits the requirements for SMAWK optimization. This transforms a "theoretical but slow" solution into a "production-ready" one.
  • Discretization Trade-offs: The authors show that you don't need to consider every single input value as a potential quantization level. By picking levels from a uniform grid (Approximate QUIVER), you can achieve near-optimal accuracy with massive speedups.

Key Results

  • Massive Speedups: QUIVER is up to 10,000x faster than the previous standard (ZipML).
  • Scalability: While previous methods crashed due to memory limits at $d=2^{17}$, QUIVER easily handles $d=2^{24}$.
  • Real-world Performance: On a standard PC, QUIVER can compute optimal 4-bit quantization for a 1-million-element vector in less than a second. The approximate version does it in just 6 milliseconds.
  • Accuracy: QUIVER consistently achieves lower MSE than non-adaptive methods like QSGD or NUQSGD, especially on skewed data distributions.

Limitations and Future Work

  • CPU vs. GPU: Currently, QUIVER is designed for CPUs. While the authors show that offloading the sorting step to a GPU helps, the core DP algorithm isn't naturally "GPU-friendly" due to its sequential nature. Designing a native GPU version is a noted area for future work.
  • Sorting Requirement: The exact version of QUIVER requires the input vector to be sorted ($O(d \log d)$). While fast, this is still a bottleneck for the very largest vectors.
  • Multi-dimensional Quantization: This work focuses on scalar quantization (one value at a time). Extending these efficiency gains to vector quantization (grouping values) remains an open challenge.

Summary updated

BibTeX
@inproceedings{benbasat2024optimal,
  author = {Ran Ben-Basat and Yaniv Ben-Itzhak and Michael Mitzenmacher and shay vargaftik},
  title = {{Optimal and Approximate Adaptive Stochastic Quantization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=8ZLL6mu2qC},
}
Figure