Diffusers 文件
DEISMultistepScheduler
並獲得增強的文件體驗
開始使用
DEISMultistepScheduler
擴散指數積分器取樣器(DEIS)在 Qinsheng Zhang 和 Yongxin Chen 的《指數積分器快速取樣擴散模型》中提出。`DEISMultistepScheduler` 是一種用於擴散常微分方程(ODE)的快速高階求解器。
此實現修改了 log-rho 空間中的多項式擬合公式,而不是 DEIS 論文中原始的線性 `t` 空間。此修改適用於指數多步更新的封閉形式係數,而不是依賴於數值求解器。
論文摘要如下:
過去幾年,擴散模型(DMs)在生成高保真樣本的生成建模任務中取得了巨大成功。DM 的一個主要限制是其眾所周知的緩慢取樣過程,通常需要數百到數千個學習擴散過程的時間離散化步驟才能達到所需的精度。我們的目標是開發一種 DM 的快速取樣方法,在更少的步驟中保持高取樣質量。為此,我們系統地分析了 DM 中的取樣過程,並確定了影響取樣質量的關鍵因素,其中離散化方法最為關鍵。透過仔細檢查學習到的擴散過程,我們提出了擴散指數積分器取樣器(DEIS)。它基於為離散化常微分方程(ODE)設計的指數積分器,並利用學習到的擴散過程的半線性結構來減少離散化誤差。所提出的方法可以應用於任何 DM,並且可以在少至 10 步內生成高保真樣本。在我們的實驗中,在單個 A6000 GPU 上生成 CIFAR10 的 5 萬張影像大約需要 3 分鐘。此外,透過直接使用預訓練的 DM,當分數函式評估(NFE)數量有限時,我們實現了最先進的取樣效能,例如,在 CIFAR10 上,10 次 NFE 達到 4.17 FID,僅 15 次 NFE 達到 3.37 FID 和 9.74 IS。程式碼可在此處獲取:this https URL。
提示
建議將 `solver_order` 設定為 2 或 3,而 `solver_order=1` 等效於 DDIMScheduler。
支援來自 Imagen 的動態閾值,對於畫素空間擴散模型,您可以設定 `thresholding=True` 以使用動態閾值。
DEISMultistepScheduler
class diffusers.DEISMultistepScheduler
< 源 >( num_train_timesteps: int = 1000 beta_start: float = 0.0001 beta_end: float = 0.02 beta_schedule: str = 'linear' trained_betas: typing.Optional[numpy.ndarray] = None solver_order: int = 2 prediction_type: str = 'epsilon' thresholding: bool = False dynamic_thresholding_ratio: float = 0.995 sample_max_value: float = 1.0 algorithm_type: str = 'deis' solver_type: str = 'logrho' lower_order_final: bool = True use_karras_sigmas: typing.Optional[bool] = False use_exponential_sigmas: typing.Optional[bool] = False use_beta_sigmas: typing.Optional[bool] = False use_flow_sigmas: typing.Optional[bool] = False flow_shift: typing.Optional[float] = 1.0 timestep_spacing: str = 'linspace' steps_offset: int = 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
, 可選) — 直接向建構函式傳遞 beta 陣列,以繞過beta_start
和beta_end
。 - solver_order (
int
, 預設為 2) — DEIS 階數,可以是1
、2
或3
。建議在引導取樣中使用solver_order=2
,在無條件取樣中使用solver_order=3
。 - 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
時有效。 - algorithm_type (
str
, 預設為deis
) — 求解器的演算法型別。 - lower_order_final (
bool
, 預設為True
) — 是否在最後幾步使用低階求解器。僅對少於 15 步的推理有效。 - use_karras_sigmas (
bool
, 可選, 預設為False
) — 是否在取樣過程中使用 Karras sigmas 作為噪聲排程中的步長。如果為True
,sigmas 將根據噪聲級別序列 {σi} 確定。 - use_exponential_sigmas (
bool
, 可選, 預設為False
) — 是否在取樣過程中使用指數 sigmas 作為噪聲排程中的步長。 - use_beta_sigmas (
bool
, 可選, 預設為False
) — 是否在取樣過程中使用 beta sigmas 作為噪聲排程中的步長。有關更多資訊,請參閱 Beta Sampling is All You Need。 - timestep_spacing (
str
, 預設為"linspace"
) — 時間步的縮放方式。有關更多資訊,請參閱 Common Diffusion Noise Schedules and Sample Steps are Flawed 的表 2。 - steps_offset (
int
, 預設為 0) — 某些模型系列所需的推理步數偏移量。
DEISMultistepScheduler
是一種用於擴散常微分方程(ODE)的快速高階求解器。
此模型繼承自 SchedulerMixin 和 ConfigMixin。檢視超類文件以瞭解庫為所有排程器實現的通用方法,例如載入和儲存。
convert_model_output
< 源 >( model_output: Tensor *args sample: Tensor = None **kwargs ) → torch.Tensor
將模型輸出轉換為 DEIS 演算法所需的相應型別。
deis_first_order_update
< 源 >( model_output: Tensor *args sample: Tensor = None **kwargs ) → torch.Tensor
一階 DEIS 的一步(等同於 DDIM)。
multistep_deis_second_order_update
< 源 >( model_output_list: typing.List[torch.Tensor] *args sample: Tensor = None **kwargs ) → torch.Tensor
二階多步 DEIS 的一步。
multistep_deis_third_order_update
< 源 >( model_output_list: typing.List[torch.Tensor] *args sample: Tensor = None **kwargs ) → torch.Tensor
三階多步 DEIS 的一步。
scale_model_input
< 源 >( sample: Tensor *args **kwargs ) → torch.Tensor
確保與需要根據當前時間步縮放去噪模型輸入的排程器互換使用。
設定排程器的起始索引。此函式應在推理之前從管道中執行。
set_timesteps
< 源 >( num_inference_steps: int device: typing.Union[str, torch.device] = None )
設定用於擴散鏈的離散時間步(在推理之前執行)。
步驟
< 源 >( model_output: Tensor timestep: typing.Union[int, torch.Tensor] sample: Tensor return_dict: bool = True ) → SchedulerOutput 或 tuple
引數
- model_output (
torch.Tensor
) — 從學習到的擴散模型直接輸出。 - timestep (
int
) — 擴散鏈中的當前離散時間步長。 - sample (
torch.Tensor
) — 擴散過程建立的樣本的當前例項。 - return_dict (
bool
) — 是否返回 SchedulerOutput 或tuple
。
返回
排程器輸出 或 tuple
如果 return_dict 為 True
,則返回 SchedulerOutput,否則返回一個元組,其中第一個元素是樣本張量。
透過反轉 SDE 預測上一個時間步的樣本。此函式使用多步 DEIS 傳播樣本。
SchedulerOutput
class diffusers.schedulers.scheduling_utils.SchedulerOutput
< 源 >( prev_sample: Tensor )
排程器 step
函式輸出的基類。