Diffusers 文档

KDPM2AncestralDiscreteScheduler

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

KDPM2AncestralDiscreteScheduler

带有祖先采样的 KDPM2DiscreteSchedulerElucidating the Design Space of Diffusion-Based Generative Models 论文的启发,并且该 scheduler 是由 Katherine Crowson 移植和创建的。

原始代码库可以在 crowsonkb/k-diffusion 中找到。

KDPM2AncestralDiscreteScheduler

class diffusers.KDPM2AncestralDiscreteScheduler

< >

( 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, defaults to 0.012) — 最终的 beta 值,默认为 0.012。
  • beta_schedule (str, defaults to "linear") — beta 时间表,用于将 beta 范围映射到模型步进的 beta 序列。可从 linearscaled_linear 中选择。
  • trained_betas (np.ndarray, 可选) — 直接将 beta 数组传递给构造函数以绕过 beta_startbeta_end
  • use_karras_sigmas (bool, optional, defaults to False) — 是否在采样过程中对噪声时间表中的步长使用 Karras sigmas。如果为 True,则根据噪声水平序列 {σi} 确定 sigmas。
  • use_exponential_sigmas (bool, optional, defaults to False) — 是否在采样过程中对噪声时间表中的步长使用指数 sigmas。
  • use_beta_sigmas (bool, optional, defaults to False) — 是否在采样过程中对噪声时间表中的步长使用 beta sigmas。有关更多信息,请参阅 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) — 扩散链中的当前时间步。

返回值

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] generator: typing.Optional[torch._C.Generator] = None return_dict: bool = True ) KDPM2AncestralDiscreteSchedulerOutputtuple

参数

  • model_output (torch.Tensor) — 来自学习的扩散模型的直接输出。
  • timestep (float) — 扩散链中的当前离散时间步长。
  • sample (torch.Tensor) — 由扩散过程创建的样本的当前实例。
  • generator (torch.Generator, optional) — 随机数生成器。
  • return_dict (bool) — 是否返回 KDPM2AncestralDiscreteSchedulerOutput 或 tuple。

返回值

KDPM2AncestralDiscreteSchedulerOutputtuple

如果 return_dict 为 True,则返回 KDPM2AncestralDiscreteSchedulerOutput,否则返回一个 tuple,其中第一个元素是样本张量。

通过反转 SDE,从上一个时间步预测样本。此函数从学习的模型输出(通常是预测的噪声)传播扩散过程。

SchedulerOutput

class diffusers.schedulers.scheduling_utils.SchedulerOutput

< >

( prev_sample: Tensor )

参数

  • prev_sample (torch.Tensor,形状为 (batch_size, num_channels, height, width),用于图像)— 计算出的先前时间步的样本 (x_{t-1})prev_sample 应用作去噪循环中的下一个模型输入。

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

< > 在 GitHub 上更新