Pseudo numerical methods for diffusion models (PNDM)
Overview
Original implementation can be found here.
PNDMScheduler
class diffusers.PNDMScheduler
< source >( num_train_timesteps: int = 1000 beta_start: float = 0.0001 beta_end: float = 0.02 beta_schedule: str = 'linear' trained_betas: typing.Union[numpy.ndarray, typing.List[float], NoneType] = None skip_prk_steps: bool = False set_alpha_to_one: bool = False prediction_type: str = 'epsilon' steps_offset: int = 0 )
Parameters

num_train_timesteps (
int
) — number of diffusion steps used to train the model. 
beta_start (
float
) — the startingbeta
value of inference. 
beta_end (
float
) — the finalbeta
value. 
beta_schedule (
str
) — the beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose fromlinear
,scaled_linear
, orsquaredcos_cap_v2
. 
trained_betas (
np.ndarray
, optional) — option to pass an array of betas directly to the constructor to bypassbeta_start
,beta_end
etc. 
skip_prk_steps (
bool
) — allows the scheduler to skip the RungeKutta steps that are defined in the original paper as being required before plms steps; defaults toFalse
. 
set_alpha_to_one (
bool
, defaultFalse
) — each diffusion step uses the value of alphas product at that step and at the previous one. For the final step there is no previous alpha. When this option isTrue
the previous alpha product is fixed to1
, otherwise it uses the value of alpha at step 0. 
prediction_type (
str
, defaultepsilon
, optional) — prediction type of the scheduler function, one ofepsilon
(predicting the noise of the diffusion process) orv_prediction
(see section 2.4 https://imagen.research.google/video/paper.pdf) 
steps_offset (
int
, default0
) — an offset added to the inference steps. You can use a combination ofoffset=1
andset_alpha_to_one=False
, to make the last step use step 0 for the previous alpha product, as done in stable diffusion.
Pseudo numerical methods for diffusion models (PNDM) proposes using more advanced ODE integration techniques, namely RungeKutta method and a linear multistep method.
~ConfigMixin takes care of storing all config attributes that are passed in the scheduler’s __init__
function, such as num_train_timesteps
. They can be accessed via scheduler.config.num_train_timesteps
.
SchedulerMixin provides general loading and saving functionality via the SchedulerMixin.save_pretrained() and
from_pretrained() functions.
For more details, see the original paper: https://arxiv.org/abs/2202.09778
scale_model_input
< source >(
sample: FloatTensor
*args
**kwargs
)
→
torch.FloatTensor
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: typing.Union[str, torch.device] = None )
Sets the discrete timesteps used for the diffusion chain. Supporting function to be run before inference.
step
< source >(
model_output: FloatTensor
timestep: int
sample: FloatTensor
return_dict: bool = True
)
→
SchedulerOutput or tuple
Parameters

model_output (
torch.FloatTensor
) — direct output from learned diffusion model. 
timestep (
int
) — current discrete timestep in the diffusion chain. 
sample (
torch.FloatTensor
) — current instance of sample being created by diffusion process. 
return_dict (
bool
) — option for returning tuple rather than SchedulerOutput class
Returns
SchedulerOutput or tuple
SchedulerOutput if return_dict
is True, otherwise a tuple
. When
returning a tuple, the first element is the sample tensor.
Predict the sample at the previous timestep by reversing the SDE. Core function to propagate the diffusion process from the learned model outputs (most often the predicted noise).
This function calls step_prk()
or step_plms()
depending on the internal variable counter
.
step_plms
< source >(
model_output: FloatTensor
timestep: int
sample: FloatTensor
return_dict: bool = True
)
→
~scheduling_utils.SchedulerOutput
or tuple
Parameters

model_output (
torch.FloatTensor
) — direct output from learned diffusion model. 
timestep (
int
) — current discrete timestep in the diffusion chain. 
sample (
torch.FloatTensor
) — current instance of sample being created by diffusion process. 
return_dict (
bool
) — option for returning tuple rather than SchedulerOutput class
Returns
~scheduling_utils.SchedulerOutput
or tuple
~scheduling_utils.SchedulerOutput
if return_dict
is
True, otherwise a tuple
. When returning a tuple, the first element is the sample tensor.
Step function propagating the sample with the linear multistep method. This has one forward pass with multiple times to approximate the solution.
step_prk
< source >(
model_output: FloatTensor
timestep: int
sample: FloatTensor
return_dict: bool = True
)
→
~scheduling_utils.SchedulerOutput
or tuple
Parameters

model_output (
torch.FloatTensor
) — direct output from learned diffusion model. 
timestep (
int
) — current discrete timestep in the diffusion chain. 
sample (
torch.FloatTensor
) — current instance of sample being created by diffusion process. 
return_dict (
bool
) — option for returning tuple rather than SchedulerOutput class
Returns
~scheduling_utils.SchedulerOutput
or tuple
~scheduling_utils.SchedulerOutput
if return_dict
is
True, otherwise a tuple
. When returning a tuple, the first element is the sample tensor.
Step function propagating the sample with the RungeKutta method. RK takes 4 forward passes to approximate the solution to the differential equation.