Q-ViT: Fully Differentiable Quantization for Vision Transformer

Zhexin Li, Tong Yang, Peisong Wang, Jian Cheng
1/19/2022
cs.CV
transformer-attentionquantization-pruning

Official code: zhexinli/Q-ViT-DeiT (26 stars, Python, Apache-2.0, last commit 2025-04-21).

Abstract

In this paper, we propose a fully differentiable quantization method for vision transformer (ViT) named as Q-ViT, in which both of the quantization scales and bit-widths are learnable parameters. Specifically, based on our observation that heads in ViT display different quantization robustness, we leverage head-wise bit-width to squeeze the size of Q-ViT while preserving performance.

Show full abstract

In addition, we propose a novel technique named switchable scale to resolve the convergence problem in the joint training of quantization scales and bit-widths. In this way, Q-ViT pushes the limits of ViT quantization to 3-bit without heavy performance drop. Moreover, we analyze the quantization robustness of every architecture component of ViT and show that the Multi-head Self-Attention (MSA) and the Gaussian Error Linear Units (GELU) are the key aspects for ViT quantization. This study provides some insights for further research about ViT quantization. Extensive experiments on different ViT models, such as DeiT and Swin Transformer show the effectiveness of our quantization method. In particular, our method outperforms the state-of-the-art uniform quantization method by 1.5% on DeiT-Tiny.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

DeiT implementation for Q-ViT

267Python, ShellJul 17, 20221 years agoApache-2.0

Similar Papers

Cite this paper

@article{li2022qvit,
  title  = {Q-ViT: Fully Differentiable Quantization for Vision Transformer},
  author = {Zhexin Li and Tong Yang and Peisong Wang and Jian Cheng},
  year   = {2022},
  eprint = {2201.07703},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2201.07703}
}

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/2201.07703.svg)](https://codeofpaper.com/paper/2201.07703)

Discussion