Diffusers 文档

海恩离散调度器

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

HeunDiscreteScheduler

Heun 调度器(算法 1)来自 Karras 等人的Elucidating the Design Space of Diffusion-Based Generative Models 论文。此调度器从 k-diffusion 库移植,并由 Katherine Crowson 创建。

HeunDiscreteScheduler

diffusers.HeunDiscreteScheduler

< >

( 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 prediction_type: str = 'epsilon' use_karras_sigmas: typing.Optional[bool] = False use_exponential_sigmas: typing.Optional[bool] = False use_beta_sigmas: typing.Optional[bool] = False clip_sample: typing.Optional[bool] = False clip_sample_range: float = 1.0 timestep_spacing: str = 'linspace' steps_offset: int = 0 )

参数

  • num_train_timesteps (int, 默认为 1000) — 用于训练模型的扩散步骤数。
  • beta_start (float, 默认为 0.0001) — 推理的起始 beta 值。
  • beta_end (float, 默认为 0.02) — 最终的 beta 值。
  • beta_schedule (str, 默认为 "linear") — beta 计划,从 beta 范围到用于步进模型的 beta 序列的映射。从 linearscaled_linear 中选择。
  • trained_betas (np.ndarray, 可选) — 直接将 betas 数组传递给构造函数以绕过 beta_startbeta_end
  • prediction_type (str, 默认为 epsilon, *可选*) — 调度器函数的预测类型;可以是 epsilon (预测扩散过程的噪声), sample (直接预测带噪样本) 或 v_prediction (参见 Imagen Video 论文的 2.4 节)。
  • clip_sample (bool, 默认为 True) — 裁剪预测的样本以获得数值稳定性。
  • clip_sample_range (float, 默认为 1.0) — 样本裁剪的最大幅度。仅当 clip_sample=True 时有效。
  • use_karras_sigmas (bool, *可选*, 默认为 False) — 是否在采样过程中使用 Karras sigmas 来确定噪声计划中的步长。如果为 True,则根据噪声水平序列 {σi} 确定 sigmas。
  • use_exponential_sigmas (bool, *可选*, 默认为 False) — 是否在采样过程中使用指数 sigmas 来确定噪声计划中的步长。
  • use_beta_sigmas (bool, *可选*, 默认为 False) — 是否在采样过程中使用 beta sigmas 来确定噪声计划中的步长。有关更多信息,请参阅 Beta Sampling is All You Need
  • timestep_spacing (str, 默认为 "linspace") — 时间步长应缩放的方式。有关更多信息,请参阅 Common Diffusion Noise Schedules and Sample Steps are Flawed 的表 2。
  • steps_offset (int, 默认为 0) — 添加到推理步骤的偏移量,某些模型系列需要这样做。

具有 Heun 步长的调度器,用于离散 beta 计划。

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

scale_model_input

< >

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

参数

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

返回

torch.Tensor

缩放后的输入样本。

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

set_begin_index

< >

( begin_index: int = 0 )

参数

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

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

set_timesteps

< >

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

参数

  • num_inference_steps (int) — 使用预训练模型生成样本时使用的扩散步骤数。
  • device (strtorch.device, *可选*) — 时间步长应移动到的设备。如果为 None,则时间步长不会移动。
  • num_train_timesteps (int, *可选*) — 训练模型时使用的扩散步骤数。如果为 None,则使用默认的 num_train_timesteps 属性。
  • timesteps (List[int], *可选*) — 用于支持时间步之间任意间隔的自定义时间步长。如果为 None,则将根据 timestep_spacing 属性生成时间步长。如果传递了 timesteps,则 num_inference_steps 必须为 None,并且 timestep_spacing 属性将被忽略。

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

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 ) HeunDiscreteSchedulerOutput or tuple

参数

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

返回

HeunDiscreteSchedulerOutputtuple

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

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

调度器输出

diffusers.schedulers.scheduling_utils.SchedulerOutput

< >

( prev_sample: Tensor )

参数

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

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

< > 更新 on GitHub