StableQ: Enhancing Data-Scarce Quantization with Text-to-Image Data

Yuhang Li, Youngeun Kim, Donghyun Lee, Priyadarshini Panda

Abstract

In the realm of deep neural network deployment, low-bit quantization presents a promising avenue for enhancing computational efficiency. However, it often hinges on the availability of training data to mitigate quantization errors, a significant challenge when data availability is scarce or restricted due to privacy or copyright concerns. Addressing this, we introduce GenQ, a novel approach employing an advanced Generative AI model to generate photorealistic, high-resolution synthetic data, overcoming the limitations of traditional methods that struggle to accurately mimic complex objects in extensive datasets like ImageNet. Our methodology is underscored by two robust filtering mechanisms designed to ensure the synthetic data closely aligns with the intrinsic characteristics of the actual training data. In case of limited data availability, the actual data is used to guide the synthetic data generation process, enhancing fidelity through the inversion of learnable token embeddings. Through rigorous experimentation, GenQ establishes new benchmarks in data-free and data-scarce quantization, significantly outperforming existing methods in accuracy and efficiency, thereby setting a new standard for quantization in low data regimes.

Introduction

Deploying large-scale AI models on resource-constrained devices necessitates quantization—the process of converting high-precision weights and activations into low-bit formats. While efficient, quantization typically requires access to the original training data for recalibration to maintain model accuracy. In many real-world scenarios, however, this data is inaccessible due to privacy, copyright, or proprietary restrictions.

Existing "data-free" quantization methods often rely on inverting pre-trained models to generate synthetic images. These methods frequently produce abstract, noisy patterns that fail to capture the semantic complexity of real-world datasets like ImageNet, leading to significant performance degradation. Furthermore, these inversion processes are often computationally intensive. To address these challenges, we propose GenQ, a framework that leverages the generative power of Stable Diffusion to create high-fidelity synthetic calibration data.

Methodology

The GenQ pipeline utilizes a pre-trained Stable Diffusion model to generate synthetic data, which is then refined through intelligent filtering to ensure it is suitable for quantization.

The GenQ pipeline for data-free and data-scarce quantization.

The framework consists of several key components:

  1. Data Synthesis:
    • Data-Free (DFQ): GenQ uses class labels and predefined templates (e.g., "A photo of a {class}") to prompt Stable Diffusion to generate photorealistic images.
  2. Data-Scarce (DSQ): When a limited amount of real data is available (e.g., 1-shot), GenQ employs textual inversion. This process learns a specific token embedding that captures the unique characteristics of the real images, which is then used to guide the generation of additional synthetic data.
  3. Filtering Mechanisms: To bridge the distribution gap between synthetic and real data, GenQ implements two filters:
  4. Energy Filtering: Calculates an energy score based on the model's output logits. Lower energy scores indicate that the synthetic image aligns better with the model's learned distribution.
  5. Structural Filtering: For CNNs, GenQ uses BatchNorm (BN) distance to measure how well an image matches the model's internal statistics. For Vision Transformers (ViTs), patch similarity is used to ensure data diversity.
  6. Quantization: The filtered synthetic data is used for both Post-Training Quantization (PTQ) and Quantization-Aware Training (QAT), employing a specialized initialization strategy to stabilize fine-tuning.

Experimental Setup

The GenQ framework was evaluated primarily on the ImageNet-1k dataset. The study covered a broad range of architectures, including:

  • CNNs: ResNet-18, ResNet-50, MobileNetV2, and MnasNet.
  • Vision Transformers: ViT-B, DeiT-B, and Swin-B.

Results and Discussion

GenQ demonstrates superior performance across various quantization regimes, effectively closing the gap between data-free and real-data-driven quantization.

Performance comparison of GenQ against existing methods in terms of accuracy and generation speed.

Key Findings

  • State-of-the-Art Accuracy: In 4-bit PTQ on ResNet-50, GenQ achieved 75.47% accuracy, matching the performance of models quantized with real ImageNet data (75.45%). In the more challenging QAT setting, GenQ reached 76.10% accuracy, a 5.4% improvement over previous state-of-the-art methods like TexQ.
  • Efficiency Gains: GenQ is significantly faster than traditional image inversion techniques, achieving up to a 15x speedup in generating 1,000 calibration images.
  • Robustness on Lightweight Models: GenQ showed remarkable success on quantization-sensitive architectures like MobileNetV2, where it improved accuracy by 5% in low-bit (2-bit/4-bit) scenarios compared to existing baselines.
  • Data-Scarce Performance: In 1-shot scenarios, GenQ's textual inversion approach allowed ResNet-50 to reach 68.88% accuracy, comparable to models trained on significantly larger real datasets.

Conclusion and Future Work

GenQ establishes a new paradigm for quantization in low-data regimes by utilizing generative AI to produce semantically rich synthetic data. By treating data selection as an out-of-distribution detection problem, the framework ensures that synthetic images are highly effective for model calibration.

While GenQ offers significant advantages, its performance is inherently tied to the quality of the underlying generative model. Future research will explore the application of this methodology to other domains, such as Large Language Models (LLMs) and multi-modal systems, and investigate ways to further reduce the computational cost of large-scale synthetic data generation.

Summary updated

BibTeX
@inproceedings{li2024stableq,
  author = {Yuhang Li and Youngeun Kim and Donghyun Lee and Priyadarshini Panda},
  title = {{StableQ: Enhancing Data-Scarce Quantization with Text-to-Image Data}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-72624-8\_13},
}
Figure