Diffusers 文档

LMSDiscreteScheduler

Hugging Face's logo
加入 Hugging Face 社区

并获取增强的文档体验

开始使用

LMSDiscreteScheduler

LMSDiscreteScheduler 是用于离散 beta 计划的线性多步调度器。该调度器由 Katherine Crowson 移植和创建,原始实现可在 crowsonkb/k-diffusion 中找到。

LMSDiscreteScheduler

class diffusers.LMSDiscreteScheduler

< >

( num_train_timesteps: int = 1000 beta_start: float = 0.0001 beta_end: float = 0.02 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.0001) — 推理的起始 beta 值。
  • beta_end (float, 默认为 0.02) — 最终 beta 值。
  • beta_schedule (str, 默认为 "linear") — beta 计划,从 beta 范围到用于步进模型的 beta 序列的映射。从 linearscaled_linear 中选择。
  • trained_betas (np.ndarray, 可选) — 直接将 beta 数组传递给构造函数以绕过 beta_startbeta_end
  • use_karras_sigmas (bool, 可选, 默认为 False) — 是否在采样过程中对噪声计划中的步长使用 Karras sigma 值。如果为 True,则根据噪声水平序列 {σi} 确定 sigma 值。
  • 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) — 添加到推理步数的偏移量,某些模型系列需要此偏移量。

用于离散 beta 时间表的线性多步调度器。

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

get_lms_coefficient

< >

( order t current_order )

参数

  • order () —
  • t () —
  • current_order () —

计算线性多步系数。

scale_model_input

< >

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

参数

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

返回

torch.Tensor

缩放后的输入样本。

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

set_begin_index

< >

( begin_index: int = 0 )

参数

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

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

set_timesteps

< >

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

参数

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

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

step

< >

( model_output: Tensor timestep: typing.Union[float, torch.Tensor] sample: Tensor order: int = 4 return_dict: bool = True ) SchedulerOutput or tuple

参数

  • model_output (torch.Tensor) — 来自学习的扩散模型的直接输出。
  • timestep (float or torch.Tensor) — 扩散链中的当前离散时间步。
  • sample (torch.Tensor) — 扩散过程创建的样本的当前实例。
  • order (int, defaults to 4) — 线性多步方法的阶数。
  • return_dict (bool, optional, defaults to True) — 是否返回 SchedulerOutput 或 tuple。

返回

SchedulerOutputtuple

如果 `return_dict` 为 `True`,则返回 SchedulerOutput,否则返回一个 tuple,其中第一个元素是 sample tensor。

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

LMSDiscreteSchedulerOutput

class diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteSchedulerOutput

< >

( prev_sample: Tensor pred_original_sample: typing.Optional[torch.Tensor] = None )

参数

  • prev_sample (torch.Tensor of shape (batch_size, num_channels, height, width) for images) — 计算出的前一个时间步的样本 (`x_{t-1}`)。 `prev_sample` 应在去噪循环中用作下一个模型输入。
  • pred_original_sample (torch.Tensor of shape (batch_size, num_channels, height, width) for images) — 基于当前时间步的模型输出预测的去噪样本 (`x_{0}`)。 `pred_original_sample` 可以用于预览进度或进行指导。

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

< > Update on GitHub