Diffusers documentation
CogVideoXDPMScheduler
CogVideoXDPMScheduler
CogVideoXDPMScheduler 基于 DPM-Solver: A Fast ODE Solver for Diffusion Probabilistic Model Sampling in Around 10 Steps 和 DPM-Solver++: Fast Solver for Guided Sampling of Diffusion Probabilistic Models,专为 CogVideoX 模型设计。
CogVideoXDPMScheduler
类 diffusers.CogVideoXDPMScheduler
< source >( num_train_timesteps: int = 1000beta_start: float = 0.00085beta_end: float = 0.012beta_schedule: typing.Literal['linear', 'scaled_linear', 'squaredcos_cap_v2'] = 'scaled_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.0sample_max_value: float = 1.0timestep_spacing: typing.Literal['leading', 'linspace', 'trailing'] = 'leading'rescale_betas_zero_snr: bool = Falsesnr_shift_scale: float = 3.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或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 乘积固定为1,否则使用步骤 0 的 alpha 值。 - steps_offset (
int,默认为 0) — 添加到推理步数中的偏移量,某些模型系列需要此参数。 - prediction_type (
str, defaults toepsilon, optional) — Prediction type of the scheduler function; can beepsilon(predicts the noise of the diffusion process),sample(directly predicts the noisy sample) orv_prediction` (see section 2.4 of Imagen Video paper). - thresholding (
bool,默认为False) — 是否使用“动态阈值”方法。此方法不适用于 Stable Diffusion 等潜在空间扩散模型。 - dynamic_thresholding_ratio (
float,默认为 0.995) — 动态阈值化方法的比例。仅在thresholding=True时有效。 - sample_max_value (
float,默认为 1.0) — 动态阈值化的阈值。仅在thresholding=True时有效。 - timestep_spacing (
str, defaults to"leading") — The way the timesteps should be scaled. Refer to Table 2 of the Common Diffusion Noise Schedules and Sample Steps are Flawed for more information. Choose fromleading,linspaceortrailing. - rescale_betas_zero_snr (
bool,默认为False) — 是否重新缩放 betas 以实现零终端 SNR。这使模型能够生成非常明亮和非常暗的样本,而不是将其限制在中等亮度的样本上。与--offset_noise大致相关。 - snr_shift_scale (
float,默认为 3.0) — SNR 的偏移比例。
DDIMScheduler 在去噪扩散概率模型(DDPM)所引入的去噪过程基础上,扩展了非马尔可夫引导。
该模型继承自 SchedulerMixin 和 ConfigMixin。有关该库为所有调度器实现的通用方法(例如加载和保存),请参阅父类文档。
add_noise
< source >( original_samples: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor
根据每个时间步的噪声幅度,向原始样本添加噪声(即前向扩散过程)。
get_mult
< source >( h: Tensorr: Tensoralpha_prod_t: Tensoralpha_prod_t_prev: Tensoralpha_prod_t_back: typing.Optional[torch.Tensor] = None ) → tuple
计算前一个样本和预测的原始样本的乘数。
get_variables
< source >( alpha_prod_t: Tensoralpha_prod_t_prev: Tensoralpha_prod_t_back: typing.Optional[torch.Tensor] = None ) → tuple
参考原始实现,计算 DPM-Solver++ (2M) 所使用的变量。
get_velocity
< source >( sample: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor
根据速度公式,从样本和噪声计算速度预测。
scale_model_input
< source >( sample: Tensortimestep: int | None = None ) → torch.Tensor
确保与那些需要根据当前时间步对去噪模型输入进行缩放的调度器之间的可互换性。
set_timesteps
< source >( num_inference_steps: intdevice: typing.Union[str, torch.device, NoneType] = None )
设置扩散链所使用的离散时间步(需在推理之前运行)。
步骤
< source >( model_output: Tensorold_pred_original_sample: Tensortimestep: inttimestep_back: intsample: Tensoreta: float = 0.0use_clipped_model_output: bool = Falsegenerator: typing.Optional[torch.Generator] = Nonevariance_noise: typing.Optional[torch.Tensor] = Nonereturn_dict: bool = False ) → DDIMSchedulerOutput or tuple
参数
- model_output (
torch.Tensor) — 学习到的扩散模型的直接输出。 - old_pred_original_sample (
torch.Tensor) — 上一步时间步预测的原始样本。 - timestep (
int) — 扩散链中的当前离散时间步。 - timestep_back (
int) — 要回看的时间步。 - 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不起作用。 - generator (
torch.Generator,可选) — 随机数生成器。 - variance_noise (
torch.Tensor) — 直接提供方差本身的噪声,作为使用generator生成噪声的替代方案。适用于CycleDiffusion等方法。 - return_dict (
bool,可选,默认为True) — 是否返回 DDIMSchedulerOutput 或tuple。
返回值
DDIMSchedulerOutput 或 tuple
如果 return_dict 为 True,则返回 DDIMSchedulerOutput,否则返回一个元组,其中第一个元素是样本张量。
通过逆向 SDE 预测上一时间步的样本。此函数将扩散过程从学习到的模型输出(通常是预测的噪声)进行传播。