Diffusers 文件

DEISMultistepScheduler

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

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 序列的對映。可選擇 linearscaled_linearsquaredcos_cap_v2
  • trained_betas (np.ndarray, 可選) — 直接向建構函式傳遞 beta 陣列,以繞過 beta_startbeta_end
  • solver_order (int, 預設為 2) — DEIS 階數,可以是 123。建議在引導取樣中使用 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)的快速高階求解器。

此模型繼承自 SchedulerMixinConfigMixin。檢視超類文件以瞭解庫為所有排程器實現的通用方法,例如載入和儲存。

convert_model_output

< >

( model_output: Tensor *args sample: Tensor = None **kwargs ) torch.Tensor

引數

  • model_output (torch.Tensor) — 從學習到的擴散模型直接輸出。
  • timestep (int) — 擴散鏈中當前的離散時間步。
  • sample (torch.Tensor) — 擴散過程建立的樣本的當前例項。

返回

torch.Tensor

轉換後的模型輸出。

將模型輸出轉換為 DEIS 演算法所需的相應型別。

deis_first_order_update

< >

( model_output: Tensor *args sample: Tensor = None **kwargs ) torch.Tensor

引數

  • model_output (torch.Tensor) — 從學習到的擴散模型直接輸出。
  • timestep (int) — 擴散鏈中當前的離散時間步。
  • prev_timestep (int) — 擴散鏈中上一個離散時間步。
  • sample (torch.Tensor) — 擴散過程建立的樣本的當前例項。

返回

torch.Tensor

上一個時間步的樣本張量。

一階 DEIS 的一步(等同於 DDIM)。

multistep_deis_second_order_update

< >

( model_output_list: typing.List[torch.Tensor] *args sample: Tensor = None **kwargs ) torch.Tensor

引數

  • model_output_list (List[torch.Tensor]) — 從學習到的擴散模型在當前和後續時間步的直接輸出。
  • sample (torch.Tensor) — 擴散過程建立的樣本的當前例項。

返回

torch.Tensor

上一個時間步的樣本張量。

二階多步 DEIS 的一步。

multistep_deis_third_order_update

< >

( model_output_list: typing.List[torch.Tensor] *args sample: Tensor = None **kwargs ) torch.Tensor

引數

  • model_output_list (List[torch.Tensor]) — 從學習到的擴散模型在當前和後續時間步的直接輸出。
  • sample (torch.Tensor) — 擴散過程建立的樣本的當前例項。

返回

torch.Tensor

上一個時間步的樣本張量。

三階多步 DEIS 的一步。

scale_model_input

< >

( sample: Tensor *args **kwargs ) torch.Tensor

引數

  • sample (torch.Tensor) — 輸入樣本。

返回

torch.Tensor

一個縮放後的輸入樣本。

確保與需要根據當前時間步縮放去噪模型輸入的排程器互換使用。

set_begin_index

< >

( begin_index: int = 0 )

引數

  • begin_index (int) — 排程器的起始索引。

設定排程器的起始索引。此函式應在推理之前從管道中執行。

set_timesteps

< >

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

引數

  • num_inference_steps (int) — 使用預訓練模型生成樣本時使用的擴散步數。
  • device (strtorch.device, 可選) — 步長應移動到的裝置。如果為 None,則步長不移動。

設定用於擴散鏈的離散時間步(在推理之前執行)。

步驟

< >

( model_output: Tensor timestep: typing.Union[int, torch.Tensor] sample: Tensor return_dict: bool = True ) SchedulerOutputtuple

引數

  • model_output (torch.Tensor) — 從學習到的擴散模型直接輸出。
  • timestep (int) — 擴散鏈中的當前離散時間步長。
  • sample (torch.Tensor) — 擴散過程建立的樣本的當前例項。
  • return_dict (bool) — 是否返回 SchedulerOutputtuple

返回

排程器輸出tuple

如果 return_dict 為 True,則返回 SchedulerOutput,否則返回一個元組,其中第一個元素是樣本張量。

透過反轉 SDE 預測上一個時間步的樣本。此函式使用多步 DEIS 傳播樣本。

SchedulerOutput

class diffusers.schedulers.scheduling_utils.SchedulerOutput

< >

( prev_sample: Tensor )

引數

  • prev_sample (torch.Tensor,影像的形狀為 (batch_size, num_channels, height, width)) — 計算出的上一個時間步的樣本 (x_{t-1})prev_sample 應作為去噪迴圈中的下一個模型輸入。

排程器 step 函式輸出的基類。

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.