Diffusers 文件
DDPMScheduler
並獲得增強的文件體驗
開始使用
DDPMScheduler
去噪擴散機率模型 (Denoising Diffusion Probabilistic Models)(DDPM),由 Jonathan Ho、Ajay Jain 和 Pieter Abbeel 提出,提出了一種同名擴散模型。在 🤗 Diffusers 庫中,DDPM 指的是論文中的離散去噪排程器和管道。
論文摘要如下:
我們使用擴散機率模型呈現高質量的影像合成結果,這是一種受非平衡熱力學考慮啟發的潛在變數模型。我們透過在加權變分界上進行訓練獲得最佳結果,該變分界根據擴散機率模型與 Langevin 動力學去噪分數匹配之間的新穎連線進行設計,並且我們的模型自然地允許漸進式有損解壓縮方案,這可以解釋為自迴歸解碼的推廣。在無條件 CIFAR10 資料集上,我們獲得了 9.46 的 Inception 分數和 3.17 的最先進 FID 分數。在 256x256 LSUN 上,我們獲得了與 ProgressiveGAN 相似的樣本質量。我們的實現可在 this https URL 獲得。
DDPMScheduler
class diffusers.DDPMScheduler
< 來源 >( 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 variance_type: str = 'fixed_small' clip_sample: bool = True prediction_type: str = 'epsilon' thresholding: bool = False dynamic_thresholding_ratio: float = 0.995 clip_sample_range: float = 1.0 sample_max_value: float = 1.0 timestep_spacing: str = 'leading' steps_offset: int = 0 rescale_betas_zero_snr: bool = False )
引數
- 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
或sigmoid
。 - trained_betas (
np.ndarray
, 可選) — 直接傳遞給建構函式而不使用beta_start
和beta_end
的 beta 陣列。 - variance_type (
str
, 預設為"fixed_small"
) — 在向去噪樣本新增噪聲時剪下方差。可選擇fixed_small
、fixed_small_log
、fixed_large
、fixed_large_log
、learned
或learned_range
。 - clip_sample (
bool
, 預設為True
) — 剪下預測樣本以實現數值穩定性。 - clip_sample_range (
float
, 預設為 1.0) — 樣本剪下的最大幅度。僅當clip_sample=True
時有效。 - prediction_type (
str
, 預設為epsilon
, 可選) — 排程器功能的預測型別;可以是epsilon
(預測擴散過程的噪聲)、sample
(直接預測噪聲樣本)或v_prediction
(參見 Imagen Video 論文的 2.4 節)。 - thresholding (
bool
, 預設為False
) — 是否使用“動態閾值”方法。這不適用於 Stable Diffusion 等潛在空間擴散模型。 - dynamic_thresholding_ratio (
float
, 預設為 0.995) — 動態閾值方法的比率。僅當thresholding=True
時有效。 - sample_max_value (
float
, 預設為 1.0) — 動態閾值的閾值。僅當thresholding=True
時有效。 - timestep_spacing (
str
, 預設為"leading"
) — 時間步長的縮放方式。更多資訊請參閱 Common Diffusion Noise Schedules and Sample Steps are Flawed 的表 2。 - steps_offset (
int
, 預設為 0) — 新增到推理步驟的偏移量,某些模型系列需要此偏移量。 - rescale_betas_zero_snr (
bool
, 預設為False
) — 是否重新調整 beta 值以獲得零終端信噪比 (SNR)。這使得模型能夠生成非常明亮和黑暗的樣本,而不是將其限制為中等亮度的樣本。與--offset_noise
鬆散相關。
DDPMScheduler
探討了去噪分數匹配和 Langevin 動力學取樣之間的聯絡。
該模型繼承自 SchedulerMixin 和 ConfigMixin。有關庫為所有排程器(例如載入和儲存)實現的一般方法,請檢視超類文件。
scale_model_input
< 來源 >( sample: Tensor timestep: typing.Optional[int] = None ) → torch.Tensor
確保與需要根據當前時間步縮放去噪模型輸入的排程器互換使用。
set_timesteps
< 來源 >( num_inference_steps: typing.Optional[int] = None device: typing.Union[str, torch.device] = None timesteps: typing.Optional[typing.List[int]] = None )
設定用於擴散鏈的離散時間步(在推理之前執行)。
步驟
< 來源 >( model_output: Tensor timestep: int sample: Tensor generator = None return_dict: bool = True ) → DDPMSchedulerOutput 或 tuple
引數
- model_output (
torch.Tensor
) — 從學習到的擴散模型直接輸出。 - timestep (
float
) — 擴散鏈中的當前離散時間步。 - sample (
torch.Tensor
) — 擴散過程建立的樣本當前例項。 - generator (
torch.Generator
, 可選) — 隨機數生成器。 - return_dict (
bool
, 可選, 預設為True
) — 是否返回 DDPMSchedulerOutput 或tuple
。
返回
DDPMSchedulerOutput 或 tuple
如果 `return_dict` 為 `True`,則返回 DDPMSchedulerOutput,否則返回一個元組,其中第一個元素是樣本張量。
透過逆轉 SDE 預測前一個時間步的樣本。此函式從學習到的模型輸出(通常是預測的噪聲)傳播擴散過程。
DDPMSchedulerOutput
class diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput
< 來源 >( prev_sample: Tensor pred_original_sample: typing.Optional[torch.Tensor] = None )
排程器 step
函式輸出的輸出類。