text
stringlengths 0
5.54k
|
---|
EulerAncestralDiscreteScheduler A scheduler that uses ancestral sampling with Euler method steps. This is a fast scheduler which can often generate good outputs in 20-30 steps. The scheduler is based on the original k-diffusion implementation by Katherine Crowson. EulerAncestralDiscreteScheduler class diffusers.EulerAncestralDiscreteScheduler < source > ( num_train_timesteps: int = 1000 beta_start: float = 0.0001 beta_end: float = 0.02 beta_schedule: str = 'linear' trained_betas: Union = None prediction_type: str = 'epsilon' timestep_spacing: str = 'linspace' steps_offset: int = 0 rescale_betas_zero_snr: bool = False ) Parameters num_train_timesteps (int, defaults to 1000) β |
The number of diffusion steps to train the model. beta_start (float, defaults to 0.0001) β |
The starting beta value of inference. beta_end (float, defaults to 0.02) β |
The final beta value. beta_schedule (str, defaults to "linear") β |
The beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from |
linear or scaled_linear. trained_betas (np.ndarray, optional) β |
Pass an array of betas directly to the constructor to bypass beta_start and beta_end. prediction_type (str, defaults to epsilon, optional) β |
Prediction type of the scheduler function; can be epsilon (predicts the noise of the diffusion process), |
sample (directly predicts the noisy sample) or v_prediction` (see section 2.4 of Imagen |
Video paper). timestep_spacing (str, defaults to "linspace") β |
The way the timesteps should be scaled. Refer to Table 2 of the Common Diffusion Noise Schedules and |
Sample Steps are Flawed for more information. steps_offset (int, defaults to 0) β |
An offset added to the inference steps. You can use a combination of offset=1 and |
set_alpha_to_one=False to make the last step use step 0 for the previous alpha product like in Stable |
Diffusion. rescale_betas_zero_snr (bool, defaults to False) β |
Whether to rescale the betas to have zero terminal SNR. This enables the model to generate very bright and |
dark samples instead of limiting it to samples with medium brightness. Loosely related to |
--offset_noise. Ancestral sampling with Euler method steps. 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. scale_model_input < source > ( sample: FloatTensor timestep: Union ) β torch.FloatTensor Parameters sample (torch.FloatTensor) β |
The input sample. timestep (int, optional) β |
The current timestep in the diffusion chain. Returns |
torch.FloatTensor |
A scaled input sample. |
Ensures interchangeability with schedulers that need to scale the denoising model input depending on the |
current timestep. Scales the denoising model input by (sigma**2 + 1) ** 0.5 to match the Euler algorithm. 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: Union sample: FloatTensor generator: Optional = None return_dict: bool = True ) β EulerAncestralDiscreteSchedulerOutput or tuple Parameters model_output (torch.FloatTensor) β |
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. generator (torch.Generator, optional) β |
A random number generator. return_dict (bool) β |
Whether or not to return a |
EulerAncestralDiscreteSchedulerOutput or tuple. Returns |
EulerAncestralDiscreteSchedulerOutput or tuple |
If return_dict is True, |
EulerAncestralDiscreteSchedulerOutput 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 diffusion |
process from the learned model outputs (most often the predicted noise). EulerAncestralDiscreteSchedulerOutput class diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteSchedulerOutput < source > ( prev_sample: FloatTensor pred_original_sample: Optional = None ) 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. pred_original_sample (torch.FloatTensor of shape (batch_size, num_channels, height, width) for images) β |
The predicted denoised sample (x_{0}) based on the model output from the current timestep. |
pred_original_sample can be used to preview progress or for guidance. Output class for the schedulerβs step function output. |
ScoreSdeVpScheduler ScoreSdeVpScheduler is a variance preserving stochastic differential equation (SDE) scheduler. It was introduced in the Score-Based Generative Modeling through Stochastic Differential Equations paper by Yang Song, Jascha Sohl-Dickstein, Diederik P. Kingma, Abhishek Kumar, Stefano Ermon, Ben Poole. The abstract from the paper is: Creating noise from data is easy; creating data from noise is generative modeling. We present a stochastic differential equation (SDE) that smoothly transforms a complex data distribution to a known prior distribution by slowly injecting noise, and a corresponding reverse-time SDE that transforms the prior distribution back into the data distribution by slowly removing the noise. Crucially, the reverse-time SDE depends only on the time-dependent gradient field (\aka, score) of the perturbed data distribution. By leveraging advances in score-based generative modeling, we can accurately estimate these scores with neural networks, and use numerical SDE solvers to generate samples. We show that this framework encapsulates previous approaches in score-based generative modeling and diffusion probabilistic modeling, allowing for new sampling procedures and new modeling capabilities. In particular, we introduce a predictor-corrector framework to correct errors in the evolution of the discretized reverse-time SDE. We also derive an equivalent neural ODE that samples from the same distribution as the SDE, but additionally enables exact likelihood computation, and improved sampling efficiency. In addition, we provide a new way to solve inverse problems with score-based models, as demonstrated with experiments on class-conditional generation, image inpainting, and colorization. Combined with multiple architectural improvements, we achieve record-breaking performance for unconditional image generation on CIFAR-10 with an Inception score of 9.89 and FID of 2.20, a competitive likelihood of 2.99 bits/dim, and demonstrate high fidelity generation of 1024 x 1024 images for the first time from a score-based generative model. π§ This scheduler is under construction! ScoreSdeVpScheduler class diffusers.schedulers.ScoreSdeVpScheduler < source > ( num_train_timesteps = 2000 beta_min = 0.1 beta_max = 20 sampling_eps = 0.001 ) Parameters num_train_timesteps (int, defaults to 2000) β |
The number of diffusion steps to train the model. beta_min (int, defaults to 0.1) β beta_max (int, defaults to 20) β sampling_eps (int, defaults to 1e-3) β |
The end value of sampling where timesteps decrease progressively from 1 to epsilon. ScoreSdeVpScheduler is a variance preserving stochastic differential equation (SDE) scheduler. 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. set_timesteps < source > ( num_inference_steps 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 continuous timesteps used for the diffusion chain (to be run before inference). step_pred < source > ( score x t generator = None ) Parameters score () β x () β t () β generator (torch.Generator, optional) β |
A random number generator. Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusion |
process from the learned model outputs (most often the predicted noise). |
Installing xFormers |
We recommend the use of xFormers for both inference and training. In our tests, the optimizations performed in the attention blocks allow for both faster speed and reduced memory consumption. |
Starting from version 0.0.16 of xFormers, released on January 2023, installation can be easily performed using pre-built pip wheels: |
Copied |
pip install xformers |
The xFormers PIP package requires the latest version of PyTorch (1.13.1 as of xFormers 0.0.16). If you need to use a previous version of PyTorch, then we recommend you install xFormers from source using the project instructions. |
After xFormers is installed, you can use enable_xformers_memory_efficient_attention() for faster inference and reduced memory consumption, as discussed here. |
According to this issue, xFormers v0.0.16 cannot be used for training (fine-tune or Dreambooth) in some GPUs. If you observe that problem, please install a development version as indicated in that comment. |
RePaint scheduler |
Overview |
DDPM-based inpainting scheduler for unsupervised inpainting with extreme masks. |
Intended for use with RePaintPipeline. |
Based on the paper RePaint: Inpainting using Denoising Diffusion Probabilistic Models |
and the original implementation by Andreas Lugmayr et al.: https://github.com/andreas128/RePaint |
RePaintScheduler |
class diffusers.RePaintScheduler |
< |
source |
> |
( |
num_train_timesteps: int = 1000 |
beta_start: float = 0.0001 |
beta_end: float = 0.02 |
beta_schedule: str = 'linear' |
eta: float = 0.0 |
trained_betas: typing.Optional[numpy.ndarray] = None |
clip_sample: bool = True |
) |
Parameters |
num_train_timesteps (int) β number of diffusion steps used to train the model. |
beta_start (float) β the starting beta value of inference. |