Diffusers 文档
KDPM2离散调度器
并获得增强的文档体验
开始使用
KDPM2DiscreteScheduler
KDPM2DiscreteScheduler
的灵感来源于 Elucidating the Design Space of Diffusion-Based Generative Models 论文,并且该调度器由 Katherine Crowson 移植和创建。
原始代码库可以在 crowsonkb/k-diffusion 中找到。
KDPM2DiscreteScheduler
class diffusers.KDPM2DiscreteScheduler
< 源代码 >( num_train_timesteps: int = 1000 beta_start: float = 0.00085 beta_end: float = 0.012 beta_schedule: str = 'linear' trained_betas: typing.Union[numpy.ndarray, typing.List[float], NoneType] = None use_karras_sigmas: typing.Optional[bool] = False use_exponential_sigmas: typing.Optional[bool] = False use_beta_sigmas: typing.Optional[bool] = False prediction_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
, 可选) — 直接将 beta 数组传递给构造函数以绕过beta_start
和beta_end
。 - use_karras_sigmas (
bool
, 可选, 默认为False
) — 是否在采样过程中对噪声调度中的步长使用 Karras sigmas。如果为True
,则根据噪声水平 {σi} 序列确定 sigmas。 - use_exponential_sigmas (
bool
, 可选, 默认为False
) — 是否在采样过程中对噪声调度中的步长使用指数 sigmas。 - use_beta_sigmas (
bool
, optional, defaults toFalse
) — 是否在采样过程中对噪声时间表中的步长使用 beta 西格玛值。 有关更多信息,请参阅 Beta Sampling is All You Need。 - prediction_type (
str
, defaults toepsilon
, optional) — 调度器函数的预测类型;可以是epsilon
(预测扩散过程的噪声),sample
(直接预测含噪样本) 或v_prediction
(参见 Imagen Video 论文的 2.4 节)。 - timestep_spacing (
str
, defaults to"linspace"
) — 时间步长应缩放的方式。 有关更多信息,请参阅 Common Diffusion Noise Schedules and Sample Steps are Flawed 的表 2。 - steps_offset (
int
, defaults to 0) — 推理步骤的偏移量,某些模型族需要此偏移量。
KDPM2DiscreteScheduler 的灵感来源于 DPMSolver2 和 Elucidating the Design Space of Diffusion-Based Generative Models 论文中的算法 2。
此模型继承自 SchedulerMixin 和 ConfigMixin。 查看超类文档以获取库为所有调度器实现的通用方法,例如加载和保存。
scale_model_input
< source >( sample: Tensor timestep: typing.Union[float, torch.Tensor] ) → torch.Tensor
确保与需要根据当前时间步缩放去噪模型输入的调度器具有互换性。
设置调度器的起始索引。 此函数应在推理之前从管道运行。
set_timesteps
< source >( num_inference_steps: int device: typing.Union[str, torch.device] = None num_train_timesteps: typing.Optional[int] = None )
设置用于扩散链的离散时间步长(在推理之前运行)。
step
< 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 ) → KDPM2DiscreteSchedulerOutput
or tuple
参数
- model_output (
torch.Tensor
) — 来自学习扩散模型的直接输出。 - timestep (
float
) — 扩散链中的当前离散时间步。 - sample (
torch.Tensor
) — 由扩散过程创建的样本的当前实例。 - return_dict (
bool
) — 是否返回KDPM2DiscreteSchedulerOutput
或元组。
Returns
KDPM2DiscreteSchedulerOutput
or tuple
如果 return_dict 为 True
,则返回 KDPM2DiscreteSchedulerOutput
,否则返回元组,其中第一个元素是样本张量。
通过反转 SDE 从上一个时间步预测样本。 此函数从学习的模型输出(通常是预测的噪声)传播扩散过程。
SchedulerOutput
class diffusers.schedulers.scheduling_utils.SchedulerOutput
< source >( prev_sample: Tensor )
调度器的 step
函数输出的基类。