Diffusers 文件

EDMEulerScheduler

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

EDMEulerScheduler

Karras 等人的論文《闡明基於擴散的生成模型的設計空間》中提出的 Euler 排程器(演算法 2)的 Karras 公式。這是一種快速排程器,通常可以在 20-30 步內生成良好的輸出。該排程器基於 Katherine Crowson 的原始 k-擴散 實現。

EDMEulerScheduler

class diffusers.EDMEulerScheduler

< >

( sigma_min: float = 0.002 sigma_max: float = 80.0 sigma_data: float = 0.5 sigma_schedule: str = 'karras' num_train_timesteps: int = 1000 prediction_type: str = 'epsilon' rho: float = 7.0 final_sigmas_type: str = 'zero' )

引數

  • sigma_min (float, 可選, 預設為 0.002) — sigma 排程中的最小噪聲幅度。在 EDM 論文 [1] 中設定為 0.002;合理範圍是 [0, 10]。
  • sigma_max (float, 可選, 預設為 80.0) — sigma 排程中的最大噪聲幅度。在 EDM 論文 [1] 中設定為 80.0;合理範圍是 [0.2, 80.0]。
  • sigma_data (float, 可選, 預設為 0.5) — 資料分佈的標準差。在 EDM 論文 [1] 中設定為 0.5。
  • sigma_schedule (str, 可選, 預設為 karras) — 用於計算 sigmas 的 Sigma 排程。預設情況下,我們使用 EDM 論文 (https://huggingface.co/papers/2206.00364) 中引入的排程。其他可接受的值是“exponential”。指數排程已在此模型中整合:https://huggingface.co/stabilityai/cosxl
  • num_train_timesteps (int, 預設為 1000) — 用於訓練模型的擴散步數。
  • prediction_type (str, 預設為 epsilon, 可選) — 排程函式中的預測型別;可以是 epsilon (預測擴散過程的噪聲)、sample (直接預測噪聲樣本) 或 v_prediction (參見 Imagen Video 論文的 2.4 節)。
  • rho (float, 可選, 預設為 7.0) — 用於計算 Karras sigma 排程的 rho 引數,在 EDM 論文 [1] 中設定為 7.0。
  • final_sigmas_type (str, 預設為 "zero") — 取樣過程中噪聲排程的最終 sigma 值。如果為 "sigma_min",則最終 sigma 與訓練排程中的最後一個 sigma 相同。如果為 zero,則最終 sigma 設定為 0。

實現了 Karras 等人於 2022 年 [1] 提出的 EDM 公式中的 Euler 排程器。

[1] Karras, Tero, et al. “闡明基於擴散的生成模型的設計空間。” https://huggingface.co/papers/2206.00364

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

scale_model_input

< >

( sample: Tensor timestep: typing.Union[float, torch.Tensor] ) torch.Tensor

引數

  • sample (torch.Tensor) — 輸入樣本。
  • timestep (int, 可選) — 擴散鏈中的當前時間步。

返回

torch.Tensor

一個縮放後的輸入樣本。

確保與需要根據當前時間步縮放去噪模型輸入的排程器可互換。透過 (sigma**2 + 1) ** 0.5 縮放去噪模型輸入以匹配尤拉演算法。

set_begin_index

< >

( begin_index: int = 0 )

引數

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

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

set_timesteps

< >

( num_inference_steps: int = None device: typing.Union[str, torch.device] = None sigmas: typing.Union[torch.Tensor, typing.List[float], NoneType] = None )

引數

  • num_inference_steps (int) — 使用預訓練模型生成樣本時使用的擴散步數。
  • device (strtorch.device, 可選) — 時間步應移動到的裝置。如果為 None,則時間步不移動。
  • sigmas (Union[torch.Tensor, List[float]], 可選) — 用於去噪過程的自定義 sigma 值。如果未定義,將使用傳入 num_inference_steps 時的預設行為。

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

步驟

< >

( model_output: Tensor timestep: typing.Union[float, torch.Tensor] sample: Tensor s_churn: float = 0.0 s_tmin: float = 0.0 s_tmax: float = inf s_noise: float = 1.0 generator: typing.Optional[torch._C.Generator] = None return_dict: bool = True pred_original_sample: typing.Optional[torch.Tensor] = None ) ~schedulers.scheduling_euler_discrete.EDMEulerSchedulerOutputtuple

引數

  • model_output (torch.Tensor) — 從學習型擴散模型直接輸出。
  • timestep (float) — 擴散鏈中的當前離散時間步。
  • sample (torch.Tensor) — 由擴散過程建立的樣本的當前例項。
  • s_churn (float) —
  • s_tmin (float) —
  • s_tmax (float) —
  • s_noise (float, 預設為 1.0) — 新增到樣本中的噪聲的縮放因子。
  • generator (torch.Generator, 可選) — 隨機數生成器。
  • return_dict (bool) — 是否返回 ~schedulers.scheduling_euler_discrete.EDMEulerSchedulerOutput 或元組。

返回

~schedulers.scheduling_euler_discrete.EDMEulerSchedulerOutputtuple

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

透過逆轉 SDE 預測前一個時間步的樣本。此函式從學習到的模型輸出(通常是預測的噪聲)傳播擴散過程。

EDMEulerSchedulerOutput

class diffusers.schedulers.scheduling_edm_euler.EDMEulerSchedulerOutput

< >

( prev_sample: Tensor pred_original_sample: typing.Optional[torch.Tensor] = None )

引數

  • prev_sample (torch.Tensor, 形狀為影像的 (batch_size, num_channels, height, width)) — 上一時間步計算出的樣本 (x_{t-1})prev_sample 應用作去噪迴圈中的下一個模型輸入。
  • pred_original_sample (torch.Tensor, 形狀為影像的 (batch_size, num_channels, height, width)) — 基於當前時間步的模型輸出預測的去噪樣本 (x_{0})pred_original_sample 可用於預覽進度或進行指導。

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

< > 在 GitHub 上更新

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