FQ-ViT: Post-Training Quantization for Fully Quantized Vision Transformer

Yang Lin, Tianyu Zhang, Peiqin Sun, Zheng Li, Shuchang Zhou
11/27/2021
cs.CV
transformer-attentionquantization-pruning

Official code: megvii-research/FQ-ViT (363 stars, Python, Apache-2.0, PyTorch, last commit 2023-04-11).

Abstract

Network quantization significantly reduces model inference complexity and has been widely used in real-world deployments. However, most existing quantization methods have been developed mainly on Convolutional Neural Networks (CNNs), and suffer severe degradation when applied to fully quantized vision transformers.

Show full abstract

In this work, we demonstrate that many of these difficulties arise because of serious inter-channel variation in LayerNorm inputs, and present, Power-of-Two Factor (PTF), a systematic method to reduce the performance degradation and inference complexity of fully quantized vision transformers. In addition, observing an extreme non-uniform distribution in attention maps, we propose Log-Int-Softmax (LIS) to sustain that and simplify inference by using 4-bit quantization and the BitShift operator. Comprehensive experiments on various transformer-based architectures and benchmarks show that our Fully Quantized Vision Transformer (FQ-ViT) outperforms previous works while even using lower bit-width on attention maps. For instance, we reach 84.89% top-1 accuracy with ViT-L on ImageNet and 50.8 mAP with Cascade Mask R-CNN (Swin-S) on COCO. To our knowledge, we are the first to achieve lossless accuracy degradation (~1%) on fully quantized vision transformers. The code is available at https://github.com/megvii-research/FQ-ViT.

View on arXivView PDF

Code Implementations(1)

PyTorchApache-2.0

[IJCAI 2022] FQ-ViT: Post-Training Quantization for Fully Quantized Vision Transformer

36357PythonNov 24, 20213 years agoApache-2.0
imagenetpost-training-quantizationpytorchquantizationvision-transformer

Similar Papers

Cite this paper

@article{lin2021fqvit,
  title  = {FQ-ViT: Post-Training Quantization for Fully Quantized Vision Transformer},
  author = {Yang Lin and Tianyu Zhang and Peiqin Sun and Zheng Li and Shuchang Zhou},
  year   = {2021},
  eprint = {2111.13824},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2111.13824}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2111.13824.svg)](https://codeofpaper.com/paper/2111.13824)

Discussion