Memory-efficient Diffusion Transformers with Quanto and Diffusers
Weight quantization with Quanto cuts the GPU memory of Transformer-based diffusion pipelines (PixArt-Sigma, Stable Diffusion 3, Aura Flow) with little quality loss and a modest latency cost. Quantizing the text encoders as well as the diffusion transformer matters most: PixArt drops from about 12 GB to 5.4 GB with FP8. For SD3, the second text encoder should be left unquantized. Benchmarks on an H100 show that bfloat16 and qint8 with fused QKV projections reduce latency. INT4 saves the most memory but is slower and needs the final proj_out layer excluded to preserve quality. Code covers quantizing, saving and loading quantized Diffusers models.
Related posts
- Exploring Quantization Backends in Diffusers
Hugging Face mediumAdeptHugging Face Diffusers supports several quantization backends (bitsandbytes, torchao, Quanto, GGUF and native FP8 layerwise casting) that shrink large diffusion models such as Flux-dev, whose full BF16 pipeline needs about 31 GB. Benchmarks on an H100 put BnB 4-bit NF4 at about 12.6 GB after loading with no inference slowdown, while torchao and Quanto INT4 cut memory further but take roughly 109 seconds per image versus 12 seconds for BF16. Code examples apply PipelineQuantizationConfig to the transformer and T5 encoder, load pre-quantized GGUF files, and combine quantization with CPU offloading, group offloading and torch.compile. The 8-bit quality differences are usually hard to see, and NF4 is suggested as the best tradeoff.
- Making LLMs lighter with AutoGPTQ and transformers
Hugging Face mediumAdeptAutoGPTQ is now integrated into Hugging Face Transformers (via Optimum), letting users quantize and run LLMs at 8, 4, 3 or 2 bits with the GPTQ post-training method. GPTQ needs a calibration dataset and quantizes only the weights: int4 weights are dequantized on the fly in a fused kernel while compute stays in fp16. That gives nearly 4x memory savings with negligible accuracy loss at 4-bit. On an A100 at batch size 1, Llama-2-7B with the exllama kernel dropped peak memory from about 29 GB to 10.5 GB with slightly better per-token latency than fp16. Text-Generation-Inference can now serve a 70B model on a single 80GB GPU and PEFT adapters can be fine-tuned on top, but the kernels slow down at larger batch sizes and W4A8 or Triton kernels remain open work.
- Optimizing Stable Diffusion for Intel CPUs with NNCF and π€ Optimum
Hugging Face hardMasterPost-training 8-bit quantization breaks Stable Diffusion's UNet, so this workflow uses NNCF quantization-aware training with knowledge distillation from the original model as teacher and EMA on non-quantizer weights. It is stacked with an OpenVINO-compatible Token Merging (merge ratio 0.4) to speed up inference on Intel CPUs. Fine-tuning a Pokemon-tuned model for 4096 iterations on a single 24 GB GPU takes under a day. Against PyTorch FP32 on a Xeon CPU, OpenVINO FP32 gives 1.9x, 8-bit QAT gives 3.9x with a 4x smaller footprint, and ToMe plus 8-bit reaches 5.1x. The resulting pipeline loads through Optimum Intel's OVStableDiffusionPipeline, and more complex datasets call for lower merging ratios.
- Quanto: a PyTorch quantization backend for Optimum
Hugging Face mediumAdeptQuanto is a PyTorch quantization backend for Optimum that works in eager mode on any device (CPU, CUDA, MPS), supports int2/int4/int8/float8 weights and int8/float8 activations, and accelerates int8-int8, fp16-int4, bf16-int8 and bf16-int4 matmuls on CUDA. The workflow runs from dynamic quantization through optional activation calibration and quantization-aware training to freezing integer weights, then serializing with safetensors plus a quantization map for reloading via requantize. It integrates with transformers through QuantoConfig, works across modalities such as Whisper, and is torch.compile-friendly when activations are left unquantized.
- Welcome FLUX.3 Image Klein in Diffusers
Hugging Face mediumAdeptFLUX.3 Image Klein from Black Forest Labs is supported in Diffusers from launch. It is a single model for text-to-image, multi-reference image-to-image, and bounding-box layout control, where regions are written as JSON with normalized 0β1000 boxes to place new content or move content from a reference image. The distilled checkpoint renders 1024Γ1024 in about 1.9 s on an H100 in 16 steps without CFG. Reference images roughly double the time because each adds 4,096 tokens to the transformer sequence. The post also covers FP8 and NVFP4 single-file variants that cut peak memory to about 15β16 GiB, DreamBooth LoRA training scripts, the VAE tokenization (one token per 16Γ16 patch), and Modular Diffusers pipeline usage.