Diffusers documentation

Controlling image quality

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.29.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Controlling image quality

The components of a diffusion model, like the UNet and scheduler, can be optimized to improve the quality of generated images leading to better details. These techniques are especially useful if you don’t have the resources to simply use a larger model for inference. You can enable these techniques during inference without any additional training.

This guide will show you how to turn these techniques on in your pipeline and how to configure them to improve the quality of your generated images.


FreeU improves image details by rebalancing the UNet’s backbone and skip connection weights. The skip connections can cause the model to overlook some of the backbone semantics which may lead to unnatural image details in the generated image. This technique does not require any additional training and can be applied on the fly during inference for tasks like image-to-image and text-to-video.

Use the enable_freeu() method on your pipeline and configure the scaling factors for the backbone (b1 and b2) and skip connections (s1 and s2). The number after each scaling factor corresponds to the stage in the UNet where the factor is applied. Take a look at the FreeU repository for reference hyperparameters for different models.

Stable Diffusion v1-5
Stable Diffusion v2-1
Stable Diffusion XL
import torch
from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, safety_checker=None
pipeline.enable_freeu(s1=0.9, s2=0.2, b1=1.5, b2=1.6)
generator = torch.Generator(device="cpu").manual_seed(33)
prompt = ""
image = pipeline(prompt, generator=generator).images[0]
FreeU disabled
FreeU enabled

Call the pipelines.StableDiffusionMixin.disable_freeu() method to disable FreeU.

< > Update on GitHub