DiT¶
Scalable Diffusion Models with Transformers (DiT) is by William Peebles and Saining Xie.
The abstract from the paper is:
We explore a new class of diffusion models based on the transformer architecture. We train latent diffusion models of images, replacing the commonly-used U-Net backbone with a transformer that operates on latent patches. We analyze the scalability of our Diffusion Transformers (DiTs) through the lens of forward pass complexity as measured by Gflops. We find that DiTs with higher Gflops -- through increased transformer depth/width or increased number of input tokens -- consistently have lower FID. In addition to possessing good scalability properties, our largest DiT-XL/2 models outperform all prior diffusion models on the class-conditional ImageNet 512x512 and 256x256 benchmarks, achieving a state-of-the-art FID of 2.27 on the latter.
The original codebase can be found at facebookresearch/dit.
Tip
Make sure to check out the Schedulers guide to learn how to explore the tradeoff between scheduler speed and quality, and see the reuse components across pipelines section to learn how to efficiently load the same components into multiple pipelines.
mindone.diffusers.DiTPipeline
¶
Bases: DiffusionPipeline
Pipeline for image generation based on a Transformer backbone instead of a UNet.
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 |
---|---|
transformer |
A class conditioned
TYPE:
|
vae |
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
TYPE:
|
scheduler |
A scheduler to be used in combination with
TYPE:
|
Source code in mindone/diffusers/pipelines/dit/pipeline_dit.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 |
|
mindone.diffusers.DiTPipeline.__call__(class_labels, guidance_scale=4.0, generator=None, num_inference_steps=50, output_type='pil', return_dict=False)
¶
The call function to the pipeline for generation.
PARAMETER | DESCRIPTION |
---|---|
class_labels |
List of ImageNet class labels for the images to be generated.
TYPE:
|
guidance_scale |
A higher guidance scale value encourages the model to generate images closely linked to the text
TYPE:
|
generator |
A
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:
|
output_type |
The output format of the generated image. Choose between
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
>>> from mindone.diffusers import DiTPipeline, DPMSolverMultistepScheduler
>>> import mindspore as ms
>>> import numpy as np
>>> pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-256", mindspore_dtype=ms.float16)
>>> pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
>>> # pick words from Imagenet class labels
>>> pipe.labels # to print all available words
>>> # pick words that exist in ImageNet
>>> words = ["white shark", "umbrella"]
>>> class_ids = pipe.get_label_ids(words)
>>> generator = np.random.default_rng(33)
>>> output = pipe(class_labels=class_ids, num_inference_steps=25, generator=generator)
>>> image = output[0][0] # label 'white shark'
RETURNS | DESCRIPTION |
---|---|
Union[ImagePipelineOutput, Tuple]
|
[ |
Source code in mindone/diffusers/pipelines/dit/pipeline_dit.py
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 |
|
mindone.diffusers.DiTPipeline.get_label_ids(label)
¶
Map label strings from ImageNet to corresponding class ids.
PARAMETER | DESCRIPTION |
---|---|
label |
Label strings to be mapped to class ids.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[int]
|
|
Source code in mindone/diffusers/pipelines/dit/pipeline_dit.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
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 |
|