Hyperspherical Loss-Aware Ternary Quantization

Dan Liu, Xue LiuarXiv 2022 · DOI

Introduction

Deep Neural Networks (DNNs) have achieved remarkable success across various domains, yet their deployment on resource-constrained edge devices remains a significant challenge due to high memory and computational requirements. Ternary quantization, which restricts weights to three values ({-1, 0, 1}), offers a compelling solution by reducing weight representation to just 2 bits. However, the transition from continuous full-precision weights to discrete ternary values often introduces a "quantization gap," leading to substantial accuracy degradation.

The authors propose Hyperspherical Loss-Aware (HLA) Ternary Quantization to bridge this gap. By leveraging hyperspherical regularization and a novel gradient re-scaling mechanism, HLA achieves near-full-precision performance on large-scale benchmarks like ImageNet.

Methodology

The HLA framework introduces a multi-stage approach to stabilize the quantization process, focusing on weight distribution and gradient stability.

Hyperspherical Regularization

A core innovation of HLA is the use of a hyperspherical regularization term ($L_d$). Instead of immediate discretization, the method minimizes the cosine distance between full-precision weights and their intended ternary targets. This "pre-quantization" phase effectively nudges weights into three distinct clusters—negative, zero, and positive—within a continuous space.

Evolution of weight distributions during the pre-quantization phase.

As shown in the figure above, as the sparsity factor $t$ increases, the weight distribution shifts from a standard Gaussian-like curve to a tri-modal distribution. This preparation ensures that the final "snap" to discrete ternary values preserves the essential semantic information of the model.

Gradient Re-scaling and Sparsity Control

Standard quantization often suffers from inaccurate gradients due to the non-differentiable nature of the rounding operation. HLA addresses this by introducing a "bell-shaped" gradient re-scaling factor $S = 1 - w^2$. This factor simulates temperature-based annealing, reducing the magnitude of gradients for weights far from the quantization thresholds. This leads to more stable optimization compared to the traditional Straight-Through Estimator (STE).

Furthermore, HLA employs a gradual sparsity control mechanism. By slowly increasing the percentage of weights destined to become zero, the network is given time to adapt its internal representations to a sparser structure, preventing the sudden "shock" of high-rate pruning.

Key Results

The effectiveness of HLA was evaluated on the ImageNet (ILSVRC12) dataset using several popular architectures, including ResNet-18, ResNet-50, and the more challenging MobileNetV2.

Performance comparison of HLA against other ternary quantization methods.

As summarized in the table above, HLA consistently outperforms existing state-of-the-art ternary quantization methods. For ResNet-18, HLA achieves a Top-1 accuracy of 68.6%, coming within 1.2% of the full-precision baseline. Notably, on MobileNetV2—an architecture notoriously difficult to quantize—HLA reaches 58.7% accuracy, significantly surpassing previous methods like BRECQ (56.3%).

Beyond classification, HLA also demonstrates robustness in complex tasks like object detection. On the MS COCO dataset, a ternary Mask R-CNN with a ResNet-50 backbone achieved a Box AP of 35.8, proving that the hyperspherical approach generalizes well to multi-task learning environments.

Conclusion

Hyperspherical Loss-Aware Ternary Quantization represents a significant step forward in model compression. By focusing on the angular direction of weights and providing a smoother transition to discrete values, HLA minimizes the accuracy loss typically associated with ultra-low bit-width quantization. While future work may explore extending these principles to ternary activations, HLA currently provides a highly effective and easy-to-implement pipeline for deploying high-performance DNNs on edge hardware.

Summary updated

BibTeX
@misc{liu2022hyperspherical,
  author = {Dan Liu and Xue Liu},
  title = {{Hyperspherical Loss-Aware Ternary Quantization}},
  year = {2022},
  eprint = {2212.12649},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2212.12649},
}
Figure