text
stringlengths
0
5.54k
Diffusion. DEISMultistepScheduler is a fast high order solver for diffusion ordinary differential equations (ODEs). This model inherits from SchedulerMixin and ConfigMixin. Check the superclass documentation for the generic
methods the library implements for all schedulers such as loading and saving. convert_model_output < source > ( model_output: FloatTensor *args sample: FloatTensor = None **kwargs ) → torch.FloatTensor Parameters model_output (torch.FloatTensor) —
The direct output from the learned diffusion model. timestep (int) —
The current discrete timestep in the diffusion chain. sample (torch.FloatTensor) —
A current instance of a sample created by the diffusion process. Returns
torch.FloatTensor
The converted model output.
Convert the model output to the corresponding type the DEIS algorithm needs. deis_first_order_update < source > ( model_output: FloatTensor *args sample: FloatTensor = None **kwargs ) → torch.FloatTensor Parameters model_output (torch.FloatTensor) —
The direct output from the learned diffusion model. timestep (int) —
The current discrete timestep in the diffusion chain. prev_timestep (int) —
The previous discrete timestep in the diffusion chain. sample (torch.FloatTensor) —
A current instance of a sample created by the diffusion process. Returns
torch.FloatTensor
The sample tensor at the previous timestep.
One step for the first-order DEIS (equivalent to DDIM). multistep_deis_second_order_update < source > ( model_output_list: List *args sample: FloatTensor = None **kwargs ) → torch.FloatTensor Parameters model_output_list (List[torch.FloatTensor]) —
The direct outputs from learned diffusion model at current and latter timesteps. sample (torch.FloatTensor) —
A current instance of a sample created by the diffusion process. Returns
torch.FloatTensor
The sample tensor at the previous timestep.
One step for the second-order multistep DEIS. multistep_deis_third_order_update < source > ( model_output_list: List *args sample: FloatTensor = None **kwargs ) → torch.FloatTensor Parameters model_output_list (List[torch.FloatTensor]) —
The direct outputs from learned diffusion model at current and latter timesteps. sample (torch.FloatTensor) —
A current instance of a sample created by diffusion process. Returns
torch.FloatTensor
The sample tensor at the previous timestep.
One step for the third-order multistep DEIS. scale_model_input < source > ( sample: FloatTensor *args **kwargs ) → torch.FloatTensor Parameters sample (torch.FloatTensor) —
The input sample. Returns
torch.FloatTensor
A scaled input sample.
Ensures interchangeability with schedulers that need to scale the denoising model input depending on the
current timestep. set_timesteps < source > ( num_inference_steps: int device: Union = None ) Parameters num_inference_steps (int) —
The number of diffusion steps used when generating samples with a pre-trained model. device (str or torch.device, optional) —
The device to which the timesteps should be moved to. If None, the timesteps are not moved. Sets the discrete timesteps used for the diffusion chain (to be run before inference). step < source > ( model_output: FloatTensor timestep: int sample: FloatTensor return_dict: bool = True ) → SchedulerOutput or tuple Pa...
The direct output from learned diffusion model. timestep (float) —
The current discrete timestep in the diffusion chain. sample (torch.FloatTensor) —
A current instance of a sample created by the diffusion process. return_dict (bool) —
Whether or not to return a SchedulerOutput or tuple. Returns
SchedulerOutput or tuple
If return_dict is True, SchedulerOutput is returned, otherwise a
tuple is returned where the first element is the sample tensor.
Predict the sample from the previous timestep by reversing the SDE. This function propagates the sample with
the multistep DEIS. SchedulerOutput class diffusers.schedulers.scheduling_utils.SchedulerOutput < source > ( prev_sample: FloatTensor ) Parameters prev_sample (torch.FloatTensor of shape (batch_size, num_channels, height, width) for images) —
Computed sample (x_{t-1}) of previous timestep. prev_sample should be used as next model input in the
denoising loop. Base class for the output of a scheduler’s step function.
Philosophy 🧨 Diffusers provides state-of-the-art pretrained diffusion models across multiple modalities.
Its purpose is to serve as a modular toolbox for both inference and training. We aim at building a library that stands the test of time and therefore take API design very seriously. In a nutshell, Diffusers is built to be a natural extension of PyTorch. Therefore, most of our design choices are based on PyTorch’s Desig...
is very simple thanks to Diffusers’ ability to separate single components of the diffusion pipeline. Tweakable, contributor-friendly over abstraction For large parts of the library, Diffusers adopts an important design principle of the Transformers library, which is to prefer copy-pasted code over hasty abstractions. ...
In short, just like Transformers does for modeling files, Diffusers prefers to keep an extremely low level of abstraction and very self-contained code for pipelines and schedulers.
Functions, long code blocks, and even classes can be copied across multiple files which at first can look like a bad, sloppy design choice that makes the library unmaintainable.
However, this design has proven to be extremely successful for Transformers and makes a lot of sense for community-driven, open-source machine learning libraries because: Machine Learning is an extremely fast-moving field in which paradigms, model architectures, and algorithms are changing rapidly, which therefore make...
at this blog post. In Diffusers, we follow this philosophy for both pipelines and schedulers, but only partly for diffusion models. The reason we don’t follow this design fully for diffusion models is because almost all diffusion pipelines, such
as DDPM, Stable Diffusion, unCLIP (DALL·E 2) and Imagen all rely on the same diffusion model, the UNet. Great, now you should have generally understood why 🧨 Diffusers is designed the way it is 🤗.
We try to apply these design principles consistently across the library. Nevertheless, there are some minor exceptions to the philosophy or some unlucky design choices. If you have feedback regarding the design, we would ❤️ to hear it directly on GitHub. Design Philosophy in Details Now, let’s look a bit into the nit...
Let’s walk through more in-detail design decisions for each class. Pipelines Pipelines are designed to be easy to use (therefore do not follow Simple over easy 100%), are not feature complete, and should loosely be seen as examples of how to use models and schedulers for inference. The following design principles are ...
readable long-term, such as UNet blocks and Attention processors. Schedulers Schedulers are responsible to guide the denoising process for inference as well as to define a noise schedule for training. They are designed as individual classes with loadable configuration files and strongly follow the single-file policy. ...
T2I-Adapter T2I-Adapter is a lightweight adapter model that provides an additional conditioning input image (line art, canny, sketch, depth, pose) to better control image generation. It is similar to a ControlNet, but it is a lot smaller (~77M parameters and ~300MB file size) because its only inserts weights into the U...
cd diffusers
pip install . Then navigate to the example folder containing the training script and install the required dependencies for the script you’re using: Copied cd examples/t2i_adapter
pip install -r requirements.txt 🤗 Accelerate is a library for helping you train on multiple GPUs/TPUs or with mixed-precision. It’ll automatically configure your training setup based on your hardware and environment. Take a look at the 🤗 Accelerate Quick tour to learn more. Initialize an 🤗 Accelerate environment: ...
write_basic_config() Lastly, if you want to train a model on your own dataset, take a look at the Create a dataset for training guide to learn how to create a dataset that works with the training script. The following sections highlight parts of the training script that are important for understanding how to modify it,...
----gradient_accumulation_steps=4 Many of the basic and important parameters are described in the Text-to-image training guide, so this guide just focuses on the relevant T2I-Adapter parameters: --pretrained_vae_model_name_or_path: path to a pretrained VAE; the SDXL VAE is known to suffer from numerical instability, ...
[
transforms.Resize(args.resolution, interpolation=transforms.InterpolationMode.BILINEAR),
transforms.CenterCrop(args.resolution),
transforms.ToTensor(),
]
) Within the main() function, the T2I-Adapter is either loaded from a pretrained adapter or it is randomly initialized: Copied if args.adapter_model_name_or_path:
logger.info("Loading existing adapter weights.")
t2iadapter = T2IAdapter.from_pretrained(args.adapter_model_name_or_path)
else:
logger.info("Initializing t2iadapter weights.")
t2iadapter = T2IAdapter(
in_channels=3,
channels=(320, 640, 1280, 1280),
num_res_blocks=2,
downscale_factor=16,
adapter_type="full_adapter_xl",
) The optimizer is initialized for the T2I-Adapter parameters: Copied params_to_optimize = t2iadapter.parameters()
optimizer = optimizer_class(
params_to_optimize,
lr=args.learning_rate,
betas=(args.adam_beta1, args.adam_beta2),
weight_decay=args.adam_weight_decay,
eps=args.adam_epsilon,
) Lastly, in the training loop, the adapter conditioning image and the text embeddings are passed to the UNet to predict the noise residual: Copied t2iadapter_image = batch["conditioning_pixel_values"].to(dtype=weight_dtype)
down_block_additional_residuals = t2iadapter(t2iadapter_image)
down_block_additional_residuals = [
sample.to(dtype=weight_dtype) for sample in down_block_additional_residuals
]
model_pred = unet(
inp_noisy_latents,
timesteps,
encoder_hidden_states=batch["prompt_ids"],