Diffusers documentation

EulerAncestralDiscreteScheduler

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

EulerAncestralDiscreteScheduler

Euler法ステップを用いた祖先サンプリングを実行するスケジューラーです。これは高速なスケジューラーであり、多くの場合、20〜30ステップで良好な出力を生成できます。このスケジューラーは、Katherine Crowson氏による元のk-diffusion実装に基づいています。

EulerAncestralDiscreteScheduler

class diffusers.EulerAncestralDiscreteScheduler

< >

( num_train_timesteps: int = 1000beta_start: float = 0.0001beta_end: float = 0.02beta_schedule: str = 'linear'trained_betas: numpy.ndarray | list[float] | None = Noneprediction_type: str = 'epsilon'timestep_spacing: str = 'linspace'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"。デフォルトは "linear")— ベータスケジュールです。モデルのステップ処理において、ベータの範囲からベータのシーケンスへの変換を定義します。linear、scaled_linear、または squaredcos_cap_v2 から選択してください。
  • trained_betas (np.ndarray, 省略可) — beta_start と beta_end をバイパスして、ベータの配列を直接コンストラクタに渡す場合に使用します。
  • prediction_type ("epsilon", "sample", or "v_prediction", defaults to "epsilon", optional) — 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).
  • timestep_spacing ("linspace", "leading", or "trailing", defaults to "linspace") — 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 とゆるく関連しています。

Euler法ステップを用いた祖先サンプリング。

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

add_noise

< >

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

パラメータ

  • original_samples (torch.Tensor) — ノイズが加えられる元のサンプルです。
  • noise (torch.Tensor) — 元のサンプルに追加するノイズのテンソル。
  • timesteps (torch.Tensor) — ノイズを追加するタイムステップ。スケジュールに基づいてノイズレベルを決定します。

戻り値

torch.Tensor

タイムステップスケジュールに従ってスケーリングされたノイズが加えられたノイズ付きサンプル。

指定されたタイムステップにおけるノイズスケジュールに従って、元のサンプルにノイズを追加します。

index_for_timestep

< >

( timestep: typing.Union[float, torch.Tensor]schedule_timesteps: typing.Optional[torch.Tensor] = None ) → int

パラメータ

  • timestep (float または torch.Tensor) — スケジュール内で検索するタイムステップの値。
  • schedule_timesteps (torch.Tensor、任意) — 検索対象となるタイムステップスケジュールです。None の場合、self.timesteps が使用されます。

戻り値

int

スケジュールにおけるタイムステップのインデックスです。最初のステップでは、スケジュールの途中で開始する場合(画像から画像への生成など)にシグマをスキップすることを避けるため、複数の一致が存在する場合は2番目のインデックスを返します。

与えられたタイムステップのタイムステップスケジュールにおけるインデックスを特定します。

scale_model_input

< >

( sample: Tensortimestep: typing.Union[float, torch.Tensor] ) → torch.Tensor

パラメータ

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

戻り値

torch.Tensor

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

現在のタイムステップに応じて、デノイジングモデルの入力をスケーリングする必要があるスケジューラとの相互運用性を保証します。Eulerアルゴリズムに合わせるため、デノイジングモデルの入力を(sigma**2 + 1) ** 0.5倍にスケーリングします。

set_begin_index

< >

( begin_index: int = 0 )

パラメータ

  • begin_index (int、デフォルトは0) — スケジューラの開始インデックスです。

スケジューラの開始インデックスを設定します。この関数は、推論の前にパイプラインから実行する必要があります。

set_timesteps

< >

( num_inference_steps: intdevice: typing.Union[str, torch.device] = None )

パラメータ

  • num_inference_steps (int) — 事前学習済みモデルでサンプルを生成する際に使用する拡散ステップの数。
  • device (str または torch.device、省略可) — timesteps を移動先とするデバイスです。None の場合、timesteps は移動されません。

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

ステップ

< >

( model_output: Tensortimestep: typing.Union[float, torch.Tensor]sample: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = True ) → EulerAncestralDiscreteSchedulerOutput or tuple

パラメータ

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

戻り値

EulerAncestralDiscreteSchedulerOutput または tuple

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

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

EulerAncestralDiscreteSchedulerOutput

class diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteSchedulerOutput

< >

( 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