Introduction
Vision Transformers (ViTs) have achieved state-of-the-art performance across various computer vision tasks. However, their deployment on resource-constrained edge devices is hindered by massive parameter counts and high computational demands. While quantization—the process of converting 32-bit floating-point (FP32) values to lower-precision integers (e.g., INT8)—is a standard optimization technique for Convolutional Neural Networks (CNNs), it has historically proven difficult for ViTs.
Specifically, "fully" quantizing a ViT, which includes the LayerNorm and Softmax modules, typically results in a catastrophic drop in accuracy. To avoid this, previous methods often maintained these modules in floating-point format, creating "islands" of FP math that necessitate expensive floating-point units (FPUs) and create hardware bottlenecks. FQ-ViT introduces the first post-training quantization (PTQ) method to achieve near-lossless accuracy on fully quantized ViTs without any retraining or fine-tuning, enabling efficient integer-only inference.
Methodology
The authors identify two primary bottlenecks in ViT quantization and propose targeted solutions for each:
Power-of-Two Factor (PTF) for LayerNorm
Analysis of ViT activations reveals extreme inter-channel variation in LayerNorm inputs, where specific channels exhibit ranges up to 40x larger than the median. Standard layer-wise quantization cannot accommodate these "spikes" without losing significant precision. FQ-ViT introduces Power-of-Two Factor (PTF) quantization, which 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 simple BitShift operators, preserving the efficiency of layer-wise quantization while achieving the precision of channel-wise methods.
Log-Int-Softmax (LIS) for Softmax
Attention maps in ViTs are highly non-uniform; the vast majority of values are clustered near zero (e.g., 98.8% of values in ViT-L are smaller than 1/16), with only a few outliers near one. Uniform quantization is inefficient here, as it wastes most quantization bins on the empty space near the upper bound. FQ-ViT proposes Log-Int-Softmax (LIS), which utilizes Log2 quantization. This approach provides significantly higher resolution for the small values that dominate the attention map, allowing for effective 4-bit compression while replacing complex multiplications with BitShifts.
Experimental Results
FQ-ViT was evaluated on ImageNet for classification and COCO for object detection/segmentation across multiple architectures, including ViT, DeiT, and Swin Transformer.
ImageNet Classification
FQ-ViT achieves near-lossless performance compared to full-precision models. For instance, on DeiT-B, FQ-ViT reached 81.20% top-1 accuracy, just 0.65% shy of the FP32 baseline (81.85%). Most notably, for large-scale models like ViT-L where vanilla PTQ collapses to 3.37% accuracy, FQ-ViT recovers performance to 85.03%.
Object Detection and 4-bit Attention
On the COCO benchmark, FQ-ViT achieved 50.8 mAP using a fully quantized Cascade Mask R-CNN with a Swin-S backbone. Furthermore, the LIS method allows attention maps to be compressed to 4-bit with minimal impact on accuracy (e.g., 84.89% on ViT-L), effectively halving the memory footprint of the attention mechanism compared to 8-bit implementations.
Conclusion
FQ-ViT provides a robust framework for deploying Vision Transformers on integer-only hardware without the need for expensive retraining. By addressing the specific distributional challenges of LayerNorm and Softmax through PTF and LIS, the method bridges the gap between high-performance Transformer architectures and efficient edge deployment. Future research may explore extending these techniques to even lower bit-widths (e.g., 2-bit) or developing entirely data-free quantization methods.
Summary updated