Diffusers 文件

潛在一致性模型多步排程器

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

潛在一致性模型多步排程器

概覽

多步和單步排程器(演算法 3),與潛在一致性模型一同在 Simian Luo、Yiqin Tan、Longbo Huang、Jian Li 和 Hang Zhao 的論文 潛在一致性模型:透過少量步驟推理合成高解析度影像 中提出。此排程器應該能夠在 1-8 步內從 LatentConsistencyModelPipeline 生成良好的樣本。

LCMScheduler

class diffusers.LCMScheduler

< >

( num_train_timesteps: int = 1000 beta_start: float = 0.00085 beta_end: float = 0.012 beta_schedule: str = 'scaled_linear' trained_betas: typing.Union[numpy.ndarray, typing.List[float], NoneType] = None original_inference_steps: int = 50 clip_sample: bool = False clip_sample_range: float = 1.0 set_alpha_to_one: bool = True steps_offset: int = 0 prediction_type: str = 'epsilon' thresholding: bool = False dynamic_thresholding_ratio: float = 0.995 sample_max_value: float = 1.0 timestep_spacing: str = 'leading' timestep_scaling: float = 10.0 rescale_betas_zero_snr: bool = False )

引數

  • 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
  • original_inference_steps (int, 可選, 預設為 50) — 用於生成線性間隔時間步排程器的預設推理步數,最終將從該排程器中均勻間隔地取 num_inference_steps 個時間步,以形成最終的時間步排程器。
  • clip_sample (bool, 預設為 True) — 剪輯預測樣本以確保數值穩定性。
  • clip_sample_range (float, 預設為 1.0) — 樣本剪輯的最大幅度。僅在 clip_sample=True 時有效。
  • set_alpha_to_one (bool, 預設為 True) — 每個擴散步驟都使用該步驟和前一步的 alphas 乘積值。對於最後一步,沒有前一個 alpha。當此選項為 True 時,前一個 alpha 乘積固定為 1,否則它使用步驟 0 的 alpha 值。
  • steps_offset (int, 預設為 0) — 新增到推理步驟的偏移量,某些模型家族需要此偏移量。
  • 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 時有效。
  • timestep_spacing (str, 預設為 "leading") — 時間步的縮放方式。更多資訊請參閱 常用擴散噪聲排程器和樣本步驟存在缺陷 的表 2。
  • timestep_scaling (float, 預設為 10.0) — 計算一致性模型邊界條件 c_skipc_out 時,時間步將被乘以的因子。增加此值將減小近似誤差(儘管預設值 10.0 時的近似誤差已經很小)。
  • rescale_betas_zero_snr (bool, 預設為 False) — 是否重新縮放 beta 值以使其具有零終端信噪比 (SNR)。這使得模型能夠生成非常明亮和黑暗的樣本,而不是將其限制在亮度適中的樣本。與 --offset_noise 有鬆散的關係。

LCMScheduler 擴充套件了去噪擴散機率模型 (DDPM) 中引入的去噪過程,並增加了非馬爾可夫引導。

此模型繼承自 SchedulerMixinConfigMixin~ConfigMixin 負責儲存排程器 __init__ 函式中傳遞的所有配置屬性,例如 num_train_timesteps。可以透過 scheduler.config.num_train_timesteps 訪問它們。SchedulerMixin 透過 SchedulerMixin.save_pretrained()from_pretrained() 函式提供通用的載入和儲存功能。

scale_model_input

< >

( sample: Tensor timestep: typing.Optional[int] = None ) 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 original_inference_steps: typing.Optional[int] = None timesteps: typing.Optional[typing.List[int]] = None strength: int = 1.0 )

引數

  • num_inference_steps (int, 可選) — 使用預訓練模型生成樣本時使用的擴散步數。如果使用此引數,則 timesteps 必須為 None
  • device (strtorch.device, 可選) — 時間步應移動到的裝置。如果為 None,則時間步不移動。
  • original_inference_steps (int, 可選) — 原始推理步數,將用於生成線性間隔的時間步排程器(這與標準 diffusers 實現不同)。然後,我們將從該排程器中均勻間隔地取 num_inference_steps 個時間步,並將其用作最終的時間步排程器。如果未設定,則預設為 original_inference_steps 屬性。
  • timesteps (List[int], 可選) — 用於支援時間步之間任意間隔的自定義時間步。如果為 None,則使用訓練/蒸餾時間步排程器上時間步之間等距的預設時間步間隔策略。如果傳遞了 timesteps,則 num_inference_steps 必須為 None

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

步驟

< >

( model_output: Tensor timestep: int sample: Tensor generator: typing.Optional[torch._C.Generator] = None return_dict: bool = True ) ~schedulers.scheduling_utils.LCMSchedulerOutputtuple

引數

  • model_output (torch.Tensor) — 從學習到的擴散模型直接輸出。
  • timestep (float) — 擴散鏈中的當前離散時間步。
  • sample (torch.Tensor) — 擴散過程建立的樣本的當前例項。
  • generator (torch.Generator, 可選) — 隨機數生成器。
  • return_dict (bool, 可選, 預設為 True) — 是否返回 LCMSchedulerOutputtuple

返回

~schedulers.scheduling_utils.LCMSchedulerOutputtuple

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

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

< > 在 GitHub 上更新

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