Abstract
Vision transformer emerges as a potential architecture for vision tasks. However, the intense computation and non-negligible delay hinder its application in the real world. As a widespread model compression technique, existing post-training quantization methods still cause severe performance drops. We find the main reasons lie in (1) the existing calibration metric is inaccurate in measuring the quantization influence for extremely low-bit representation, and (2) the existing quantization paradigm is unfriendly to the power-law distribution of Softmax. Based on these observations, we propose a novel Accurate Post-training Quantization framework for Vision Transformer, namely APQ-ViT. We first present a unified Bottom-elimination Blockwise Calibration scheme to optimize the calibration metric to perceive the overall quantization disturbance in a blockwise manner and prioritize the crucial quantization errors that influence more on the final output. Then, we design a Matthew-effect Preserving Quantization for Softmax to maintain the power-law character and keep the function of the attention mechanism. Comprehensive experiments on large-scale classification and detection datasets demonstrate that our APQ-ViT surpasses the existing post-training quantization methods by convincing margins, especially in lower bit-width settings (e.g., averagely up to 5.17% improvement for classification and 24.43% for detection on W4A4). We also highlight that APQ-ViT enjoys versatility and works well on diverse transformer variants.
Introduction
Vision Transformers (ViTs) have revolutionized computer vision but come with a heavy computational price tag. While Post-Training Quantization (PTQ)—which compresses a model using only a small unlabeled dataset—is a practical solution for deployment, it often fails when pushed to ultra-low bit-widths like 4-bit weights and activations (W4A4).
Researchers identify two primary culprits for this failure: inaccurate calibration metrics that cannot perceive error accumulation across transformer blocks, and the sensitivity of the Softmax function's "power-law" distribution to standard quantization methods. To address these, the APQ-ViT framework introduces two novel components: Bottom-elimination Blockwise Calibration (BBC) and Matthew-effect Preserving Quantization (MPQ).
Methodology
Bottom-elimination Blockwise Calibration (BBC)
Instead of optimizing one layer at a time, BBC optimizes an entire Transformer Block as a single unit. This blockwise perception measures how quantization in one layer affects the output of the entire block.
Inspired by the observation that small gradients have minimal impact on learning, the authors implement "bottom-elimination." By pruning the Hessian matrix to ignore the smallest, trivial quantization errors, the optimization is forced to focus on significant errors that actually change the final prediction. This approach makes the calibration process more robust and efficient, reducing GPU memory footprint by approximately 80% compared to previous methods.
Matthew-effect Preserving Quantization (MPQ)
In sociology, the "Matthew Effect" describes how the rich get richer. Softmax behaves similarly: a few high scores receive the vast majority of "attention." Standard quantizers often try to maximize mutual information, which inadvertently spends too many bits on negligible values near zero, thereby "flattening" the attention and destroying the model's logic.
MPQ utilizes asymmetric linear quantization specifically for Softmax to intentionally prioritize large, significant values. This ensures that the "peaks" of the attention map remain sharp even at 4-bit precision, maintaining the functional integrity of the attention mechanism.
Key Results
APQ-ViT significantly outperforms previous state-of-the-art methods like PTQ4ViT and FQ-ViT, particularly in low-bit settings:
- ImageNet Classification: On average, accuracy improved by 5.17% in W4A4 settings. For a ViT-B model, APQ-ViT achieved 41.41% accuracy, whereas previous methods struggled to reach 31%.
- COCO Object Detection: The gains were even more dramatic, with a 24.43% improvement in mAP for a Swin-S based detector compared to PTQ4ViT.
- Near Lossless 8-bit: At 8-bit precision (W8A8), the model performs almost identically to the full-precision version, with less than a 0.1% accuracy drop.
Conclusion
APQ-ViT addresses the fundamental challenges of quantizing Vision Transformers by focusing on blockwise error perception and preserving the essential power-law nature of attention. While future work could extend this to fully integer-only pipelines and real-world hardware latency benchmarks, APQ-ViT sets a new standard for accurate post-training quantization in vision tasks.
Summary updated