NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

PTQ4ViT: Post-training Quantization for Vision Transformers with Twin Uniform Quantization

Zhihang Yuan, Chenhao Xue, Yiqi Chen, Qiang Wu, Guangyu Sun

Introduction

Quantization is a critical technique for deploying large-scale deep learning models on resource-constrained edge devices. By converting high-precision floating-point weights and activations into low-bit integers (e.g., 8-bit), researchers can significantly reduce memory footprint and increase inference speed. While post-training quantization (PTQ) has been highly successful for Convolutional Neural Networks (CNNs), Vision Transformers (ViTs) present unique challenges. Standard PTQ methods often lead to accuracy drops exceeding 1% for ViTs at 8-bit precision, and performance collapses at lower bit-widths.

Challenges in ViT Quantization

The researchers identified two primary obstacles to effective ViT quantization:

  1. Extreme Activation Distributions: Activations following Softmax and GELU functions are highly unbalanced. Softmax outputs are mostly near zero with a few critical values near one, while GELU has a small negative range and a large positive tail. Standard uniform quantization either loses precision for small values or clips important outliers.
  2. Metric Misalignment: Traditional metrics used to calibrate quantization parameters, such as Mean Squared Error (MSE) or Cosine Distance, do not correlate well with the final task accuracy in Transformers. Minimizing local error does not necessarily minimize global loss.

Proposed Framework: PTQ4ViT

To address these issues, the authors propose PTQ4ViT, a framework incorporating two main innovations: Twin Uniform Quantization and a Hessian-guided metric.

Overview of the PTQ4ViT framework, illustrating Twin Uniform Quantization for GELU/Softmax and the Hessian-guided calibration process.

Twin Uniform Quantization

Instead of a single uniform range, Twin Uniform Quantization employs two overlapping ranges ($R1$ and $R2$) defined by two scaling factors. For Softmax, one range captures the dense values near zero, while the other preserves high-attention peaks near 1.0. For GELU, the two ranges separately handle the asymmetric positive and negative distributions. To maintain hardware efficiency, the scaling factors are constrained to be related by a power of two, allowing the ranges to be aligned using fast bit-shift operations rather than expensive multiplications.

Hessian-Guided Metric

The framework replaces standard error metrics with a Hessian-guided metric. By utilizing second-order derivatives, this metric estimates the impact of local quantization errors on the final output loss. This provides a more accurate objective for finding optimal scaling factors during the calibration phase.

Comparison of various metrics (Hessian, MSE, Cosine, etc.) against the actual Cross-Entropy (CE) loss. The Hessian-guided metric more closely tracks the optimal scaling factor for the final task.

Experimental Results

PTQ4ViT was evaluated on the ImageNet (ILSVRC2012) dataset using standard ViT, DeiT, and Swin architectures. As a PTQ method, it requires only a small calibration set of 32 unlabeled images.

  • 8-bit Precision (W8A8): The method achieved near-lossless performance, with accuracy drops typically under 0.5%. For ViT-S, the drop was only 0.38%, a significant improvement over the 0.91% drop seen with baseline methods.
  • 6-bit Precision (W6A6): PTQ4ViT demonstrates superior robustness at lower bit-widths. While baseline methods often saw accuracy drops of ~10%, PTQ4ViT maintained an average drop of only 2.1%.
  • Efficiency: The calibration process is highly efficient, completing in minutes on a single GPU without requiring full model retraining or labeled data.

Conclusion

PTQ4ViT effectively bridges the performance gap in post-training quantization for Vision Transformers. By tailoring the quantization scheme to the specific distribution characteristics of Transformer activations and employing a more theoretically grounded Hessian-guided metric, the framework enables high-performance deployment of ViTs on edge hardware. Future work may explore mixed-precision strategies to further push the boundaries of 4-bit quantization.

Summary updated

BibTeX
@inproceedings{yuan2022ptq,
  author = {Zhihang Yuan and Chenhao Xue and Yiqi Chen and Qiang Wu and Guangyu Sun},
  title = {{PTQ4ViT: Post-training Quantization for Vision Transformers with Twin Uniform Quantization}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-19775-8\_12},
}
Figure