Consistency Models¶
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, please use MindSpore Graph Mode
to generate multiple images:
import mindspore as ms
from mindone.diffusers import ConsistencyModelPipeline
+ ms.set_context(mode=0)
# Load the cd_bedroom256_lpips checkpoint.
model_id_or_path = "openai/diffusers-cd_bedroom256_lpips"
pipe = ConsistencyModelPipeline.from_pretrained(model_id_or_path, mindspore_dtype=ms.float16)
# one step sampling
image = pipe(num_inference_steps=1)[0][0]
image.save("one_step_sample.png")
# one step sampling, class-conditional image generation
# Imagenet-64 class label 145 corresponds to king penguins
image = pipe(num_inference_steps=1, class_labels=145)[0][0]
image.save("cd_imagenet64_12_onestep_sample_penguin.png")
# Multistep sampling
# Timesteps can be explicitly specified; the particular timesteps below are from the original GitHub repo:
# https://github.com/openai/consistency_models/blob/main/scripts/launch.sh#L83
image = pipe(num_inference_steps=None, timesteps=[22, 0], class_label=145)[0][0]
image.save("multi_step_sample.png")
mindone.diffusers.ConsistencyModelPipeline
¶
Bases: DiffusionPipeline
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.).
PARAMETER | DESCRIPTION |
---|---|
unet |
A
TYPE:
|
scheduler |
A scheduler to be used in combination with
TYPE:
|
Source code in mindone/diffusers/pipelines/consistency_models/pipeline_consistency_models.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
mindone.diffusers.ConsistencyModelPipeline.__call__(batch_size=1, class_labels=None, num_inference_steps=1, timesteps=None, generator=None, latents=None, output_type='pil', return_dict=False, callback=None, callback_steps=1)
¶
PARAMETER | DESCRIPTION |
---|---|
batch_size |
The number of images to generate.
TYPE:
|
class_labels |
Optional class labels for conditioning class-conditional consistency models. Not used if the model is not class-conditional.
TYPE:
|
num_inference_steps |
The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference.
TYPE:
|
timesteps |
Custom timesteps to use for the denoising process. If not defined, equal spaced
TYPE:
|
generator |
A
TYPE:
|
latents |
Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor is generated by sampling using the supplied random
TYPE:
|
output_type |
The output format of the generated image. Choose between
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
callback |
A function that calls every
TYPE:
|
callback_steps |
The frequency at which the
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
[ |
Source code in mindone/diffusers/pipelines/consistency_models/pipeline_consistency_models.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
mindone.diffusers.pipelines.ImagePipelineOutput
dataclass
¶
Bases: BaseOutput
Output class for image pipelines.
Source code in mindone/diffusers/pipelines/pipeline_utils.py
69 70 71 72 73 74 75 76 77 78 79 80 |
|