Diffusers 文档
KDPM2AncestralDiscreteScheduler
并获得增强的文档体验
开始使用
KDPM2AncestralDiscreteScheduler
带有祖先采样的 KDPM2DiscreteScheduler
受 Elucidating the Design Space of Diffusion-Based Generative Models 论文的启发,并且该 scheduler 是由 Katherine Crowson 移植和创建的。
原始代码库可以在 crowsonkb/k-diffusion 中找到。
KDPM2AncestralDiscreteScheduler
class diffusers.KDPM2AncestralDiscreteScheduler
< source >( 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 序列。可从linear
或scaled_linear
中选择。 - trained_betas (
np.ndarray
, 可选) — 直接将 beta 数组传递给构造函数以绕过beta_start
和beta_end
。 - use_karras_sigmas (
bool
, optional, defaults toFalse
) — 是否在采样过程中对噪声时间表中的步长使用 Karras sigmas。如果为True
,则根据噪声水平序列 {σi} 确定 sigmas。 - use_exponential_sigmas (
bool
, optional, defaults toFalse
) — 是否在采样过程中对噪声时间表中的步长使用指数 sigmas。 - use_beta_sigmas (
bool
, optional, defaults toFalse
) — 是否在采样过程中对噪声时间表中的步长使用 beta sigmas。有关更多信息,请参阅 Beta Sampling is All You Need。 - prediction_type (
str
, defaults toepsilon
, 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。
此模型继承自 SchedulerMixin 和 ConfigMixin。查看超类文档以获取库为所有调度器实现的通用方法,例如加载和保存。
scale_model_input
< source >( sample: Tensor timestep: typing.Union[float, torch.Tensor] ) → torch.Tensor
确保与需要根据当前时间步缩放去噪模型输入的调度器具有互换性。
设置调度器的起始索引。此函数应在推理之前从管道运行。
set_timesteps
< source >( num_inference_steps: int device: typing.Union[str, torch.device] = None num_train_timesteps: typing.Optional[int] = None )
设置用于扩散链的离散时间步长(在推理之前运行)。
step
< source >( 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 ) → KDPM2AncestralDiscreteSchedulerOutput
或 tuple
参数
- model_output (
torch.Tensor
) — 来自学习的扩散模型的直接输出。 - timestep (
float
) — 扩散链中的当前离散时间步长。 - sample (
torch.Tensor
) — 由扩散过程创建的样本的当前实例。 - generator (
torch.Generator
, optional) — 随机数生成器。 - return_dict (
bool
) — 是否返回KDPM2AncestralDiscreteSchedulerOutput
或 tuple。
返回值
KDPM2AncestralDiscreteSchedulerOutput
或 tuple
如果 return_dict 为 True
,则返回 KDPM2AncestralDiscreteSchedulerOutput
,否则返回一个 tuple,其中第一个元素是样本张量。
通过反转 SDE,从上一个时间步预测样本。此函数从学习的模型输出(通常是预测的噪声)传播扩散过程。
SchedulerOutput
class diffusers.schedulers.scheduling_utils.SchedulerOutput
< source >( prev_sample: Tensor )
调度器的 step
函数输出的基类。