Diffusers 文件

LMS離散排程器

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

LMS離散排程器

LMSDiscreteScheduler 是用於離散 beta 排程器的線性多步排程器。該排程器由Katherine Crowson移植和建立,原始實現可在crowsonkb/k-diffusion找到。

LMSDiscreteScheduler

diffusers.LMSDiscreteScheduler

< >

( 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 use_karras_sigmas: typing.Optional[bool] = False use_exponential_sigmas: typing.Optional[bool] = False use_beta_sigmas: typing.Optional[bool] = False prediction_type: str = 'epsilon' 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_linear
  • trained_betas (np.ndarray, 可選) — 直接向建構函式傳遞一個 beta 陣列,以繞過 beta_startbeta_end
  • use_karras_sigmas (bool, 可選, 預設為 False) — 在取樣過程中,是否在噪聲排程中使用 Karras sigma 作為步長。如果為 True,sigma 將根據噪聲水平序列 {σi} 確定。
  • use_exponential_sigmas (bool, 可選, 預設為 False) — 在取樣過程中,是否在噪聲排程中使用指數 sigma 作為步長。
  • use_beta_sigmas (bool, 可選, 預設為 False) — 在取樣過程中,是否在噪聲排程中使用 beta sigma 作為步長。更多資訊請參閱Beta 取樣是你所需的一切
  • prediction_type (str, 預設為 epsilon, 可選) — 排程器函式的預測型別;可以是 epsilon (預測擴散過程的噪聲)、sample (直接預測噪聲樣本) 或 v_prediction (參見 Imagen Video 論文的 2.4 節)。
  • timestep_spacing (str, 預設為 "linspace") — 時間步長的縮放方式。更多資訊請參閱常見擴散噪聲排程和取樣步長存在缺陷的表 2。
  • steps_offset (int, 預設為 0) — 根據某些模型系列的要求,新增到推理步驟中的偏移量。

用於離散 beta 排程器的線性多步排程器。

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

get_lms_coefficient

< >

( order t current_order )

引數

  • order () —
  • t () —
  • current_order () —

計算線性多步係數。

縮放模型輸入

< >

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

引數

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

返回

torch.Tensor

一個縮放後的輸入樣本。

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

設定開始索引

< >

( begin_index: int = 0 )

引數

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

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

設定時間步

< >

( 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[float, torch.Tensor] sample: Tensor order: int = 4 return_dict: bool = True ) 排程器輸出tuple

引數

  • model_output (torch.Tensor) — 從學習到的擴散模型直接輸出。
  • timestep (floattorch.Tensor) — 擴散鏈中的當前離散時間步。
  • sample (torch.Tensor) — 擴散過程建立的樣本的當前例項。
  • order (int, 預設為 4) — 線性多步法的階數。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 SchedulerOutput 或元組。

返回

排程器輸出tuple

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

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

LMSDiscreteSchedulerOutput

diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteSchedulerOutput

< >

( 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.