Abstract
Vision Transformers (ViTs) have established state-of-the-art performance across various computer vision tasks but remain computationally expensive for edge deployment. Post-training quantization (PTQ) is a critical technique for model compression; however, ViTs suffer significant accuracy degradation at ultra-low bit-widths (e.g., 4-bit). This paper introduces ADFQ-ViT, a framework designed to handle the "quantization-unfriendly" activation distributions inherent in ViTs. By employing a Per-Patch Outlier-aware Quantizer (POQ), a Shift-Log2 Quantizer (SLQ), and Attention-score enhanced Module-wise Optimization (AMO), ADFQ-ViT achieves substantial accuracy improvements, including a 10.23% boost on ViT-B at 4-bit precision.
Introduction
While Vision Transformers (ViTs) excel in accuracy, their massive parameter counts and high computational costs pose challenges for deployment on resource-constrained devices. Quantization—reducing the precision of weights and activations from 32-bit floating-point to low-bit integers—is a standard solution. Despite its success in Convolutional Neural Networks (CNNs), applying 4-bit quantization to ViTs typically results in a "performance cliff."
The authors identify two primary bottlenecks in ViT quantization:
- Irregular Outliers: Post-LayerNorm activations contain sporadic, extreme values that skew the quantization scale, reducing the resolution for the majority of the data.
- Lopsided GELU Outputs: The GELU activation function produces distributions that are heavily concentrated in negative regions but widely spread in positive regions, which standard uniform quantizers fail to represent efficiently.
Methodology
ADFQ-ViT addresses these challenges through three specialized components designed to accommodate the unique statistical properties of Transformer activations.
Per-Patch Outlier-aware Quantizer (POQ)
Unlike previous methods that assume outliers follow a per-channel pattern, the authors demonstrate that outliers in ViTs are irregular across layers and patches. POQ identifies a small fraction of extreme outliers (typically <0.1%) at the patch level and maintains them in full precision. The remaining "well-behaved" data is quantized to 4-bit. This hybrid approach prevents a few extreme values from dominating the quantization range, preserving precision for the bulk of the activation values.
Shift-Log2 Quantizer (SLQ)
To handle the asymmetric and long-tailed distribution of GELU outputs, SLQ first shifts all values into the positive domain. It then applies a logarithmic (log2) quantizer. Logarithmic quantization is inherently better suited for long-tailed distributions, as it provides higher resolution for smaller values where the data density is highest.
Attention-score enhanced Module-wise Optimization (AMO)
Standard quantization optimization focuses on minimizing the reconstruction error of a layer's output. However, in Transformers, the attention scores (the relationships between tokens) are more critical than the raw feature values. AMO introduces a specialized loss function based on KL divergence to ensure that the attention maps remain consistent between the full-precision and quantized models during the calibration process.
Experimental Results
ADFQ-ViT was evaluated across multiple benchmarks, including ImageNet-1K for classification, COCO for object detection, and the Segment Anything Model (SAM) for zero-shot segmentation.
- 4-Bit Performance: On the ViT-B model, ADFQ-ViT improved Top-1 accuracy on ImageNet by 10.23% compared to the previous state-of-the-art method, RepQ-ViT.
- 6-Bit Near-Lossless Quantization: At 6-bit precision, the models achieved performance nearly identical to their 32-bit counterparts, with an average accuracy drop of only 0.67%.
- Downstream Tasks: For SAM, the framework improved mask accuracy by 4.0 points at 4-bit precision, demonstrating its versatility across different vision architectures.
- Calibration Efficiency: Despite the inclusion of optimization steps, ADFQ-ViT remains faster to calibrate than other optimization-heavy PTQ methods like BRECQ or QDrop.
Discussion and Conclusion
ADFQ-ViT demonstrates that the key to low-bit ViT quantization lies in respecting the irregular nature of its activations. By prioritizing the preservation of attention scores and handling outliers at a granular patch level, the framework enables 4-bit deployment with manageable accuracy loss.
Future work remains to be done in developing specialized hardware kernels (such as Sparse Matrix Multiplication) to fully realize the theoretical speedups of the outlier-aware strategy on physical chips. Additionally, exploring the application of these techniques to large-scale multimodal models presents a promising avenue for further research.
Summary updated