Abstract
Quantization is essential for deploying deep neural networks on resource-constrained devices, yet training low-bit models remains challenging due to the non-differentiable nature of the rounding function. The standard Straight-Through Estimator (STE) often leads to sub-optimal results by ignoring discretization errors. We present Element-Wise Gradient Scaling (EWGS), a method that adaptively scales gradients based on discretization errors and Hessian information. EWGS improves training stability and accuracy, enabling 4-bit models to surpass full-precision baselines on ImageNet.
Introduction
Deep learning models are increasingly deployed on edge devices like smartphones and IoT hardware, where memory and power are limited. Network quantization—reducing the precision of weights and activations to low bit-widths (e.g., 2-bit or 4-bit)—is a primary technique to meet these constraints. However, the rounding function used in quantization has a derivative of zero almost everywhere, preventing standard backpropagation.
The conventional workaround is the Straight-Through Estimator (STE), which approximates the gradient of the rounding function as an identity mapping. While effective, STE introduces a significant gradient mismatch because it treats all values identically, regardless of their distance from the nearest discrete level. This "coarse" approximation can stall training or lead to poor local minima, especially at ultra-low bit-widths.
Element-Wise Gradient Scaling (EWGS)
To address the limitations of STE, we propose Element-Wise Gradient Scaling (EWGS). Unlike STE, which simply copies the gradient, EWGS scales the gradient based on the discretization error ($x_n - x_q$) and the sign of the gradient itself.
As shown in the comparison between STE and EWGS, STE propagates the gradient without modification. In contrast, EWGS adaptively scales the gradient to better reflect the underlying loss landscape, encouraging values to move toward more optimal discrete levels.
The core EWGS formula modifies the gradient $g_{x_n}$ for the latent value $x_n$ as follows: $$g_{x_n} = g_{x_q} (1 + \delta \cdot \text{sign}(g_{x_q})(x_n - x_q))$$ where $g_{x_q}$ is the gradient of the quantized value, and $\delta$ is a scaling factor. If a latent value is far from its quantized point and the gradient direction suggests moving further away, EWGS scales the gradient up to encourage the value to transition to the next discrete level.
Adaptive Scaling via Hessian Information
A key challenge in gradient scaling is determining the optimal scaling factor $\delta$. Rather than manual tuning, EWGS utilizes Hessian (second-order) information to adaptively adjust $\delta$. Since computing the full Hessian is computationally prohibitive, we employ Hutchinson’s method to estimate the Hessian trace efficiently. This allows the model to adjust scaling for each layer based on its sensitivity to quantization errors, capturing the unique characteristics of each layer's loss landscape.
Experimental Results
We evaluated EWGS on standard image classification benchmarks, including CIFAR-10 and ImageNet (ILSVRC-2012), using architectures like ResNet-18, ResNet-34, and MobileNet-V2.
Performance on ImageNet
EWGS demonstrates significant improvements over existing quantization methods. On ImageNet with ResNet-18, a 4-bit (weights and activations) model trained with EWGS achieved 70.6% top-1 accuracy, notably outperforming the 32-bit full-precision baseline of 69.9%.
| Method | Bit-width (W/A) | Top-1 Acc (%) |
|---|---|---|
| Full Precision | 32/32 | 69.9 |
| STE (Baseline) | 4/4 | 69.2 |
| EWGS | 4/4 | 70.6 |
| XNOR-Net | 1/1 | 51.2 |
| EWGS | 1/1 | 55.3 |
Robustness and Compatibility
EWGS is particularly effective for ultra-low bit-widths (1-bit or 2-bit), where discretization errors are most pronounced. For 1-bit ResNet-18, EWGS reached 55.3% accuracy, a substantial gain over the classic XNOR-Net. Furthermore, EWGS is compatible with other quantization frameworks like DoReFa-Net or PROFIT, providing an additional performance boost when integrated.
Conclusion
Element-Wise Gradient Scaling (EWGS) provides a mathematically grounded alternative to the Straight-Through Estimator for training quantized networks. By incorporating discretization errors and second-order Hessian information into the gradient calculation, EWGS enables more stable and accurate training of low-precision models. Our results show that EWGS not only surpasses state-of-the-art quantization methods but can even allow low-bit models to exceed the performance of their full-precision counterparts.
Summary updated