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

Q-ViT: Fully Differentiable Quantization for Vision Transformer

Zhexin Li, Tong Yang, Peisong Wang, Jian ChengarXiv 2022

Introduction

Vision Transformers (ViTs) have set new benchmarks in computer vision, yet their deployment on resource-constrained edge devices remains challenging due to high memory and computational costs. While quantization is a common strategy to reduce model size, ViTs are particularly sensitive to low-bit precision. Standard Quantization-Aware Training (QAT) often fails when bit-widths drop below 6 bits. Q-ViT addresses this by introducing a fully differentiable quantization framework that enables stable and accurate 3-bit precision.

Methodology: Fully Differentiable Quantization

The core of Q-ViT lies in treating both quantization scales and bit-widths as learnable parameters. This allows the network to automatically discover the optimal precision for each layer and component during the training process.

The Q-ViT architecture features learnable bit-widths and a switchable scale mechanism to stabilize training across different precisions.

Key Components

  • Learnable Bit-widths: Q-ViT employs a Straight-Through Estimator (STE) to make bit-widths ($b$) differentiable, allowing the model to optimize precision via standard backpropagation.
  • Head-wise Bit-width Allocation: Recognizing that different attention heads capture varying features, Q-ViT allows each head in the Multi-head Self-Attention (MSA) layer to learn its own bit-width independently.
  • Switchable Scale: To combat training instability caused by shifting quantization scales as bit-widths change, the authors introduce a "switchable scale" vector. This ensures that each candidate bit-width has a corresponding learned scale, facilitating smooth transitions during optimization.
  • Complexity-Aware Loss: A BitOPs (Bit Operations) constraint is integrated into the loss function to penalize high average bit-widths, ensuring the final model meets target size and efficiency constraints.

Key Insights: Identifying Bottlenecks

The researchers conducted extensive sensitivity analyses to understand why ViTs struggle with low-bit quantization compared to traditional CNNs.

Sensitivity analysis showing (a) the impact of quantizing GELU vs. Linear layers and (b) accuracy degradation across different attention heads.
  • The GELU Bottleneck: The Gaussian Error Linear Unit (GELU) activation function was identified as a primary source of accuracy loss under quantization. Q-ViT compensates by automatically assigning higher precision to these sensitive layers.
  • Attention Head Diversity: Analysis revealed that early-layer attention heads are highly heterogeneous in their precision requirements, whereas deeper layers tend to be more uniform. This justifies the use of granular, head-wise bit-width allocation to preserve critical features.

Experimental Results

Q-ViT was evaluated on the ImageNet-1K dataset using several architectures, including DeiT and Swin-Transformer. It consistently outperformed state-of-the-art methods like LSQ+:

  • DeiT-Tiny (3-bit): Achieved 69.62% Top-1 accuracy, a 1.53% improvement over the LSQ+ baseline.
  • Swin-T (3-bit): Reached 79.45% accuracy, surpassing LSQ+ while utilizing fewer theoretical BitOPs.
  • 4-bit Performance: At 4-bit precision, Q-ViT models nearly match the performance of their full-precision (float) counterparts, demonstrating the effectiveness of the differentiable approach for real-world deployment.

Conclusion

Q-ViT pushes the boundaries of Vision Transformer compression, making 3-bit precision a reality without sacrificing significant accuracy. By making quantization fully differentiable and hardware-aware, it paves the way for efficient ViT deployment on mobile and embedded platforms. Future work will focus on reducing the computational overhead of the training phase and optimizing for specific hardware backends like mobile DSPs.

Summary updated

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