Introduction
Vision Transformers (ViTs) have achieved state-of-the-art performance across various computer vision tasks. However, their deployment on edge devices is hindered by massive parameter counts and high computational costs. While quantization—converting 32-bit floating-point numbers to lower-bit integers (e.g., INT8)—is a standard optimization technique, ViTs present unique challenges compared to traditional Convolutional Neural Networks (CNNs).
Specifically, standard quantization methods lead to significant accuracy degradation in ViTs due to the non-uniform data distributions in LayerNorm and Softmax layers. Consequently, most existing "quantized" ViTs retain these layers in floating-point precision. This hybrid approach forces hardware to switch between integer and floating-point units, creating a substantial bottleneck in inference speed and power efficiency. FQ-ViT addresses this by enabling a truly "fully quantized" pipeline.
Methodology
The FQ-ViT framework introduces two primary innovations designed to handle the problematic distributions in ViT modules:
Power-of-Two Factor (PTF) for LayerNorm
The authors observed extreme inter-channel variation in LayerNorm inputs, where some channels exhibit ranges significantly larger than others (up to 40x). Standard layer-wise quantization fails to capture this variance, leading to high errors. PTF assigns a unique power-of-two scaling factor to each channel. By restricting these factors to powers of two, the hardware can implement the scaling using efficient BitShift operations instead of expensive multiplications, preserving accuracy without sacrificing throughput.
Log-Int-Softmax (LIS) for Attention Maps
Attention maps are characterized by highly non-uniform distributions; most values are near zero, while a few critical values are near one. Uniform quantization tends to "crush" these small values, destroying the model's ability to rank feature importance. LIS employs Log2 quantization, which provides higher resolution for small values. This approach not only preserves the relative order of attention values but also allows subsequent matrix multiplications to be replaced by BitShifts, facilitating an integer-only attention mechanism.
Experimental Setup
The effectiveness of FQ-ViT was evaluated on two major benchmarks:
- ImageNet: Used for image classification across several architectures, including ViT (Base/Large), DeiT (Tiny/Small/Base), and Swin Transformer (Tiny/Small/Base).
- COCO: Used for object detection and instance segmentation tasks, testing the Swin Transformer backbone within Mask R-CNN and Cascade Mask R-CNN frameworks.
Results and Discussion
FQ-ViT demonstrates that it is possible to achieve near-lossless performance with fully quantized Vision Transformers.
Performance and Efficiency
On ImageNet, FQ-ViT achieved 84.89% top-1 accuracy with a fully quantized ViT-L, a negligible drop of approximately 1% from the full-precision baseline. In contrast, a "vanilla" quantization approach caused the same ViT-L model to collapse to 3.37% accuracy. Furthermore, by utilizing 4-bit quantization for attention maps via LIS, the memory footprint was reduced by 50% compared to 8-bit methods while maintaining comparable performance.
Key Insights
- Inter-channel Variation: The extreme variation in LayerNorm channels is a primary reason why ViTs are more difficult to quantize than CNNs like ResNet.
- Ranking over Precision: For Softmax, maintaining the relative order (ranking) of attention values is more critical than linear precision. Logarithmic quantization excels at this, even at 4-bit widths.
- Hardware-Algorithm Co-design: The use of power-of-two scaling and Log2 quantization is a deliberate choice to leverage the high-speed BitShift operator available on FPGAs, ASICs, and modern CPUs.
Conclusion
FQ-ViT provides a robust framework for deploying Vision Transformers on integer-only hardware. While the method requires a small calibration dataset (~1000 images) and has yet to explore ultra-low bit-widths (e.g., 2-bit), it sets a new standard for post-training quantization in Transformers. This work paves the way for more efficient real-world edge adoption of state-of-the-art vision models.
Summary updated