Diffusers documentation
HeunDiscreteScheduler
HeunDiscreteScheduler
Heun スケジューラ(アルゴリズム 1)は、Karras らによる Elucidating the Design Space of Diffusion-Based Generative Models 論文に由来します。このスケジューラは k-diffusion ライブラリから移植され、Katherine Crowson 氏によって作成されました。
HeunDiscreteScheduler
class diffusers.HeunDiscreteScheduler
< source >( num_train_timesteps: int = 1000beta_start: float = 0.00085beta_end: float = 0.012beta_schedule: str = 'linear'trained_betas: numpy.ndarray | list[float] | None = Noneprediction_type: str = 'epsilon'use_karras_sigmas: bool = Falseuse_exponential_sigmas: bool = Falseuse_beta_sigmas: bool = Falseclip_sample: bool = Falseclip_sample_range: float = 1.0timestep_spacing: typing.Literal['linspace', 'leading', 'trailing'] = 'linspace'steps_offset: int = 0 )
パラメータ
- 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"、または"exp"、デフォルトは"linear") — ベータスケジュールです。モデルのステップ処理において、ベータの範囲からベータのシーケンスへのマッピングを指定します。linear、scaled_linear、squaredcos_cap_v2、またはexpから選択してください。 - 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 beepsilon(predicts the noise of the diffusion process),sample(directly predicts the noisy sample) orv_prediction` (see section 2.4 of Imagen Video paper). - clip_sample (
bool、デフォルトはTrue) — 数値の安定性を確保するために、予測されたサンプルをクリップします。 - clip_sample_range (
float、デフォルト値は 1.0) — サンプルクリッピングの最大振幅です。clip_sample=Trueの場合のみ有効です。 - use_karras_sigmas (
bool、任意、デフォルトはFalse) — サンプリング処理中のノイズスケジュールにおけるステップサイズに Karras sigmas を使用するかどうか。Trueの場合、sigmas はノイズレベルの列 {σi} に基づいて決定されます。 - use_exponential_sigmas (
bool、任意、デフォルトはFalse) — サンプリング処理中のノイズスケジュールにおけるステップサイズに、指数関数的なシグマを使用するかどうかを指定します。 - use_beta_sigmas (
bool, optional, defaults toFalse) — Whether to use beta sigmas for step sizes in the noise schedule during the sampling process. Refer to Beta Sampling is All You Need for more information. - 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)— 一部のモデルファミリーで必要とされる、推論ステップに追加されるオフセットです。
離散ベータスケジュール用のHeunステップ付きスケジューラ。
このモデルは SchedulerMixin および ConfigMixin を継承しています。読み込みや保存など、ライブラリがすべてのスケジューラに対して実装している汎用的なメソッドについては、スーパークラスのドキュメントを参照してください。
add_noise
< source >( original_samples: Tensornoise: Tensortimesteps: Tensor ) → torch.Tensor
指定されたタイムステップにおけるノイズスケジュールに従って、元のサンプルにノイズを追加します。
index_for_timestep
< source >( timestep: typing.Union[float, torch.Tensor]schedule_timesteps: typing.Optional[torch.Tensor] = None ) → int
与えられたタイムステップのタイムステップスケジュールにおけるインデックスを特定します。
scale_model_input
< source >( sample: Tensortimestep: typing.Union[float, torch.Tensor] ) → torch.Tensor
現在のタイムステップに応じて、デノイジングモデルの入力をスケーリングする必要があるスケジューラーとの相互運用性を保証します。
set_begin_index
< source >( begin_index: int = 0 )
スケジューラの開始インデックスを設定します。この関数は、推論の前にパイプラインから実行する必要があります。
set_timesteps
< source >( num_inference_steps: int | None = Nonedevice: typing.Union[str, torch.device] = Nonenum_train_timesteps: int | None = Nonetimesteps: list[int] | None = None )
パラメータ
- num_inference_steps (
int、任意、デフォルトはNone) — 事前学習済みモデルでサンプルを生成する際に使用する拡散ステップ数です。 - device (
str、torch.device、任意、デフォルトはNone) — timesteps を移動先とするデバイスです。Noneの場合、timesteps は移動されません。 - num_train_timesteps (
int、任意、デフォルトはNone) — モデルの学習時に使用される拡散ステップ数です。Noneの場合、デフォルトのnum_train_timesteps属性が使用されます。 - timesteps (
list[int], 任意) — タイムステップ間の任意の間隔をサポートするために使用するカスタムタイムステップ。Noneの場合、timestep_spacing属性に基づいてタイムステップが生成されます。timestepsが渡された場合、num_inference_stepsはNoneでなければならず、timestep_spacing属性は無視されます。
拡散チェーンで使用される離散タイムステップを設定します(推論の実行前に実行する必要があります)。
ステップ
< source >( model_output: typing.Union[torch.Tensor, numpy.ndarray]timestep: typing.Union[float, torch.Tensor]sample: typing.Union[torch.Tensor, numpy.ndarray]return_dict: bool = True ) → HeunDiscreteSchedulerOutput or tuple
パラメータ
- model_output (
torch.Tensor) — 学習済み拡散モデルからの直接の出力です。 - timestep (
float) — 拡散チェーンにおける現在の離散タイムステップ。 - sample (
torch.Tensor) — 拡散プロセスによって生成されたサンプルの現在のインスタンス。 - return_dict (
bool) —HeunDiscreteSchedulerOutputを返すか、タプルを返すかを指定します。
戻り値
HeunDiscreteSchedulerOutput または tuple
True の場合、HeunDiscreteSchedulerOutput が返され、それ以外の場合は、最初の要素がサンプルテンソルであるタプルが返されます。
前のタイムステップのサンプルを、SDEを逆方向に適用することで予測します。この関数は、学習済みモデルの出力(多くの場合、予測されたノイズ)から拡散過程を伝播させます。
SchedulerOutput
class diffusers.schedulers.scheduling_utils.SchedulerOutput
< source >( prev_sample: Tensor )
スケジューラーのstep関数の出力の基底クラス。