Quantization Variation: A New Perspective on Training Transformers with Low-Bit Precision

Xijie Huang, Zhiqiang Shen, Pingcheng Dong, Kwang-Ting Cheng

Abstract

Despite the outstanding performance of transformers in both language and vision tasks, the expanding computation and model size have increased the demand for efficient deployment. To address the heavy computation and parameter drawbacks, quantization is frequently studied in the community as a representative model compression technique and has seen extensive use on ConvNets. However, due to the unique properties of transformers, the low-bit quantization applications are still limited and underexplored. In this paper, we identify the difficulty of transformer low-bit quantization-aware training on its unique variation behaviors, which significantly differ from ConvNets. Based on comprehensive quantitative analysis, we observe variation in three hierarchies: various module quantization sensitivities, outliers in static weight and activation distribution, and oscillation in dynamic parameter fluctuations. These variations of transformers bring instability to the quantization-aware training (QAT) and negatively influence the performance. We explore the best practices to alleviate the variation's influence during low-bit transformer QAT and propose a variation-aware quantization scheme for both vision and language transformers. We extensively verify and show our scheme can alleviate the variation and improve the performance of transformers across various models and tasks. Our solution substantially improves the 2-bit Swin-T and binary BERT-base, achieving a 3.35% and 1.4% accuracy improvement over previous state-of-the-art methods on ImageNet-1K and GLUE.

Introduction

Transformers have revolutionized artificial intelligence across vision and language domains, but their massive parameter counts and computational demands pose significant challenges for deployment on resource-constrained edge devices. Quantization—reducing the precision of weights and activations from 32-bit floating point to low-bit integers—offers a promising path for compression. However, while convolutional neural networks (ConvNets) adapt well to quantization, Transformers often encounter a severe "accuracy cliff" when pushed to extreme low-bit levels like 2-bit or binary representations.

The Root Cause: Quantization Variation

The researchers identify the primary hurdle as Quantization Variation. Unlike the relatively stable training dynamics of ConvNets, Transformers exhibit instability across three distinct hierarchies:

  1. Heterogeneous Sensitivity: Not all components of a Transformer are created equal. Through "leave-one-out" analysis, the authors discovered that the Value (V) matrices in Multi-Head Self-Attention (MHSA) are significantly more sensitive to precision loss than the Query (Q) or Key (K) matrices.
  2. Distribution Outliers: Weights and activations in Transformers often follow "spiky" distributions with extreme outliers. These outliers make it difficult for standard quantization methods to find an optimal scaling factor without losing critical information.
  3. Weight Oscillation: A phenomenon largely unique to Transformers where latent weights frequently "flip-flop" across quantization boundaries during training. This prevents the model from converging to a stable, high-performing state.
The three hierarchies of Quantization Variation: (a) module sensitivity, (b) distribution outliers, and (c) weight oscillation.

A Variation-Aware Quantization Scheme

To address these challenges, the paper proposes a comprehensive "variation-aware" quantization framework:

  • Module-dependent Quantization: Instead of a one-size-fits-all approach, the authors assign distinct learnable scales to the Q, K, and V matrices. They also employ gradient scaling to prevent outliers from dominating the learning process.
  • Multi-crop Knowledge Distillation (MCKD): For Vision Transformers (ViTs), a high-precision "teacher" model guides the low-bit "student." By using multiple random crops of the same image, the student receives a richer, more stable supervision signal that helps it ignore minor data variances.
  • Oscillation-aware Bin Regularization (OBR): To stabilize training, the authors introduced a regularizer that penalizes weights for being near quantization boundaries. This forces weights to cluster around the centers of their assigned "quantization bins," effectively anchoring them and ensuring smoother convergence.

Experimental Results

The proposed methods were evaluated on ImageNet-1K for vision tasks (DeiT, Swin, SReT) and the GLUE benchmark for language tasks (BERT-base). The results demonstrate a significant leap over previous state-of-the-art (SOTA) techniques.

Performance comparison on vision (Top-1 Accuracy vs BitOPs) and language (GLUE benchmark) tasks.

Key highlights include:

  • 2-bit Swin-T: Achieved 77.66% Top-1 accuracy on ImageNet, a 3.35% improvement over previous methods.
  • Binary (1-bit) BERT: Reached an average GLUE score of 74.9, outperforming the previous best (BiT) by 1.4 points.
  • Training Efficiency: By stabilizing the training process, the authors achieved these results in half the usual time—150 epochs instead of 300.
  • Hardware Viability: Simulations in a 40nm CMOS process indicate that the module-dependent approach requires 32% less area and 12% less power than traditional mixed-precision methods.

Conclusion

By shifting the focus to the unique "variations" inherent in Transformer training, this work provides a robust roadmap for extreme low-bit quantization. While the current regularization techniques are most effective for 1-bit and 2-bit models, future research may extend these insights to Large Language Models (LLMs), where activation outliers and parameter scales present even greater deployment hurdles.

Summary updated

BibTeX
@article{huang2024quantization,
  author = {Xijie Huang and Zhiqiang Shen and Pingcheng Dong and Kwang-Ting Cheng},
  title = {{Quantization Variation: A New Perspective on Training Transformers with Low-Bit Precision}},
  journal = {Accepted by TMLR},
  year = {2024},
  url = {https://openreview.net/forum?id=MHfoA0Qf6g},
}
Figure