Diffusers 文档
DDIM逆向调度器
并获得增强的文档体验
开始
DDIM逆向调度器
DDIMInverseScheduler
是来自 Denoising Diffusion Implicit Models (DDIM) 的 Jiaming Song、Chenlin Meng 和 Stefano Ermon 开发的逆向调度器。 此实现主要基于 Null-text Inversion for Editing Real Images using Guided Diffusion Models 中的 DDIM 逆向定义。
DDIMInverseScheduler
类 diffusers.DDIMInverseScheduler
< 源码 >( 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 clip_sample: bool = True set_alpha_to_one: bool = True steps_offset: int = 0 prediction_type: str = 'epsilon' clip_sample_range: float = 1.0 timestep_spacing: str = '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
, 可选) — 直接将 beta 数组传递给构造函数以绕过beta_start
和beta_end
。 - clip_sample (
bool
, 默认为True
) — 裁剪预测的样本以获得数值稳定性。 - clip_sample_range (
float
, 默认为 1.0) — 样本裁剪的最大幅度。仅当clip_sample=True
时有效。 - set_alpha_to_one (
bool
, 默认为True
) — 每个扩散步骤使用该步骤和前一步骤的 alphas 乘积值。对于最后一步,没有前一个 alpha。当此选项为True
时,前一个 alpha 乘积固定为 0,否则它使用步骤num_train_timesteps - 1
的 alpha 值。 - steps_offset (
int
, 默认为 0) — 添加到推理步骤的偏移量,某些模型系列需要此偏移量。 - prediction_type (
str
, 默认为epsilon
, 可选) — 调度器函数的预测类型;可以是epsilon
(预测扩散过程的噪声)、sample
(直接预测噪声样本) 或v_prediction
(参见 Imagen Video 论文的 2.4 节)。 - timestep_spacing (
str
, 默认为"leading"
) — 应该缩放时间步长的方式。 有关更多信息,请参阅 Common Diffusion Noise Schedules and Sample Steps are Flawed 的表 2。 - rescale_betas_zero_snr (
bool
, 默认为False
) — 是否重新缩放 betas 以使其终端 SNR 为零。 这使模型能够生成非常明亮和黑暗的样本,而不是将其限制为中等亮度的样本。 与--offset_noise
松散相关。
DDIMInverseScheduler
是 DDIMScheduler 的反向调度器。
此模型继承自 SchedulerMixin 和 ConfigMixin。 查看超类文档,了解库为所有调度器(例如加载和保存)实现的通用方法。
scale_model_input
< source >( sample: Tensor timestep: typing.Optional[int] = None ) → torch.Tensor
确保与需要根据当前时间步缩放去噪模型输入的调度器具有互换性。
set_timesteps
< source >( num_inference_steps: int device: typing.Union[str, torch.device] = None )
设置用于扩散链的离散时间步长(在推理之前运行)。
step
< source >( model_output: Tensor timestep: int sample: Tensor return_dict: bool = True ) → ~schedulers.scheduling_ddim_inverse.DDIMInverseSchedulerOutput
or tuple
参数
- model_output (
torch.Tensor
) — 来自学习扩散模型的直接输出。 - timestep (
float
) — 扩散链中的当前离散时间步。 - sample (
torch.Tensor
) — 由扩散过程创建的样本的当前实例。 - eta (
float
) — 扩散步骤中添加噪声的权重。 - use_clipped_model_output (
bool
, 默认为False
) — 如果为True
,则从裁剪的预测原始样本计算“校正后的”model_output
。 这是必要的,因为当self.config.clip_sample
为True
时,预测的原始样本会被裁剪到 [-1, 1]。 如果没有发生裁剪,“校正后的”model_output
将与作为输入提供的输出一致,并且use_clipped_model_output
不起作用。 - variance_noise (
torch.Tensor
) — 通过直接为方差本身提供噪声来替代使用generator
生成噪声。 对于诸如CycleDiffusion
之类的方法很有用。 - return_dict (
bool
, 可选, 默认为True
) — 是否返回~schedulers.scheduling_ddim_inverse.DDIMInverseSchedulerOutput
或tuple
。
返回值
~schedulers.scheduling_ddim_inverse.DDIMInverseSchedulerOutput
或 tuple
如果 return_dict 为 True
,则返回 ~schedulers.scheduling_ddim_inverse.DDIMInverseSchedulerOutput
,否则返回一个元组,其中第一个元素是样本张量。
通过反转 SDE 从上一个时间步预测样本。 此函数从学习的模型输出(最常见的是预测的噪声)传播扩散过程。