Diffusers 文件

Heun離散排程器

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

HeunDiscreteScheduler

Heun 排程器(演算法 1)來自 Karras 等人的 Elucidating the Design Space of Diffusion-Based Generative Models 論文。該排程器移植自 k-diffusion 庫,由 Katherine Crowson 建立。

HeunDiscreteScheduler

class diffusers.HeunDiscreteScheduler

< >

( num_train_timesteps: int = 1000 beta_start: float = 0.00085 beta_end: float = 0.012 beta_schedule: str = 'linear' trained_betas: typing.Union[numpy.ndarray, typing.List[float], NoneType] = None prediction_type: str = 'epsilon' use_karras_sigmas: typing.Optional[bool] = False use_exponential_sigmas: typing.Optional[bool] = False use_beta_sigmas: typing.Optional[bool] = False clip_sample: typing.Optional[bool] = False clip_sample_range: 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_linear
  • trained_betas (np.ndarray, 可選) — 直接將 beta 陣列傳遞給建構函式以繞過 beta_startbeta_end
  • prediction_type (str, 預設為 epsilon, 可選) — 排程函式預測型別;可以是 epsilon (預測擴散過程的噪聲), sample (直接預測噪聲樣本) 或 v_prediction (參見 Imagen Video 論文的 2.4 節)。
  • clip_sample (bool, 預設為 True) — 為數值穩定性裁剪預測樣本。
  • clip_sample_range (float, 預設為 1.0) — 樣本裁剪的最大幅度。僅當 clip_sample=True 時有效。
  • 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) — 新增到推理步數的偏移量,某些模型系列需要。

帶有 Heun 步的離散 beta 排程器。

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

scale_model_input

< >

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

引數

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

返回

torch.Tensor

一個縮放後的輸入樣本。

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

set_begin_index

< >

( begin_index: int = 0 )

引數

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

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

set_timesteps

< >

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

引數

  • num_inference_steps (int) — 使用預訓練模型生成樣本時使用的擴散步數。
  • device (strtorch.device, 可選) — 時間步長應移動到的裝置。如果為 None,時間步長不會移動。
  • num_train_timesteps (int, 可選) — 訓練模型時使用的擴散步數。如果為 None,則使用預設的 num_train_timesteps 屬性。
  • timesteps (List[int], 可選) — 用於支援時間步長之間任意間距的自定義時間步長。如果為 None,則時間步長將根據 timestep_spacing 屬性生成。如果傳遞 timesteps,則 num_inference_steps 必須為 None,並且將忽略 timestep_spacing 屬性。

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

步驟

< >

( model_output: typing.Union[torch.Tensor, numpy.ndarray] timestep: typing.Union[float, torch.Tensor] sample: typing.Union[torch.Tensor, numpy.ndarray] return_dict: bool = True ) HeunDiscreteSchedulerOutputtuple

引數

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

返回

HeunDiscreteSchedulerOutputtuple

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

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

SchedulerOutput

class diffusers.schedulers.scheduling_utils.SchedulerOutput

< >

( prev_sample: 張量 )

引數

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