Diffusers documentation

DiscreteDDIMScheduler

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

DiscreteDDIMScheduler

DiscreteDDIMScheduler は、Structured Denoising Diffusion Models in Discrete State-Spaces に従い、均一な破損プロセス(D3PM)の厳密な離散事後分布から各キャンバスの位置をサンプリングします。パラメータを必要とせず、最終ステップでは予測されたトークンを決定論的に確定します。任意の predictor-corrector モードでは、corrector_steps を通じて、Uniform Diffusion Models Revisited: Leave-One-Out Denoiser and Absorbing State Reformulation の leave-one-out Gibbs スイープが追加されます。

このスケジューラは、DiffusionGemmaPipelineで使用されます。

DiscreteDDIMScheduler

class diffusers.DiscreteDDIMScheduler

< >

( num_inference_steps: int = 32corrector_steps: int = 0corrector_k: int = 1corrector_selection: str = 'lowest_log_margin'corrector_selection_tau: float = 1.0 )

パラメータ

  • num_inference_steps (int、デフォルト値は 32) — デノイジングのステップ数です。ポスターior が評価される線形時間グリッドを定義します。
  • corrector_steps (int、デフォルト値は 0)— 各 predictor ステップの後に実行する Gibbs corrector スイープの回数です。0 を指定すると、通常の ancestral DDIM サンプリングが復元されます。
  • corrector_k (int、デフォルトは 1) — 1回の corrector sweep ごとに再サンプリングされる位置の数。
  • corrector_selection (str、デフォルトは "lowest_log_margin") — リサンプリングされた位置の選択方法: "lowest_log_margin"、"lowest_maxprob"、"lowest_current_prob"、または "random"。
  • corrector_selection_tau (float、デフォルト値は 1.0) — Gumbel-top-k による位置選択の温度パラメータ(値が小さいほど貪欲になります)。

https://huggingface.co/papers/2107.03006 の “Structured Denoising Diffusion Models in Discrete State-Spaces” (D3PM) に従う、一様破損プロセス用の離散 DDIM スケジューラーです。

線形スケジュールでは、時刻 t におけるクリーンなトークンの生存確率は alpha(t) = 1 - t です。時刻 t から s < t への 1 ステップのノイズ除去では、すべてのブロック位置について、厳密な事後分布 q(x_s | x_t, x0) からサンプリングが行われます。一様カーネルの場合、この事後分布は 3 つの経路に分解されます。予測されたクリーンなトークン x0 へのジャンプ、現在のトークンの維持、および一様ランダムなトークンへのジャンプです。マスク拡散とは異なり、マスクトークンは存在しません。未確定の位置にはランダムなトークンが保持されます。

任意の predictor-corrector モードは、leave-one-out (LOO) デノイザーによる “Uniform Diffusion Models Revisited: Leave-One-Out Denoiser and Absorbing State Reformulation” (https://huggingface.co/papers/2605.22765) に従います。 corrector_steps > 0 の場合、パイプラインは各 predictor ステップの後にその回数分の Gibbs corrector スイープを実行します(step_correct() を参照)。この処理では、残りの位置を固定したまま、最も確信度の低い位置を 1 座標条件分布 Cat(alpha_s * x0_loo + (1 - alpha_s) / K) から再サンプリングします。これにより周辺分布 p_s は不変のまま、学習コストなしで生成品質が向上します。

ステップ

< >

( model_output: torch.Tensortimestep: int | torch.Tensorsample: torch.LongTensortemperature: float = 0.0generator: torch.Generator | None = Nonereturn_dict: bool = True )

パラメータ

  • model_output (torch.Tensor、形状 (batch_size, block_length, vocab_size)) — 現在のブロックに対するモデルからの生の logits。
  • timestep (int または torch.Tensor) — デノイジングスケジュール内の現在のステップインデックスで、[0, num_inference_steps - 1] の範囲です。
  • sample (torch.LongTensor、形状 (batch_size, block_length)) — 現在のブロックのトークン ID x_t。
  • temperature (float) — x0 をサンプリングする際に logits に適用されるサンプリング温度です。
  • generator (torch.Generator、任意) — サンプリング用の乱数生成器。
  • return_dict (bool) — bool を返すかどうか。DiscreteDDIMSchedulerOutput か、通常のタプルを返すか。

一様破損過程の事後分布q(x_s | x_t, x0)から次のブロックをサンプリングします。

a = alpha_t / alpha_s(s から t までの生存確率)および b = alpha_s とすると、各経路の事後確率質量は

clean: b * (1 - a) / K + a * b * 1[x_t = x0]、stay: a * (1 - b) / K、noise: (1 - a) * (1 - b) / K、

したがって、最後のステップ(b = 1)では、予測されたクリーンなトークンが決定論的にコミットされます。

step_correct

< >

( model_output: torch.Tensortimestep: int | torch.Tensorsample: torch.LongTensorgenerator: torch.Generator | None = Nonereturn_dict: bool = True )

パラメータ

  • model_output (torch.Tensor、shape (batch_size, block_length, vocab_size)) — 現在の(predictor 適用後の)sample で再計算されたモデルの生の logits。
  • timestep (int または torch.Tensor) — 直前に完了した predictor のステップインデックス。corrector は次のグリッドポイント s で実行されます。
  • sample (torch.LongTensor、形状 (batch_size, block_length)) — リファインする現在のブロックのトークン ID。
  • generator (torch.Generator、任意) — サンプリング用の乱数生成器。
  • return_dict (bool) — bool を返すかどうか。DiscreteDDIMSchedulerOutput を返すか、通常のタプルを返すかを指定します。

予測子後の時刻sで、https://huggingface.co/papers/2605.22765のleave-one-out predictor-correctorに従い、Gibbs correctorのスイープを1回実行します。

モデルの logits(現在の sample で再計算されます)は LOO デノイザーに変換され、1 座標条件付き分布 p_s(x^l | x^{-l}) = Cat(alpha_s * x0_loo + (1 - alpha_s) / K) が形成されます。次に、最も確信度が低い corrector_k の位置が選択され、それらの位置のみが再サンプリングされ、残りの位置は固定されます。このスウィープは p_s を保持するため、周辺分布を変更せずにサンプルを洗練させることができ、追加の学習は不要です。

DiscreteDDIMSchedulerOutput

class diffusers.DiscreteDDIMSchedulerOutput

< >

( prev_sample: torch.LongTensorsampled_tokens: torch.LongTensorsampled_probs: torch.Tensorpred_logits: torch.Tensor )

パラメータ

  • prev_sample (torch.LongTensor、形状 (batch_size, block_length)) — 現在のデノイジングステップ後に更新されたブロックトークン。
  • sampled_tokens (torch.LongTensor、shape (batch_size, block_length)) — モデルの logits からサンプリングされたトークン ID、つまり予測されたクリーンなトークン x0 です。
  • sampled_probs (torch.Tensor、形状 (batch_size, block_length)) — サンプリングされたトークンの確率です。
  • pred_logits (torch.Tensor、shape (batch_size, block_length, vocab_size)) — 次のステップの自己条件付けのために渡される、denoiser の logits です。

離散型DDIMスケジューラーの出力クラスです。

Update on GitHub