Diffusers documentation
KDPM2DiscreteScheduler
KDPM2DiscreteScheduler
The KDPM2DiscreteScheduler is inspired by the Elucidating the Design Space of Diffusion-Based Generative Models paper, and the scheduler is ported from and created by Katherine Crowson.
原始代码库可在 crowsonkb/k-diffusion 中找到。
KDPM2DiscreteScheduler
class diffusers.KDPM2DiscreteScheduler
< source >( num_train_timesteps: int = 1000beta_start: float = 0.00085beta_end: float = 0.012beta_schedule: str = 'linear'trained_betas: numpy.ndarray | list[float] | None = Noneuse_karras_sigmas: bool = Falseuse_exponential_sigmas: bool = Falseuse_beta_sigmas: bool = Falseprediction_type: str = 'epsilon'timestep_spacing: str = 'linspace'steps_offset: int = 0 )
参数
- num_train_timesteps (
int,默认为1000) — 用于训练模型的扩散步数。 - beta_start (
float,默认为0.00085) — 推理的起始beta值。 - beta_end (
float,默认为0.012) — 最终的beta值。 - beta_schedule (
str,默认为"linear") — beta 调度,将 beta 范围映射为用于模型步进的一系列 beta 值。可选linear或scaled_linear。 - trained_betas(
np.ndarray或list[float],可选)— 直接传入 betas 数组到构造函数中,以绕过beta_start和beta_end。 - use_karras_sigmas (
bool,默认为False) — 是否在采样过程的噪声调度中,使用 Karras sigmas 来确定步长。如果为True, 则 sigmas 将根据噪声水平序列 {σi} 来确定。 - use_exponential_sigmas (
bool,默认为False) — 在采样过程中,噪声调度的步长是否使用指数 sigmas。 - use_beta_sigmas (
bool, defaults toFalse) — Whether to use beta sigmas for step sizes in the noise schedule during the sampling process. Refer to Beta Sampling is All You Need for more information. - prediction_type (
str, defaults to"epsilon") — Prediction type of the scheduler function; can beepsilon(predicts the noise of the diffusion process),sample(directly predicts the noisy sample) orv_prediction` (see section 2.4 of Imagen Video paper). - timestep_spacing(
str,默认为"linspace")— 时间步的缩放方式。更多信息请参阅 《常见的扩散噪声调度和采样步骤存在缺陷》 中的表 2。 - steps_offset(
int,默认为0)— 添加到推理步数中的偏移量,某些模型系列需要此参数。
KDPM2DiscreteScheduler is inspired by the DPMSolver2 and Algorithm 2 from the Elucidating the Design Space of Diffusion-Based Generative Models paper.
该模型继承自 SchedulerMixin 和 ConfigMixin。有关该库为所有调度器实现的通用方法(例如加载和保存),请参阅父类文档。
add_noise
< source >( original_samples: Tensornoise: Tensortimesteps: Tensor ) → torch.Tensor
根据指定时间步的噪声调度,向原始样本添加噪声。
index_for_timestep
< source >( timestep: typing.Union[float, torch.Tensor]schedule_timesteps: typing.Optional[torch.Tensor] = None ) → int
查找给定时间步在时间步调度中的索引。
scale_model_input
< source >( sample: Tensortimestep: typing.Union[float, torch.Tensor] ) → torch.Tensor
确保与那些需要根据当前时间步对去噪模型输入进行缩放的调度器之间的可互换性。
设置调度器的起始索引。此函数应在推理之前从流水线中运行。
set_timesteps
< source >( num_inference_steps: intdevice: typing.Union[str, torch.device, NoneType] = Nonenum_train_timesteps: int | None = None )
设置扩散链所使用的离散时间步(需在推理之前运行)。
步骤
< source >( model_output: typing.Union[torch.Tensor, numpy.ndarray]timestep: typing.Union[float, torch.Tensor]sample: typing.Union[torch.Tensor, numpy.ndarray]return_dict: bool = True )
通过逆向 SDE 预测上一时间步的样本。此函数将扩散过程从学习到的模型输出(通常是预测的噪声)进行传播。
SchedulerOutput
class diffusers.schedulers.scheduling_utils.SchedulerOutput
< source >( prev_sample: Tensor )
调度器 step 函数输出的基类。