Consistency Models (original) (raw)

Consistency Models were proposed in Consistency Models by Yang Song, Prafulla Dhariwal, Mark Chen, and Ilya Sutskever.

The abstract from the paper is:

Diffusion models have significantly advanced the fields of image, audio, and video generation, but they depend on an iterative sampling process that causes slow generation. To overcome this limitation, we propose consistency models, a new family of models that generate high quality samples by directly mapping noise to data. They support fast one-step generation by design, while still allowing multistep sampling to trade compute for sample quality. They also support zero-shot data editing, such as image inpainting, colorization, and super-resolution, without requiring explicit training on these tasks. Consistency models can be trained either by distilling pre-trained diffusion models, or as standalone generative models altogether. Through extensive experiments, we demonstrate that they outperform existing distillation techniques for diffusion models in one- and few-step sampling, achieving the new state-of-the-art FID of 3.55 on CIFAR-10 and 6.20 on ImageNet 64x64 for one-step generation. When trained in isolation, consistency models become a new family of generative models that can outperform existing one-step, non-adversarial generative models on standard benchmarks such as CIFAR-10, ImageNet 64x64 and LSUN 256x256.

The original codebase can be found at openai/consistency_models, and additional checkpoints are available at openai.

The pipeline was contributed by dg845 and ayushtues. ❤️

Tips

For an additional speed-up, use torch.compile to generate multiple images in <1 second:

import torch from diffusers import ConsistencyModelPipeline

device = "cuda"

Load the cd_bedroom256_lpips checkpoint.

model_id_or_path = "openai/diffusers-cd_bedroom256_lpips" pipe = ConsistencyModelPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) pipe.to(device)

ConsistencyModelPipeline

class diffusers.ConsistencyModelPipeline

< source >

( unet: UNet2DModel scheduler: CMStochasticIterativeScheduler )

Parameters

Pipeline for unconditional or class-conditional image generation.

This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods implemented for all pipelines (downloading, saving, running on a particular device, etc.).

__call__

< source >

( batch_size: int = 1 class_labels: Union = None num_inference_steps: int = 1 timesteps: List = None generator: Union = None latents: Optional = None output_type: Optional = 'pil' return_dict: bool = True callback: Optional = None callback_steps: int = 1 ) → ImagePipelineOutput or tuple

Parameters

If return_dict is True, ImagePipelineOutput is returned, otherwise a tuple is returned where the first element is a list with the generated images.

Examples:

import torch

from diffusers import ConsistencyModelPipeline

device = "cuda"

model_id_or_path = "openai/diffusers-cd_imagenet64_l2" pipe = ConsistencyModelPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16) pipe.to(device)

image = pipe(num_inference_steps=1).images[0] image.save("cd_imagenet64_l2_onestep_sample.png")

image = pipe(num_inference_steps=1, class_labels=145).images[0] image.save("cd_imagenet64_l2_onestep_sample_penguin.png")

image = pipe(num_inference_steps=None, timesteps=[22, 0], class_labels=145).images[0] image.save("cd_imagenet64_l2_multistep_sample_penguin.png")

ImagePipelineOutput

class diffusers.ImagePipelineOutput

< source >

( images: Union )

Parameters

Output class for image pipelines.

< > Update on GitHub