Diffusers documentation
DEISMultistepScheduler
DEISMultistepScheduler
Diffusion Exponential Integrator Sampler (DEIS) は、Qinsheng Zhang と Yongxin Chen による Fast Sampling of Diffusion Models with Exponential Integrator で提案されました。DEISMultistepScheduler は、拡散常微分方程式 (ODE) に対する高速な高次ソルバーです。
この実装では、DEIS論文の元の線形t空間ではなく、log-rho空間における多項式フィッティングの式を変更しています。この変更により、数値ソルバーに依存する代わりに、指数型多段更新に対して閉形式の係数が得られます。
論文の抄録は以下の通りです:
ここ数年、Diffusion models~(DMs)は生成モデリングタスクにおいて高忠実度のサンプルを生成する上で大きな成功を収めています。DMの主要な制約の一つは、その悪名高い低速なサンプリング手順であり、通常、学習された拡散過程の数百から数千の時間離散化ステップを必要とします。私たちの目標は、サンプル品質を維持しながら、はるかに少ないステップ数でDMの高速サンプリング手法を開発することです。そのために、DMにおけるサンプリング手順を体系的に分析し、サンプル品質に影響を与える主要な要因を特定しました。その中でも、離散化手法が最も重要です。学習された拡散過程を慎重に検討することで、Diffusion Exponential Integrator Sampler~(DEIS)を提案します。これは、常微分方程式 (ODEs) の離散化のために設計されたExponential Integratorに基づいており、学習された拡散過程の半線形構造を活用して離散化誤差を低減します。提案手法は任意のDMに適用可能であり、わずか10ステップで高忠実度のサンプルを生成できます。実験では、1つのA6000 GPU上で約3分でCIFAR10から50k枚の画像を生成しました。さらに、事前学習済みDMを直接使用することで、スコア関数評価~(NFE) の回数が制限されている場合でも、最先端のサンプリング性能を達成しました。例えば、CIFAR10では10 NFEで4.17 FID、15 NFEのみで3.37 FIDおよび9.74 ISを達成しています。コードはthis https URLで入手できます。
ヒント
solver_order は 2 または 3 に設定することをお勧めします。solver_order=1 は DDIMScheduler と同等です。
Imagenの動的閾値化はサポートされており、ピクセル空間の拡散モデルでは、thresholding=Trueを設定することで動的閾値化を使用できます。
DEISMultistepScheduler
クラス diffusers.DEISMultistepScheduler
< source >( num_train_timesteps: int = 1000beta_start: float = 0.0001beta_end: float = 0.02beta_schedule: typing.Literal['linear', 'scaled_linear', 'squaredcos_cap_v2'] = 'linear'trained_betas: numpy.ndarray | list[float] | None = Nonesolver_order: int = 2prediction_type: typing.Literal['epsilon', 'sample', 'v_prediction', 'flow_prediction'] = 'epsilon'thresholding: bool = Falsedynamic_thresholding_ratio: float = 0.995sample_max_value: float = 1.0algorithm_type: typing.Literal['deis'] = 'deis'solver_type: typing.Literal['logrho'] = 'logrho'lower_order_final: bool = Trueuse_karras_sigmas: bool = Falseuse_exponential_sigmas: bool = Falseuse_beta_sigmas: bool = Falseuse_flow_sigmas: bool = Falseflow_shift: float = 1.0timestep_spacing: typing.Literal['linspace', 'leading', 'trailing'] = 'linspace'steps_offset: int = 0use_dynamic_shifting: bool = Falsetime_shift_type: typing.Literal['exponential'] = 'exponential' )
パラメータ
- 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またはlist[float]、省略可) —beta_startとbeta_endをバイパスして、ベータの配列を直接コンストラクタに渡すことができます。 - solver_order (
int、デフォルトは2) —1、2、または3のいずれかのDEISのオーダーです。ガイド付きサンプリングにはsolver_order=2、無条件サンプリングにはsolver_order=3の使用を推奨します。 - prediction_type (
"epsilon","sample","v_prediction", or"flow_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),v_prediction(see section 2.4 of [Imagen Video](https://huggingface.co/papers/2210.02303) paper), orflow_prediction`. - thresholding (
bool、デフォルトはFalse) — 「動的閾値処理」メソッドを使用するかどうか。Stable Diffusion などの潜在空間拡散モデルには不向きです。 - dynamic_thresholding_ratio (
float、デフォルトは0.995) — 動的閾値化手法の比率。thresholding=Trueの場合にのみ有効です。 - sample_max_value (
float, デフォルトは1.0) — 動的閾値処理の閾値です。thresholding=Trueの場合のみ有効です。 - algorithm_type (
"deis"、デフォルトは"deis") — ソルバーのアルゴリズムタイプです。 - solver_type (
"logrho"、デフォルトは"logrho") — DEIS のソルバータイプ。 - lower_order_final (
bool、デフォルトはTrue) — 最終ステップで低次数のソルバーを使用するかどうか。推論ステップ数が15未満の場合のみ有効です。 - 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. - use_flow_sigmas (
bool、任意、デフォルトはFalse) — サンプリング処理中のノイズスケジュールにおいて、ステップサイズにフローシグマを使用するかどうかを指定します。 - flow_shift (
float、任意、デフォルト値は1.0) — フローベースモデルにおけるフローシフトパラメータです。 - 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) — 一部のモデルファミリーで必要とされる、推論ステップに追加されるオフセットです。 - use_dynamic_shifting (
bool、デフォルトはFalse) — ノイズスケジュールにダイナミックシフティングを使用するかどうか。 - time_shift_type (
"exponential"、デフォルトは"exponential") — 適用する時間シフトの種類です。
DEISMultistepScheduler は、拡散常微分方程式(ODE)を解く高速な高次ソルバーです。
このモデルは SchedulerMixin および ConfigMixin を継承しています。読み込みや保存など、ライブラリがすべてのスケジューラに対して実装している汎用的なメソッドについては、スーパークラスのドキュメントを参照してください。
add_noise
< source >( original_samples: Tensornoise: Tensortimesteps: IntTensor ) → torch.Tensor
指定されたタイムステップにおけるノイズスケジュールに従って、元のサンプルにノイズを追加します。
convert_model_output
< source >( model_output: Tensor*argssample: Tensor = None**kwargs ) → torch.Tensor
DEISアルゴリズムが要求する対応する型に、モデルの出力を変換します。
deis_first_order_update
< source >( model_output: Tensor*argssample: Tensor = None**kwargs ) → torch.Tensor
1次DEIS(DDIMと同等)の1ステップ。
index_for_timestep
< source >( timestep: typing.Union[int, torch.Tensor]schedule_timesteps: typing.Optional[torch.Tensor] = None ) → int
スケジュール内の指定されたタイムステップのインデックスを取得します。
multistep_deis_second_order_update
< source >( model_output_list: list*argssample: Tensor = None**kwargs ) → torch.Tensor
2次多段DEISの1ステップ。
multistep_deis_third_order_update
< source >( model_output_list: list*argssample: Tensor = None**kwargs ) → torch.Tensor
3次多ステップDEISの1ステップ。
scale_model_input
< source >( sample: Tensor*args**kwargs ) → torch.Tensor
現在のタイムステップに応じて、デノイジングモデルの入力をスケーリングする必要があるスケジューラーとの相互運用性を保証します。
set_begin_index
< source >( begin_index: int = 0 )
スケジューラの開始インデックスを設定します。この関数は、推論の前にパイプラインから実行する必要があります。
set_timesteps
< source >( num_inference_steps: intdevice: typing.Union[str, torch.device] = Nonemu: float | None = None )
拡散チェーンで使用される離散タイムステップを設定します(推論の実行前に実行する必要があります)。
ステップ
< source >( model_output: Tensortimestep: typing.Union[int, torch.Tensor]sample: Tensorreturn_dict: bool = True ) → SchedulerOutput or tuple
パラメータ
- model_output (
torch.Tensor) — 学習済み拡散モデルからの直接の出力です。 - timestep (
intまたはtorch.Tensor) — 拡散チェーンにおける現在の離散タイムステップです。 - sample (
torch.Tensor) — 拡散プロセスによって生成されたサンプルの現在のインスタンス。 - return_dict (
bool、デフォルトはTrue) —tupleを返すか、SchedulerOutput を返すかを指定します。
戻り値
SchedulerOutput または tuple
True の場合、SchedulerOutput が返され、それ以外の場合は、最初の要素がサンプルテンソルであるタプルが返されます。
前のタイムステップのサンプルをSDEを逆方向に適用することで予測します。この関数は、マルチステップDEISを用いてサンプルを伝播します。
SchedulerOutput
class diffusers.schedulers.scheduling_utils.SchedulerOutput
< source >( prev_sample: Tensor )
スケジューラーのstep関数の出力の基底クラス。