Exploring Quantization Backends in Diffusers
Hugging 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.
Related posts
- Memory-efficient Diffusion Transformers with Quanto and Diffusers
Hugging Face mediumAdeptWeight 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.
- Bringing Nunchaku 4-bit Diffusion Inference to Diffusers
Hugging Face hardMasterDiffusers can now load SVDQuant/Nunchaku 4-bit (W4A4) diffusion checkpoints natively via from_pretrained(), with CUDA kernels fetched from the Hub through the kernels package instead of compiled locally. Nunchaku Lite patches stock nn.Linear modules with SVDQ W4A4 layers for attention/MLP projections and AWQ W4A16 layers for modulation layers. Because it skips architecture-specific fused kernels, it is slower than the original Nunchaku engine. On an RTX PRO 6000 it still gives about a 1.35x speedup and up to 50% lower peak VRAM versus BF16, rising to 1.8x with torch.compile. The companion diffuse-compressor toolkit calibrates, quantizes, packages and publishes new models, and model-specific adapters handle structural rewrites such as fused QKV.
- 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.
- Making LLMs even more accessible with bitsandbytes, 4-bit quantization and QLoRA
Hugging Face mediumAdeptbitsandbytes now integrates 4-bit quantization into Hugging Face transformers, letting most accelerate-loadable models (text, vision, multimodal) run in 4-bit and be fine-tuned via QLoRA, which backpropagates through a frozen 4-bit base model into LoRA adapters. QLoRA stores weights in NF4 and dequantizes to bfloat16 for compute, adds double quantization (saving ~0.4 bits per parameter) and paged optimizers, and matches 16-bit fine-tuning while fitting a 33B model on a 24GB GPU or 65B on a 48GB GPU. The post explains FP8/FP4 bit layouts and shows BitsAndBytesConfig usage. Recommended defaults are NF4 for precision, double quant for memory pressure, and a 16-bit compute dtype for speed.
- State of open video generation models in Diffusers
Hugging Face mediumAdeptOpen video generation models such as HunyuanVideo, CogVideoX, LTX-Video, Mochi-1 and Allegro share a common architecture: T5-style text encoders, a DiT-based denoiser over 3D spatio-temporal tokens, a spatially and temporally compressing VAE, and a scheduler. Diffusers runs them in a few lines of code but they need a lot of memory, about 60 GB for HunyuanVideo at default settings. Benchmarks combining bitsandbytes/FP8 quantization, CPU and group offloading, VAE tiling and layerwise casting bring HunyuanVideo down to about 6.6 GB with little extra latency. Timestep and guidance distillation speed up generation, and the finetrainers repo supports LoRA fine-tuning.