Diffusers 文档

KDPM2离散调度器

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

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 序列的映射。从 linearscaled_linear 中选择。
  • trained_betas (np.ndarray, 可选) — 直接将 beta 数组传递给构造函数以绕过 beta_startbeta_end
  • use_karras_sigmas (bool, 可选, 默认为 False) — 是否在采样过程中对噪声调度中的步长使用 Karras sigmas。如果为 True,则根据噪声水平 {σi} 序列确定 sigmas。
  • use_exponential_sigmas (bool, 可选, 默认为 False) — 是否在采样过程中对噪声调度中的步长使用指数 sigmas。
  • use_beta_sigmas (bool, optional, defaults to False) — 是否在采样过程中对噪声时间表中的步长使用 beta 西格玛值。 有关更多信息,请参阅 Beta Sampling is All You Need
  • prediction_type (str, defaults to epsilon, 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。

此模型继承自 SchedulerMixinConfigMixin。 查看超类文档以获取库为所有调度器实现的通用方法,例如加载和保存。

scale_model_input

< >

( sample: Tensor timestep: typing.Union[float, torch.Tensor] ) torch.Tensor

参数

  • sample (torch.Tensor) — 输入样本。
  • timestep (int, optional) — 扩散链中的当前时间步。

Returns

torch.Tensor

缩放后的输入样本。

确保与需要根据当前时间步缩放去噪模型输入的调度器具有互换性。

set_begin_index

< >

( begin_index: int = 0 )

参数

  • begin_index (int) — 调度器的起始索引。

设置调度器的起始索引。 此函数应在推理之前从管道运行。

set_timesteps

< >

( num_inference_steps: int device: typing.Union[str, torch.device] = None num_train_timesteps: typing.Optional[int] = None )

参数

  • num_inference_steps (int) — 使用预训练模型生成样本时使用的扩散步骤数。
  • device (str or torch.device, optional) — 时间步长应移动到的设备。 如果为 None,则时间步长不会移动。

设置用于扩散链的离散时间步长(在推理之前运行)。

step

< >

( 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

< >

( prev_sample: Tensor )

参数

  • prev_sample (torch.Tensor of shape (batch_size, num_channels, height, width) for images) — 上一个时间步的计算样本 (x_{t-1})prev_sample 应在去噪循环中用作下一个模型输入。

调度器的 step 函数输出的基类。

< > Update on GitHub