Diffusers documentation
DDPMScheduler
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
< source >( 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 beepsilon(predicts the noise of the diffusion process),sample(directly predicts the noisy sample) orv_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
< source >( original_samples: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor
各タイムステップにおけるノイズの大きさに従って、元のサンプルにノイズを追加します(これはフォワード拡散プロセスです)。
get_velocity
< source >( sample: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor
速度の式に従って、サンプルとノイズから速度予測を計算します。
previous_timestep
< source >( timestep: int ) → int or torch.Tensor
拡散チェーンにおける直前のタイムステップを計算します。
scale_model_input
< source >( sample: Tensortimestep: int | None = None ) → torch.Tensor
現在のタイムステップに応じて、デノイジングモデルの入力をスケーリングする必要があるスケジューラーとの相互運用性を保証します。
set_timesteps
< source >( 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でなければなりません。
拡散チェーンで使用される離散タイムステップを設定します(推論の実行前に実行する必要があります)。
ステップ
< source >( 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
< source >( 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関数の出力用のクラス。