Diffusers 文档
海恩离散调度器
并获得增强的文档体验
开始使用
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 序列的映射。从linear
或scaled_linear
中选择。 - trained_betas (
np.ndarray
, 可选) — 直接将 betas 数组传递给构造函数以绕过beta_start
和beta_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 计划。
此模型继承自 SchedulerMixin 和 ConfigMixin。查看超类文档,了解库为所有调度器实现的通用方法,例如加载和保存。
scale_model_input
< source >( sample: Tensor timestep: typing.Union[float, torch.Tensor] ) → torch.Tensor
确保与需要根据当前时间步缩放去噪模型输入的调度器具有互换性。
设置调度器的起始索引。此函数应在推理之前从 pipeline 运行。
set_timesteps
< source >( 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 (
str
或torch.device
, *可选*) — 时间步长应移动到的设备。如果为None
,则时间步长不会移动。 - num_train_timesteps (
int
, *可选*) — 训练模型时使用的扩散步骤数。如果为None
,则使用默认的num_train_timesteps
属性。 - timesteps (
List[int]
, *可选*) — 用于支持时间步之间任意间隔的自定义时间步长。如果为None
,则将根据timestep_spacing
属性生成时间步长。如果传递了timesteps
,则num_inference_steps
必须为None
,并且timestep_spacing
属性将被忽略。
设置用于扩散链的离散时间步长(在推理之前运行)。
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 ) → HeunDiscreteSchedulerOutput
or tuple
参数
- model_output (
torch.Tensor
) — 来自学习的扩散模型的直接输出。 - timestep (
float
) — 扩散链中的当前离散时间步长。 - sample (
torch.Tensor
) — 由扩散过程创建的样本的当前实例。 - return_dict (
bool
) — 是否返回HeunDiscreteSchedulerOutput
或 tuple。
返回
HeunDiscreteSchedulerOutput
或 tuple
如果 return_dict 为 True
,则返回 HeunDiscreteSchedulerOutput
,否则返回一个 tuple,其中第一个元素是样本张量。
通过反转 SDE,从上一个时间步预测样本。此函数从学习的模型输出(通常是预测的噪声)传播扩散过程。
调度器输出
类 diffusers.schedulers.scheduling_utils.SchedulerOutput
< 源代码 >( prev_sample: Tensor )
调度器的 step
函数输出的基类。