Temporal Dynamic Quantization for Diffusion Models

Junhyuk So, Jungwon Lee, Daehyun Ahn, Hyungjun Kim, Eunhyeok Park

Introduction

Diffusion models have revolutionized image generation, achieving state-of-the-art results by iteratively refining noise into high-fidelity images over hundreds of steps. However, their massive size and the iterative nature of their generation process make them computationally expensive and difficult to deploy on mobile or edge devices.

While quantization—mapping high-precision floating-point numbers to low-precision integers (like 8-bit or 4-bit)—is a standard solution for model compression, it struggles when applied to diffusion models. This paper introduces Temporal Dynamic Quantization (TDQ), a novel method that dynamically adjusts quantization parameters based on the denoising time step, enabling high-quality 4-bit generation with zero additional inference latency.

The Challenge of Quantizing Diffusion Models

Standard "static" quantization methods use a single, fixed scale for all operations. However, diffusion models possess a unique "time-variant" property: the distribution of their internal activations shifts drastically as the image transitions from pure noise to a clean result.

Using a fixed quantization scale across all time steps leads to massive errors:

  1. Truncation Error: If the scale is too small, large activation values at certain time steps are clipped.
  2. Rounding Error: If the scale is too large, precision is lost for smaller values at other time steps.
Static quantization struggles with shifting activation distributions, leading to severe truncation errors at different time steps.

While "dynamic" quantization—calculating scales on the fly based on input data—can solve this, it introduces significant computational overhead that often negates the speed benefits of quantization in the first place.

Temporal Dynamic Quantization (TDQ)

To bridge this gap, the authors propose the TDQ module. Instead of calculating quantization scales based on the input data (which is slow), TDQ calculates them based on the time step ($t$).

Key Mechanisms

  • The TDQ Module: A lightweight Multi-Layer Perceptron (MLP) is attached to each quantization operator. It takes the current time step $t$ as input and predicts the optimal quantization interval ($s$).
  • Frequency Encoding: Because neural networks often struggle to learn high-frequency changes from a single scalar input, the authors apply a geometric Fourier encoding (similar to positional encodings in Transformers) to the time step before feeding it to the MLP.
  • Zero Inference Overhead: Since the denoising time steps are known before inference begins, the quantization scales for every step can be pre-computed and stored in a lookup table. During image generation, the model simply retrieves the correct scale, adding absolutely no computational overhead.
  • Universal Compatibility: TDQ can be seamlessly integrated into both Post-Training Quantization (PTQ) (minimizing reconstruction error on a small calibration set) and Quantization-Aware Training (QAT) (fine-tuning the model with quantization in the loop).

Key Insights: Temporal Correlation

A core finding of the paper is that approximately 62% of layers in a diffusion model exhibit a moderate-to-strong correlation between the time step and activation variance. This confirms that time is a highly reliable proxy for activation statistics.

Activation ranges in diffusion models vary significantly across different time steps, necessitating dynamic quantization scales.

Instead of learning a separate, discrete scalar for every single time step, the TDQ module acts as a smooth interpolator. This allows the model to generalize better to different sampling schedules—for instance, training on 1000 steps but running inference with only 50. To ensure training stability, the TDQ module is initialized so its starting output matches the optimal "static" quantization scale, allowing it to gradually learn the temporal dynamics.

Experimental Results

The researchers evaluated TDQ on CIFAR-10 (using a DDIM model) and LSUN Churches (using a Latent Diffusion Model, the architecture behind Stable Diffusion). The results demonstrate that TDQ significantly outperforms standard static quantization, especially at lower bit-widths.

  • QAT Performance: In a stringent 4-bit weight and 4-bit activation (W4A4) setting on CIFAR-10, TDQ achieved a Fréchet Inception Distance (FID) of 4.48. By comparison, the popular Learned Step Size Quantization (LSQ) method lagged significantly at 7.30 (lower FID indicates better image quality).
  • PTQ Performance: For W8A5 quantization on LSUN Churches, TDQ achieved an FID of 4.85, beating the previous state-of-the-art (PTQ4DM) score of 7.06.
  • Robustness to Sampling Steps: Standard quantized models often degrade rapidly if the number of denoising steps is changed at inference time. TDQ remains highly stable, closely following the performance curve of the full-precision (FP32) model even when steps are reduced from 100 to 10.
  • Visual Quality: Qualitatively, standard W4A4 models often produce blurry or unrecognizable artifacts. TDQ, however, generates sharp, high-fidelity images that are nearly indistinguishable from the uncompressed original.

Limitations and Future Work

While highly effective, TDQ has a few limitations. About 30% of the layers—mostly in the middle blocks of the U-Net—do not show strong temporal correlation, as they are more influenced by the specific semantic content of the image. While TDQ still functions in these layers, the performance gains are less pronounced.

Additionally, for Latent Diffusion Models, the authors focused exclusively on quantizing the U-Net. Future work could extend TDQ to the VAE (which decodes latents into pixels) for further memory savings. Finally, combining TDQ's temporal focus with spatial or input-dependent cues could potentially push quantization to extreme 2-bit or 3-bit levels without sacrificing generation quality.

Summary updated

BibTeX
@inproceedings{so2023temporal,
  author = {Junhyuk So and Jungwon Lee and Daehyun Ahn and Hyungjun Kim and Eunhyeok Park},
  title = {{Temporal Dynamic Quantization for Diffusion Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=D1sECc9fiG},
}
Figure