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

Patch Similarity Aware Data-Free Quantization for Vision Transformers

Zhikai Li, Liping Ma, Mengjuan Chen, Junrui Xiao, Qingyi Gu

Abstract

Vision transformers have recently gained great success on various computer vision tasks; nevertheless, their high model complexity makes it challenging to deploy on resource-constrained devices. Quantization is an effective approach to reduce model complexity, and data-free quantization, which can address data privacy and security concerns during model deployment, has received widespread interest. Unfortunately, all existing methods, such as BN regularization, were designed for convolutional neural networks and cannot be applied to vision transformers with significantly different model architectures. In this paper, we propose PSAQ-ViT, a Patch Similarity Aware data-free Quantization framework for Vision Transformers, to enable the generation of “realistic" samples based on the vision transformer’s unique properties for calibrating the quantization parameters. Specifically, we analyze the self-attention module’s properties and reveal a general difference (patch similarity) in its processing of Gaussian noise and real images. The above insights guide us to design a relative value metric to optimize the Gaussian noise to approximate the real images, which are then utilized to calibrate the quantization parameters. Extensive experiments and ablation studies are conducted on various benchmarks to validate the effectiveness of PSAQ-ViT, which can even outperform the real-data-driven methods.

Introduction

Vision Transformers (ViTs) have revolutionized computer vision, but their massive memory and computational requirements make them difficult to deploy on edge devices like smartphones or IoT sensors. Quantization—converting 32-bit floating-point weights into lower-precision formats like 8-bit or 4-bit integers—is a standard solution to shrink these models.

However, most quantization methods require a "calibration" dataset of real-world images to minimize accuracy loss. In many industries (e.g., healthcare or defense), the original training data is inaccessible due to privacy and security concerns. While "data-free" quantization exists for Convolutional Neural Networks (CNNs) by exploiting Batch Normalization (BN) statistics, ViTs use Layer Normalization (LN), which does not store the statistical "fingerprints" of the training data. PSAQ-ViT addresses this gap by leveraging the unique way self-attention modules distinguish foreground from background to synthesize "realistic" calibration data from random noise.

Methodology

The core idea of PSAQ-ViT (Patch Similarity Aware data-free Quantization) is to treat the pre-trained ViT as a teacher that "knows" what a real image should look like based on its internal attention patterns.

Patch Similarity Analysis

The researchers observed that when a ViT processes a real image, the self-attention module produces diverse responses—it clearly differentiates between foreground patches (the object) and background patches. In contrast, when processing Gaussian noise, the responses are homogeneous. Real images result in a bimodal similarity curve (high similarity within the object, low similarity between object and background), whereas noise results in a unimodal curve.

Overview of the PSAQ-ViT framework, illustrating how patch similarity distributions are used to optimize Gaussian noise into realistic calibration data.

Differential Entropy Loss ($L_{PSE}$)

To turn noise into "realistic" data, the framework uses Kernel Density Estimation (KDE) to model the distribution of patch similarities. By maximizing the differential entropy ($L_{PSE}$) of this distribution, the synthetic image is forced to develop the complex, bimodal similarity patterns found in real images.

The Pipeline

The process consists of two main stages:

  1. Sample Generation: Starting with Gaussian noise, the image is optimized using the Patch Similarity Entropy loss, a One-hot loss (to ensure confident classification), and a Total Variance loss (for spatial smoothness).
  2. Calibration: These synthesized "realistic" images are then used to calibrate the clipping ranges for the model's weights and activations.

Experimental Results

The framework was evaluated on the ImageNet (ILSVRC-2012) dataset across several popular architectures, including ViT, DeiT, and Swin Transformer.

Key Performance Metrics

  • Outperforming Baselines: On ViT-S, PSAQ-ViT achieved 20.84% Top-1 accuracy at 4-bit quantization, outperforming the "Standard" method using real data (19.91%).
  • Near-Lossless 8-bit: For DeiT-T, the method achieved 8-bit quantization with only a 0.65% drop from the full-precision model (71.56% vs 72.21%).
  • Robustness: On the Swin-T model, where raw Gaussian noise calibration failed completely (0.52% accuracy), PSAQ-ViT recovered the model to 71.79% accuracy, nearly matching the real-data baseline of 70.16%.
  • Efficiency: The entire process (generation + calibration) takes less than 4 minutes on a single NVIDIA RTX 3090 GPU.

Conclusion and Future Work

PSAQ-ViT demonstrates that the Self-Attention module itself can serve as a powerful data prior. Surprisingly, in several tests, PSAQ-ViT outperformed calibration using actual real images, suggesting that synthesized images may capture the most critical features for the model more effectively than natural datasets containing outliers.

While 4-bit results are impressive for a data-free approach, a significant accuracy gap remains compared to 32-bit originals. Future work could explore combining PSAQ-ViT with more sophisticated Post-Training Quantization (PTQ) techniques like rounding optimization (AdaRound) or extending the patch similarity priors to tasks like object detection and segmentation.

Summary updated

BibTeX
@inproceedings{li2022patch,
  author = {Zhikai Li and Liping Ma and Mengjuan Chen and Junrui Xiao and Qingyi Gu},
  title = {{Patch Similarity Aware Data-Free Quantization for Vision Transformers}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  url = {https://openreview.net/forum?id=gu9huxXl0aZ},
}
Figure