DiT (original) (raw)

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.

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.

DiTPipeline

class diffusers.DiTPipeline

< source >

( transformer: DiTTransformer2DModel vae: AutoencoderKL scheduler: KarrasDiffusionSchedulers id2label: typing.Optional[typing.Dict[int, str]] = None )

Parameters

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.).

__call__

< source >

( class_labels: typing.List[int] guidance_scale: float = 4.0 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None num_inference_steps: int = 50 output_type: typing.Optional[str] = 'pil' return_dict: bool = True ) → 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

The call function to the pipeline for generation.

Examples:

from diffusers import DiTPipeline, DPMSolverMultistepScheduler import torch

pipe = DiTPipeline.from_pretrained("facebook/DiT-XL-2-256", torch_dtype=torch.float16) pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) pipe = pipe.to("cuda")

pipe.labels

words = ["white shark", "umbrella"]

class_ids = pipe.get_label_ids(words)

generator = torch.manual_seed(33) output = pipe(class_labels=class_ids, num_inference_steps=25, generator=generator)

image = output.images[0]

get_label_ids

< source >

( label: typing.Union[str, typing.List[str]] ) → list of int

Parameters

Class ids to be processed by pipeline.

Map label strings from ImageNet to corresponding class ids.

ImagePipelineOutput

class diffusers.ImagePipelineOutput

< source >

( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )

Parameters

Output class for image pipelines.

< > Update on GitHub