Diffusers documentation

DDPMScheduler

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

DDPMScheduler

Jonathan Ho、Ajay Jain、Pieter Abbeel による Denoising Diffusion Probabilistic Models(DDPM)は、同名の拡散ベースのモデルを提案しています。🤗 Diffusers ライブラリの文脈では、DDPM は論文に記述された離散型ノイズ除去スケジューラおよびパイプラインを指します。

論文の抄録は以下の通りです:

非平衡熱力学の考察に着想を得た潜在変数モデルの一種である拡散確率モデルを用いた、高品質な画像合成の結果を提示します。私たちの最良の結果は、拡散確率モデルと Langevin 動力学を用いた去噪スコアマッチングとの新たな関連性に基づいて設計された重み付き変分境界で訓練することで得られ、私たちのモデルは、自己回帰デコーディングの一般化と解釈できる漸進的有圧縮スキームを自然に許容します。無条件 CIFAR10 データセットでは、Inception スコア 9.46 と、最先端の FID スコア 3.17 を達成しました。256x256 LSUN では、ProgressiveGAN と同様のサンプル品質を得ました。実装は この https URL で利用可能です。

DDPMScheduler

class diffusers.DDPMScheduler

< >

( num_train_timesteps: int = 1000beta_start: float = 0.0001beta_end: float = 0.02beta_schedule: typing.Literal['linear', 'scaled_linear', 'squaredcos_cap_v2', 'sigmoid'] = 'linear'trained_betas: numpy.ndarray | list[float] | None = Nonevariance_type: typing.Literal['fixed_small', 'fixed_small_log', 'fixed_large', 'fixed_large_log', 'learned', 'learned_range'] = 'fixed_small'clip_sample: bool = Trueprediction_type: typing.Literal['epsilon', 'sample', 'v_prediction'] = 'epsilon'thresholding: bool = Falsedynamic_thresholding_ratio: float = 0.995clip_sample_range: float = 1.0sample_max_value: float = 1.0timestep_spacing: typing.Literal['linspace', 'leading', 'trailing'] = 'leading'steps_offset: int = 0rescale_betas_zero_snr: bool = False )

パラメータ

  • num_train_timesteps (int、デフォルトは 1000) — モデルを学習するための拡散ステップ数。
  • beta_start (float、デフォルトは 0.0001) — 推論の初期 beta 値です。
  • beta_end (float、デフォルト値は0.02) — 最終的なbeta値です。
  • beta_schedule("linear"、"scaled_linear"、"squaredcos_cap_v2"、または "sigmoid"。デフォルトは "linear")— ベータスケジュールです。ベータの範囲を、モデルをステップするためのベータの列にマッピングします。
  • trained_betas (np.ndarray, 省略可) — beta_start と beta_end を使用せずに、コンストラクタに直接渡すベータの配列です。
  • variance_type("fixed_small"、"fixed_small_log"、"fixed_large"、"fixed_large_log"、"learned"、または "learned_range"。デフォルトは "fixed_small")— ノイズをデノイズされたサンプルに追加する際に、分散をクリップします。
  • clip_sample (bool、デフォルトは True) — 数値の安定性を確保するために、予測されたサンプルをクリップします。
  • clip_sample_range (float, デフォルトは 1.0) — サンプルクリッピングの最大振幅です。clip_sample=True の場合のみ有効です。
  • prediction_type ("epsilon", "sample", or "v_prediction", defaults to "epsilon") — Prediction type of the scheduler function; can be epsilon (predicts the noise of the diffusion process), sample (directly predicts the noisy sample) or v_prediction` (see section 2.4 of Imagen Video paper).
  • thresholding (bool、デフォルトは False) — 「動的閾値処理」メソッドを使用するかどうか。Stable Diffusion などの潜在空間拡散モデルには不向きです。
  • dynamic_thresholding_ratio (float、デフォルトは0.995) — 動的閾値化手法の比率。thresholding=Trueの場合にのみ有効です。
  • sample_max_value (float, デフォルトは 1.0) — 動的閾値処理の閾値です。thresholding=True の場合のみ有効です。
  • timestep_spacing ("linspace", "leading", or "trailing", defaults to "leading") — The way the timesteps should be scaled. Refer to Table 2 of the Common Diffusion Noise Schedules and Sample Steps are Flawed for more information.
  • steps_offset (int、デフォルトは 0) — 一部のモデルファミリーで必要とされる、推論ステップに追加されるオフセットです。
  • rescale_betas_zero_snr (bool、デフォルトは False) — betas を再スケーリングして、終端 SNR をゼロにするかどうかを指定します。これにより、モデルは中間の明るさに限定されず、非常に明るく暗いサンプルを生成できるようになります。--offset_noise とゆるく関連しています。

DDPMScheduler は、デノイジング・スコア・マッチングとランジュバン力学サンプリングの間の関連性を検討します。

このモデルは SchedulerMixin および ConfigMixin を継承しています。読み込みや保存など、ライブラリがすべてのスケジューラに対して実装している汎用的なメソッドについては、スーパークラスのドキュメントを参照してください。

add_noise

< >

( original_samples: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor

パラメータ

  • original_samples (torch.Tensor) — ノイズが加えられる元のサンプルです。
  • noise (torch.Tensor) — サンプルに追加するノイズ。
  • timesteps (torch.IntTensor) — 各サンプルのノイズレベルを示すタイムステップです。

戻り値

torch.Tensor

ノイズ付きサンプル。

各タイムステップにおけるノイズの大きさに従って、元のサンプルにノイズを追加します(これはフォワード拡散プロセスです)。

get_velocity

< >

( sample: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor

パラメータ

  • sample (torch.Tensor) — 入力サンプルです。
  • noise (torch.Tensor) — ノイズテンソルです。
  • timesteps (torch.IntTensor) — 速度計算に使用するタイムステップです。

戻り値

torch.Tensor

計算された速度。

速度の式に従って、サンプルとノイズから速度予測を計算します。

previous_timestep

< >

( timestep: int ) → int or torch.Tensor

パラメータ

  • timestep (int) — 現在のタイムステップ。

戻り値

int または torch.Tensor

直前のタイムステップ。

拡散チェーンにおける直前のタイムステップを計算します。

scale_model_input

< >

( sample: Tensortimestep: int | None = None ) → torch.Tensor

パラメータ

  • sample (torch.Tensor) — 入力サンプルです。
  • timestep (int, 任意) — 拡散チェーンにおける現在のタイムステップ。

戻り値

torch.Tensor

スケーリングされた入力サンプル。

現在のタイムステップに応じて、デノイジングモデルの入力をスケーリングする必要があるスケジューラーとの相互運用性を保証します。

set_timesteps

< >

( num_inference_steps: int = Nonedevice: typing.Union[str, torch.device] = Nonetimesteps: list[int] | None = None )

パラメータ

  • num_inference_steps (int, 省略可) — 事前学習済みモデルでサンプルを生成する際に使用する拡散ステップ数。使用する場合、timesteps は None である必要があります。
  • device (str または torch.device、省略可) — timesteps を移動先とするデバイスです。None の場合、timesteps は移動されません。
  • timesteps (list[int]、任意) — timesteps 間の任意の間隔をサポートするために使用されるカスタムな timesteps。None の場合、timesteps 間の等間隔というデフォルトの timesteps 間隔戦略が使用されます。timesteps が渡された場合、num_inference_steps は None でなければなりません。

拡散チェーンで使用される離散タイムステップを設定します(推論の実行前に実行する必要があります)。

ステップ

< >

( model_output: Tensortimestep: intsample: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = True ) → DDPMSchedulerOutput or tuple

パラメータ

  • model_output (torch.Tensor) — 学習済み拡散モデルからの直接の出力です。
  • timestep (int) — 拡散チェーンにおける現在の離散タイムステップ。
  • sample (torch.Tensor) — 拡散プロセスによって生成されたサンプルの現在のインスタンス。
  • generator (torch.Generator、任意) — 乱数生成器です。
  • return_dict (bool、デフォルトは True) — DDPMSchedulerOutput を返すか、tuple を返すかを指定します。

戻り値

DDPMSchedulerOutput または tuple

True の場合、DDPMSchedulerOutput が返され、それ以外の場合は、最初の要素がサンプルテンソルであるタプルが返されます。

前のタイムステップのサンプルを、SDEを逆方向に適用することで予測します。この関数は、学習済みモデルの出力(多くの場合、予測されたノイズ)から拡散過程を伝播させます。

DDPMSchedulerOutput

class diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput

< >

( prev_sample: Tensorpred_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関数の出力用のクラス。

Update on GitHub