Diffusers documentation

DDIMInverseScheduler

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

DDIMInverseScheduler

DDIMInverseScheduler 是 Jiaming Song、Chenlin Meng 和 Stefano Ermon 提出的 Denoising Diffusion Implicit Models(DDIM)中的反向调度器。 其实现主要基于 Null-text Inversion for Editing Real Images using Guided Diffusion Models 中定义的 DDIM 反转。

DDIMInverseScheduler

class diffusers.DDIMInverseScheduler

< >

( num_train_timesteps: int = 1000beta_start: float = 0.0001beta_end: float = 0.02beta_schedule: typing.Literal['linear', 'scaled_linear', 'squaredcos_cap_v2'] = 'linear'trained_betas: numpy.ndarray | list[float] | None = Noneclip_sample: bool = Trueset_alpha_to_one: bool = Truesteps_offset: int = 0prediction_type: typing.Literal['epsilon', 'sample', 'v_prediction'] = 'epsilon'clip_sample_range: float = 1.0timestep_spacing: typing.Literal['leading', 'trailing'] = 'leading'rescale_betas_zero_snr: bool = False**kwargs )

参数

  • 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 或 squaredcos_cap_v2。
  • trained_betas (np.ndarray, 可选) — 直接传入 betas 数组到构造函数中,以绕过 beta_start 和 beta_end。
  • clip_sample (bool,默认为 True) — 对预测样本进行裁剪,以确保数值稳定性。
  • clip_sample_range (float,默认为 1.0) — 样本裁剪的最大幅度。仅在 clip_sample=True 时有效。
  • set_alpha_to_one (bool,默认为 True) — 每个扩散步骤都会使用当前步骤和上一步骤的 alpha 乘积值。对于最后一步,不存在上一步的 alpha。当此选项为 True 时,上一步的 alpha 乘积被固定为 0;否则,使用步骤 num_train_timesteps - 1 处的 alpha 值。
  • steps_offset (int,默认为 0) — 添加到推理步数中的偏移量,某些模型系列需要此参数。
  • prediction_type (str, defaults to epsilon, optional) — Prediction type of the scheduler function; can be epsilon (predicts the noise of the diffusion process), sample (directly predicts the noisy sample) or v_prediction` (see section 2.4 of Imagen Video paper).
  • timestep_spacing (str,默认为 "leading") — 时间步的缩放方式。更多信息请参阅 常见扩散噪声调度和采样步骤存在缺陷 中的表 2。
  • rescale_betas_zero_snr (bool,默认为 False) — 是否重新缩放 betas 以实现零终端 SNR。这使模型能够生成非常明亮和非常暗的样本,而不是将其限制在中等亮度的样本上。与 --offset_noise 大致相关。

DDIMInverseScheduler 是 DDIMScheduler 的反向调度器。

该模型继承自 SchedulerMixin 和 ConfigMixin。有关该库为所有调度器实现的通用方法(例如加载和保存),请参阅父类文档。

scale_model_input

< >

( sample: Tensortimestep: int | None = None ) → torch.Tensor

参数

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

返回值

torch.Tensor

经过缩放的输入样本。

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

set_timesteps

< >

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

参数

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

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

步骤

< >

( model_output: Tensortimestep: intsample: Tensorreturn_dict: bool = True ) → ~schedulers.scheduling_ddim_inverse.DDIMInverseSchedulerOutput or tuple

参数

  • model_output (torch.Tensor) — 学习到的扩散模型的直接输出。
  • timestep (int) — 扩散链中的当前离散时间步。
  • sample (torch.Tensor) — 扩散过程生成的样本的当前实例。
  • return_dict (bool,可选,默认为 True) — 是否返回 ~schedulers.scheduling_ddim_inverse.DDIMInverseSchedulerOutput 或 tuple。

返回值

~schedulers.scheduling_ddim_inverse.DDIMInverseSchedulerOutput 或 tuple

如果 True,则返回 ~schedulers.scheduling_ddim_inverse.DDIMInverseSchedulerOutput,否则返回一个元组,其中第一个元素是样本张量。

通过逆向 SDE 预测上一时间步的样本。此函数将扩散过程从学习到的模型输出(通常是预测的噪声)进行传播。

Update on GitHub