Diffusers 文件
ScoreSdeVeScheduler
並獲得增強的文件體驗
開始使用
ScoreSdeVeScheduler
ScoreSdeVeScheduler
是一個方差爆炸隨機微分方程 (SDE) 排程器。它由 Yang Song、Jascha Sohl-Dickstein、Diederik P. Kingma、Abhishek Kumar、Stefano Ermon、Ben Poole 在論文 Score-Based Generative Modeling through Stochastic Differential Equations 中提出。
論文摘要如下:
從資料生成噪聲很容易;從噪聲生成資料是生成建模。我們提出了一種隨機微分方程(SDE),它透過緩慢注入噪聲將複雜資料分佈平滑地轉換為已知先驗分佈,以及一個相應的反向 SDE,它透過緩慢去除噪聲將先驗分佈轉換回資料分佈。關鍵是,反向 SDE 僅取決於擾動資料分佈的時間相關梯度場(即分數)。透過利用基於分數的生成建模的進展,我們可以使用神經網路準確估計這些分數,並使用數值 SDE 求解器生成樣本。我們表明,這個框架包含了以前基於分數的生成建模和擴散機率建模的方法,允許新的取樣過程和新的建模能力。特別是,我們引入了一個預測器-校正器框架來糾正離散反向 SDE 演化中的錯誤。我們還推匯出了一個等價的神經 ODE,它從與 SDE 相同的分佈中取樣,但此外還支援精確的似然計算和改進的取樣效率。此外,我們提供了一種使用基於分數模型解決逆問題的新方法,正如類條件生成、影像修復和著色實驗所證明的那樣。結合多項架構改進,我們在 CIFAR-10 上實現了無條件影像生成的破紀錄效能,Inception 分數為 9.89,FID 為 2.20,有競爭力的似然為 2.99 bits/dim,並首次從基於分數的生成模型中展示了 1024 x 1024 影像的高保真生成。
ScoreSdeVeScheduler
class diffusers.ScoreSdeVeScheduler
< 來源 >( num_train_timesteps: int = 2000 snr: float = 0.15 sigma_min: float = 0.01 sigma_max: float = 1348.0 sampling_eps: float = 1e-05 correct_steps: int = 1 )
引數
- num_train_timesteps (
int
, 預設為 1000) — 用於訓練模型的擴散步數。 - snr (
float
, 預設為 0.15) — 一個係數,用於加權從model_output
樣本(來自網路)到隨機噪聲的步長。 - sigma_min (
float
, 預設為 0.01) — 取樣過程中 sigma 序列的初始噪聲尺度。最小 sigma 應反映資料的分佈。 - sigma_max (
float
, 預設為 1348.0) — 傳遞給模型的連續時間步長範圍的最大值。 - sampling_eps (
float
, 預設為 1e-5) — 取樣結束值,其中時間步長從 1 逐漸減小到 epsilon。 - correct_steps (
int
, 預設為 1) — 對生成的樣本執行的校正步數。
ScoreSdeVeScheduler
是一個方差爆炸隨機微分方程 (SDE) 排程器。
此模型繼承自 SchedulerMixin 和 ConfigMixin。有關庫為所有排程器實現的通用方法(如載入和儲存),請參閱超類文件。
scale_model_input
< 源 >( sample: Tensor timestep: typing.Optional[int] = None ) → torch.Tensor
確保與需要根據當前時間步縮放去噪模型輸入的排程器互換使用。
set_sigmas
< 源 >( num_inference_steps: int sigma_min: float = None sigma_max: float = None sampling_eps: float = None )
設定擴散鏈使用的噪聲尺度(在推理之前執行)。sigma 控制樣本更新的 drift
和 diffusion
分量的權重。
set_timesteps
< 源 >( num_inference_steps: int sampling_eps: float = None device: typing.Union[str, torch.device] = None )
設定擴散鏈使用的連續時間步(在推理之前執行)。
step_correct
< 源 >( model_output: Tensor sample: Tensor generator: typing.Optional[torch._C.Generator] = None return_dict: bool = True ) → SdeVeOutput 或 tuple
引數
- model_output (
torch.Tensor
) — 從學習到的擴散模型直接輸出。 - sample (
torch.Tensor
) — 擴散過程建立的樣本的當前例項。 - generator (
torch.Generator
, 可選) — 隨機數生成器。 - return_dict (
bool
, 可選, 預設為True
) — 是否返回 SdeVeOutput 或tuple
。
返回
SdeVeOutput 或 tuple
如果 return_dict 為 True
,則返回 SdeVeOutput,否則返回一個元組,其中第一個元素是樣本張量。
根據網路的 model_output
校正預測樣本。這通常在對前一個時間步進行預測後重復執行。
step_pred
< 源 >( model_output: Tensor timestep: int sample: Tensor generator: typing.Optional[torch._C.Generator] = None return_dict: bool = True ) → SdeVeOutput 或 tuple
引數
- model_output (
torch.Tensor
) — 從學習到的擴散模型直接輸出。 - timestep (
int
) — 擴散鏈中的當前離散時間步。 - sample (
torch.Tensor
) — 擴散過程建立的樣本的當前例項。 - generator (
torch.Generator
, 可選) — 隨機數生成器。 - return_dict (
bool
, 可選, 預設為True
) — 是否返回 SdeVeOutput 或tuple
。
返回
SdeVeOutput 或 tuple
如果 return_dict 為 True
,則返回 SdeVeOutput,否則返回一個元組,其中第一個元素是樣本張量。
透過逆轉 SDE 預測前一個時間步的樣本。此函式從學習到的模型輸出(通常是預測的噪聲)傳播擴散過程。
SdeVeOutput
class diffusers.schedulers.scheduling_sde_ve.SdeVeOutput
< source >( prev_sample: Tensor prev_sample_mean: Tensor )
排程器 step
函式輸出的輸出類。