Diffusers contains multiple pre-built schedule functions for the diffusion process.
The schedule functions, denoted Schedulers in the library take in the output of a trained model, a sample which the diffusion process is iterating on, and a timestep to return a denoised sample. That’s why schedulers may also be called Samplers in other diffusion models implementations.
All schedulers take in a timestep to predict the updated version of the sample being diffused.
The timesteps dictate where in the diffusion process the step is, where data is generated by iterating forward in time and inference is executed by propagating backwards through timesteps.
Different algorithms use timesteps that can be discrete (accepting int
inputs), such as the DDPMScheduler or PNDMScheduler, or continuous (accepting float
inputs), such as the score-based schedulers ScoreSdeVeScheduler or ScoreSdeVpScheduler
.
The core design principle between the schedule functions is to be model, system, and framework independent. This allows for rapid experimentation and cleaner abstractions in the code, where the model prediction is separated from the sample update. To this end, the design of schedulers is such that:
KarrasDiffusionSchedulers
The following table summarizes all officially supported schedulers, their corresponding paper
The core API for any new scheduler must follow a limited structure.
def step(...)
functions that should be called to update the generated sample iteratively.set_timesteps(...)
method that configures the parameters of a schedule function for a specific inference task.The base class SchedulerMixin implements low level utilities used by multiple schedulers.
Mixin containing common functions for the schedulers.
Class attributes:
List[str]
) — A list of classes that are compatible with the parent class, so that
from_config
can be used from a class different than the one used to save the config (should be overridden
by parent class).( pretrained_model_name_or_path: typing.Dict[str, typing.Any] = None subfolder: typing.Optional[str] = None return_unused_kwargs = False **kwargs )
Parameters
str
or os.PathLike
, optional) —
Can be either:
google/ddpm-celebahq-256
../my_model_directory/
.str
, optional) —
In case the relevant files are located inside a subfolder of the model repo (either remote in
huggingface.co or downloaded locally), you can specify the folder name here.
bool
, optional, defaults to False
) —
Whether kwargs that are not consumed by the Python class should be returned or not.
Union[str, os.PathLike]
, optional) —
Path to a directory in which a downloaded pretrained model configuration should be cached if the
standard cache should not be used.
bool
, optional, defaults to False
) —
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist.
bool
, optional, defaults to False
) —
Whether or not to delete incompletely received files. Will attempt to resume the download if such a
file exists.
Dict[str, str]
, optional) —
A dictionary of proxy servers to use by protocol or endpoint, e.g., {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}
. The proxies are used on each request.
bool
, optional, defaults to False
) —
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
bool
, optional, defaults to False
) —
Whether or not to only look at local files (i.e., do not try to download the model).
str
or bool, optional) —
The token to use as HTTP bearer authorization for remote files. If True
, will use the token generated
when running transformers-cli login
(stored in ~/.huggingface
).
str
, optional, defaults to "main"
) —
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
git-based system for storing models and other artifacts on huggingface.co, so revision
can be any
identifier allowed by git.
Instantiate a Scheduler class from a pre-defined JSON configuration file inside a directory or Hub repo.
It is required to be logged in (huggingface-cli login
) when you want to use private or gated
models.
Activate the special “offline-mode” to use this method in a firewalled environment.
( save_directory: typing.Union[str, os.PathLike] push_to_hub: bool = False **kwargs )
Save a scheduler configuration object to the directory save_directory
, so that it can be re-loaded using the
from_pretrained() class method.
( prev_sample: FloatTensor )
Base class for the scheduler’s step function output.
KarrasDiffusionSchedulers
encompasses the main generalization of schedulers in Diffusers. The schedulers in this class are distinguished, at a high level, by their noise sampling strategy; the type of network and scaling; and finally the training strategy or how the loss is weighed.
The different schedulers, depending on the type of ODE solver, fall into the above taxonomy and provide a good abstraction for the design of the main schedulers implemented in Diffusers. The schedulers in this class are given below:
( value names = None module = None qualname = None type = None start = 1 )
An enumeration.