Abstract
Vision Transformers (ViTs) have established a new state-of-the-art in computer vision but present significant deployment challenges due to their high computational and memory requirements. While quantization offers a solution for model compression, standard data-free quantization (DFQ) methods rely on Batch Normalization (BN) statistics—a feature absent in ViT architectures, which utilize Layer Normalization (LN). This paper presents PSAQ-ViT, the first data-free quantization framework specifically designed for Vision Transformers. By exploiting the inherent ability of self-attention modules to distinguish foreground from background, PSAQ-ViT synthesizes realistic calibration images from Gaussian noise using a novel Patch Similarity Entropy metric. Our results on ImageNet demonstrate that PSAQ-ViT achieves near-lossless compression and can even surpass the performance of models calibrated with real data.
Introduction
The deployment of Vision Transformers (ViTs) on edge devices, such as mobile phones and IoT sensors, is often hindered by their intensive resource demands. Quantization—the process of mapping 32-bit floating-point weights and activations to lower-precision formats like 8-bit or 4-bit integers—is a critical technique for reducing these demands. However, quantization typically requires a small set of real "calibration" data to maintain accuracy. In privacy-sensitive sectors like healthcare or defense, accessing original training data is often impossible.
Existing Data-Free Quantization (DFQ) methods bridge this gap by generating synthetic data based on statistics stored in Batch Normalization layers. However, ViTs use Layer Normalization, which does not store the running means and variances of the training distribution. This architectural difference renders traditional DFQ methods ineffective for Transformers, creating a significant barrier to their efficient deployment.
Methodology: PSAQ-ViT
PSAQ-ViT (Patch Similarity Aware data-free Quantization) shifts the focus from stored statistics to the internal behavior of the model's self-attention mechanism. The framework is built on the observation that when a ViT processes a coherent image, the self-attention layers produce diverse responses, effectively separating foreground objects from the background. In contrast, processing random noise results in homogeneous, "flat" attention maps.
1. Patch Similarity and Relative Metrics
Since ViTs lack absolute statistical markers, PSAQ-ViT utilizes a relative metric: the Cosine Similarity between patches. This allows the framework to analyze the structural relationships within an image without needing the original data distribution.
2. Differential Entropy via Kernel Density Estimation (KDE)
To optimize synthetic images, the authors calculate the diversity of patch similarities using Kernel Density Estimation (KDE). This approach makes the "diversity" of the attention maps differentiable, allowing the framework to use back-propagation to update the input noise into structured synthetic data.
3. The Generation Pipeline
The framework transforms Gaussian noise into calibration data by optimizing three primary loss functions:
- Patch Similarity Entropy ($L_{PSE}$): Forces the synthetic noise to adopt the complex, bimodal structural diversity (foreground vs. background) found in real images.
- One-Hot Loss ($L_{OH}$): Encourages the generated image to be strongly associated with a specific target category.
- Total Variation ($L_{TV}$): Acts as a regularizer to ensure spatial smoothness and reduce high-frequency artifacts.
4. Calibration
Once the synthetic samples are generated, they are used to determine the optimal clipping ranges for the quantized model’s activations using a standard MinMax calibration approach. This ensures that the quantization process is driven by data that the model perceives as "realistic."
Experimental Results
The researchers evaluated PSAQ-ViT on the ImageNet (ILSVRC-2012) dataset across several architectures, including ViT, DeiT (Data-efficient Image Transformer), and Swin Transformer.
Performance Benchmarks
PSAQ-ViT demonstrated high effectiveness across various bit-widths (W8/A8 and W4/A8):
- ViT-S: PSAQ-ViT achieved a Top-1 accuracy of 31.45% (W8/A8), notably outperforming the standard method using real calibration data (30.28%).
- DeiT-T: The method achieved 4-fold compression with a negligible accuracy loss of only 0.65%.
- Swin-T: While calibration with pure Gaussian noise failed (0.52% accuracy), PSAQ-ViT recovered performance to 71.79%, exceeding the real-data baseline of 70.16%.
Efficiency and Insights
A key finding of the study is that synthetic data can occasionally outperform real data for calibration. This suggests that PSAQ-ViT generates "distilled" samples that emphasize the features most critical for setting quantization parameters. Furthermore, the process is highly efficient; the entire generation and calibration pipeline takes less than four minutes on a single NVIDIA RTX 3090 GPU.
Discussion and Limitations
PSAQ-ViT proves that the self-attention module itself contains a powerful prior regarding the structure of natural images. By forcing synthetic noise to match the bimodal similarity distribution of real images, the framework bypasses the need for Batch Normalization statistics.
However, some limitations remain. The current work focuses primarily on image classification; the effectiveness of patch similarity entropy for dense prediction tasks like object detection or segmentation requires further exploration. Additionally, the method's success depends on the quality of the pre-trained FP32 model; if the base model has not learned to distinguish foreground from background, the generated samples may lack the necessary quality for effective calibration.
Conclusion
PSAQ-ViT provides a robust and efficient solution for the data-free quantization of Vision Transformers. By leveraging the internal logic of self-attention, it enables high-performance model compression without compromising data privacy, paving the way for the deployment of advanced Transformer architectures on resource-constrained edge devices.
Summary updated