Diffusers documentation

FlowMapEulerDiscreteScheduler

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

FlowMapEulerDiscreteScheduler

FlowMapEulerDiscreteScheduler は、フローマップ蒸留拡散モデル向けに設計された Euler 方式のサンプラーです。フローマップモデルは、固定の zt→zr\mathbf{z}_t \to \mathbf{z}_r ではなく、任意の間隔の遷移 zt→z0\mathbf{z}_t \to \mathbf{z}_0 を学習します。ステップの両端点は呼び出し側で指定されるため、任意ステップのサンプリングが可能になります。蒸留済みの単一チェックポイントを再学習せずに、NFE 1、2、4、8、16… で評価できます。

このスケジューラーは AnyFlow: Any-Step Video Diffusion Model with On-Policy Flow Map Distillation で導入され、AnyFlowPipeline および AnyFlowFARPipeline の統合に同梱されていますが、AnyFlow 固有のものではなく、フローマップ蒸留されたチェックポイントであれば何でも使用できます。

FlowMapEulerDiscreteScheduler

class diffusers.FlowMapEulerDiscreteScheduler

< >

( num_train_timesteps: int = 1000shift: float = 1.0 )

パラメータ

  • num_train_timesteps (int、デフォルト値は 1000) — 基盤となる flow-map モデルの学習に使用される拡散ステップ数。
  • shift (float、デフォルト値: 1.0) — 推論スケジュールに適用される乗法的なタイムステップシフト。shift=1.0 は恒等変換です。1.0 以上の値は、スケジュールを後続のステップでより多くのデノイジングを行う方向にシフトします(例: shift=5 は Wan2.1 のデフォルト値と一致します)。

フローマップ蒸留拡散モデル向けのオイラー型サンプラー。

Flow-map モデルは、固定の zt→zrz_t \to z_r ではなく、任意の区間での遷移を学習します。 zt→z0z_t \to z_0 consistency モデルの マッピングとは異なり、蒸留済みの単一のチェックポイントを再学習せずに 1、2、4、8、… NFE で評価できます。 step メソッドは、予測された速度に沿って、サンプルを timestep から r_timestep

Yuchao Gu、Guian Fang らによる AnyFlow: Any-Step Video Diffusion Model with On-Policy Flow Map Distillation で紹介されました。

このスケジューラは [SchedulerMixin] と [ConfigMixin] を継承しています。すべてのスケジューラに実装されている汎用的なメソッド(読み込み、保存など)については、スーパークラスのドキュメントを参照してください。

apply_shift

< >

( sigmas: Tensor )

設定されたシフト変換をシグマテンソルに適用します。

index_for_timestep

< >

( timestep: typing.Union[float, torch.FloatTensor] )

現在のスケジュール上のtimestepのインデックスを返します。スケジュール外の場合はNoneを返します。

self.timesteps に対して、小さな fp 許容誤差を用いて参照が行われます。これにより、timesteps = sigmas * num_train_timesteps という線形な関係を前提とせずに、対応する sigma を復元できます。これによって、カスタムスケジュール(非線形シフトや手動で設定された timesteps など)でも正しく解決されます。

scale_model_input

< >

( sample: Tensor*args**kwargs )

何もしない恒等スケーリング。他の Diffusers スケジューラとの API 互換性のために提供されています。

scale_noise

< >

( sample: FloatTensortimestep: typing.Union[float, torch.FloatTensor]noise: typing.Optional[torch.FloatTensor] = None )

正規化されたtimestepに従って、sampleをnoiseへ線形補間します。

set_begin_index

< >

( begin_index: int = 0 )

スケジューラの開始インデックスを設定します。スケジュールの途中から開始するパイプライン(例: image-to-image)は、ロールアウトの基準点を設定するために、set_timestepsと最初のstepの間にこれを呼び出します。

set_timesteps

< >

( num_inference_steps: typing.Optional[int] = Nonedevice: typing.Union[str, torch.device] = Nonesigmas: typing.Optional[typing.List[float]] = Nonetimesteps: typing.Optional[typing.List[float]] = None )

パラメータ

  • num_inference_steps (int, 任意) — 推論ステップ数。None の場合、sigmas または timesteps を渡す必要があります。
  • device (str または torch.device、任意) — self.sigmas / self.timesteps のターゲットデバイス。
  • sigmas (List[float]、optional) — num_inference_steps の長さを持つカスタムの sigma スケジュール。末尾の 0 sigma は自動的に追加されます。設定された shift がその上に適用されます。
  • timesteps (List[float], 任意) — num_inference_steps の長さを持つカスタムなタイムステップスケジュールです。self.timesteps と同じ単位(つまり num_train_timesteps でスケーリングされた値)で指定します。内部でシグマに変換されます。sigmas と timesteps の両方が渡された場合、その長さは一致する必要があります。

推論用のタイムステップスケジュールを構築します。

内部で、長さ num_inference_steps + 1 の self.sigmas を管理します(デフォルトでは、設定されたシフトが 1.0 から 0.0 までの linspace に適用されます)。self.timesteps は、num_train_timesteps によってスケーリングされた最初の num_inference_steps 個のシグマを公開します。つまり、推論ステップごとに1つのタイムステップが対応し、FlowMatchEulerDiscreteScheduler と一致します。最後のシグマ(0)は、最後のステップの暗黙の r 端点であり、sigmas / timesteps がユーザーによって提供された場合、自動的に追加されます。

ステップ

< >

( model_output: FloatTensortimestep: typing.Union[float, torch.FloatTensor]sample: FloatTensorr_timestep: typing.Union[float, torch.FloatTensor, NoneType] = Nonereturn_dict: bool = True ) → [FlowMapEulerDiscreteSchedulerOutput] or tuple

パラメータ

  • model_output (torch.Tensor) — フローマップモデルからの直接の出力(予測された平均速度)。
  • timestep (float または torch.Tensor) — self.timesteps と同じ単位で表されるソースタイムステップ t。
  • sample (torch.Tensor) — 現在のサンプル ztz_t。
  • r_timestep (float または torch.Tensor、optional) — ターゲットのタイムステップ r。None の場合はスケジュール上の次のタイムステップがデフォルトとして使用されます。any-step サンプリングには明示的な値を指定してください。r_timestep == timestep の場合は何もしません。
  • return_dict (bool、デフォルトは True) — [FlowMapEulerDiscreteSchedulerOutput] (デフォルト) を返すか、通常のタプルを返すかを指定します。

戻り値

[FlowMapEulerDiscreteSchedulerOutput] または tuple

return_dict=Trueの場合、prev_sampleがzrz_rである[FlowMapEulerDiscreteSchedulerOutput]を返します。それ以外の場合は、1タプル(prev_sample,)を返します。

モデルが予測した速度を用いて、timestep から r_timestep へ sample を進めます。

標準的な Euler スケジューラとは異なり、区間の両端を呼び出し側で指定できるため、任意ステップのサンプリングが可能です。単一のモデル呼び出しで、t から任意に選択したターゲット r(ワンショット生成のための r=0 を含む)へステップを進めることができます。r_timestep が省略された場合、スケジュール上の次のタイムステップがデフォルトとして使用されます(FlowMatchEulerDiscreteScheduler のセマンティクスと一致)。

内部では、ソースおよびターゲットのシグマは、入力タイムステップをnum_train_timestepsで割るのではなく、index_for_timestepを介してself.sigmasにインデックス指定することで復元されるため、タイムステップとシグマの関係が非線形であるスケジュール(カスタムシフトなど)でも正しく動作します。スケジュール外のr_timestepに対しては、スケジューラはr_timestep / num_train_timestepsにフォールバックするため、スケジュール外の任意のステップでのサンプリングも引き続きサポートされます。

Update on GitHub