DiT
Last updated
Last updated
(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 .
Make sure to check out the Schedulers to learn how to explore the tradeoff between scheduler speed and quality, and see the section to learn how to efficiently load the same components into multiple pipelines.
( transformer: Transformer2DModelvae: AutoencoderKLscheduler: KarrasDiffusionSchedulersid2label: typing.Union[typing.Dict[int, str], NoneType] = None )
Parameters
transformer () — A class conditioned Transformer2DModel
to denoise the encoded image latents.
vae () — Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
scheduler () — A scheduler to be used in combination with transformer
to denoise the encoded image latents.
Pipeline for image generation based on a Transformer backbone instead of a UNet.
__call__
Parameters
class_labels (List[int]) — List of ImageNet class labels for the images to be generated.
guidance_scale (float
, optional, defaults to 4.0) — A higher guidance scale value encourages the model to generate images closely linked to the text prompt
at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1
.
num_inference_steps (int
, optional, defaults to 250) — The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference.
output_type (str
, optional, defaults to "pil"
) — The output format of the generated image. Choose between PIL.Image
or np.array
.
Returns
The call function to the pipeline for generation.
Examples:
Copied
get_label_ids
( label: typing.Union[str, typing.List[str]] ) → list
of int
Parameters
label (str
or dict
of str
) — Label strings to be mapped to class ids.
Returns
list
of int
Class ids to be processed by pipeline.
Map label strings from ImageNet to corresponding class ids.
( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )
Parameters
images (List[PIL.Image.Image]
or np.ndarray
) — List of denoised PIL images of length batch_size
or NumPy array of shape (batch_size, height, width, num_channels)
.
Output class for image pipelines.
This model inherits from . Check the superclass documentation for the generic methods implemented for all pipelines (downloading, saving, running on a particular device, etc.).
( class_labels: typing.List[int]guidance_scale: float = 4.0generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = Nonenum_inference_steps: int = 50output_type: typing.Optional[str] = 'pil'return_dict: bool = True ) → or tuple
generator (torch.Generator
, optional) — A to make generation deterministic.
return_dict (bool
, optional, defaults to True
) — Whether or not to return a instead of a plain tuple.
or tuple
If return_dict
is True
, is returned, otherwise a tuple
is returned where the first element is a list with the generated images