# FlowMatchEulerDiscreteScheduler

`FlowMatchEulerDiscreteScheduler` は、[Stable Diffusion 3](https://huggingface.co/papers/2403.03206) で導入された flow-matching サンプリングに基づいています。

## FlowMatchEulerDiscreteScheduler[[diffusers.FlowMatchEulerDiscreteScheduler]]

#### diffusers.FlowMatchEulerDiscreteScheduler[[diffusers.FlowMatchEulerDiscreteScheduler]]

```python
diffusers.FlowMatchEulerDiscreteScheduler(num_train_timesteps: int = 1000, shift: float = 1.0, use_dynamic_shifting: bool = False, base_shift: float | None = 0.5, max_shift: float | None = 1.15, base_image_seq_len: int = 256, max_image_seq_len: int = 4096, invert_sigmas: bool = False, shift_terminal: float = None, use_karras_sigmas: bool = False, use_exponential_sigmas: bool = False, use_beta_sigmas: bool = False, time_shift_type: typing.Literal['exponential', 'linear'] = 'exponential', stochastic_sampling: bool = False)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L48)

**パラメータ:**

num_train_timesteps (`int`、デフォルトは 1000) : モデルを学習するための拡散ステップ数。

shift (`float`、デフォルト値は 1.0) : タイムステップスケジュールのシフト値です。

use_dynamic_shifting (`bool`、デフォルトは False) : 画像の解像度に基づいて、タイムステップシフトをオンザフライで適用するかどうか。

base_shift (`float`、デフォルト値は 0.5) : 画像生成を安定させるための値。`base_shift` を増やすとバリエーションが減少し、望ましい出力により一貫性のある画像が生成されます。

max_shift (`float`、デフォルト値は 1.15) : 潜在ベクトルに許可される値の変化量。`max_shift` を増やすと、より多くのバリエーションが促され、画像がより誇張されたり、スタイライズされたりする可能性があります。

base_image_seq_len (`int`、デフォルトは 256) : ベース画像のシーケンス長です。

max_image_seq_len (`int`、デフォルトは 4096) : 画像シーケンスの最大長です。

invert_sigmas (`bool`、デフォルトは False) : シグマを反転するかどうか。

shift_terminal (`float`、デフォルトは None) : シフトされたタイムステップスケジュールの終了値。

use_karras_sigmas (`bool`、デフォルトは False) : サンプリング中のノイズスケジュールにおけるステップサイズに Karras シグマを使用するかどうか。

use_exponential_sigmas (`bool`、デフォルトは False) : サンプリング時のノイズスケジュールにおけるステップサイズに、指数関数的なシグマを使用するかどうかを指定します。

use_beta_sigmas (`bool`、デフォルトは False) : サンプリング中のノイズスケジュールにおいて、ステップサイズにベータシグマを使用するかどうか。

time_shift_type (`str`、デフォルトは "exponential") : 適用する動的な解像度依存のタイムステップシフトの種類。"exponential" または "linear" のいずれかです。

stochastic_sampling (`bool`、デフォルトは False) : 確率的サンプリングを使用するかどうか。

Euler スケジューラ。

このモデルは [SchedulerMixin](/docs/diffusers/main/ja/api/schedulers/overview#diffusers.SchedulerMixin) と [ConfigMixin](/docs/diffusers/main/ja/api/configuration#diffusers.ConfigMixin) を継承しています。読み込みや保存など、ライブラリがすべてのスケジューラに対して実装している汎用的なメソッドについては、スーパークラスのドキュメントを参照してください。

#### index_for_timestep[[diffusers.FlowMatchEulerDiscreteScheduler.index_for_timestep]]

```python
index_for_timestep(timestep: typing.Union[float, torch.FloatTensor], schedule_timesteps: typing.Optional[torch.FloatTensor] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L393)

**パラメータ:**

timestep (`float` または `torch.FloatTensor`) : インデックスを特定するためのタイムステップ。

schedule_timesteps (`torch.FloatTensor`, *任意*) : 検証に使用するスケジュールのタイムステップ。`None` の場合、スケジューラのタイムステップが使用されます。

**戻り値:** `int`

タイムステップのインデックス。

与えられたタイムステップのインデックスを取得します。

#### scale_noise[[diffusers.FlowMatchEulerDiscreteScheduler.scale_noise]]

```python
scale_noise(sample: FloatTensor, timestep: typing.Union[float, torch.FloatTensor], noise: typing.Optional[torch.FloatTensor] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L188)

**パラメータ:**

sample (`torch.FloatTensor`) : 入力サンプル。

timestep (`torch.FloatTensor`) : 拡散チェーンにおける現在のタイムステップ。

noise (`torch.FloatTensor`) : ノイズテンソル。

**戻り値:** `torch.FloatTensor`

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

フローマッチングにおけるフォワードプロセス

#### set_begin_index[[diffusers.FlowMatchEulerDiscreteScheduler.set_begin_index]]

```python
set_begin_index(begin_index: int = 0)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L168)

**パラメータ:**

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

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

#### set_shift[[diffusers.FlowMatchEulerDiscreteScheduler.set_shift]]

```python
set_shift(shift: float)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L178)

**パラメータ:**

shift (`float`) : 設定するシフト値。

スケジューラーのシフト値を設定します。

#### set_timesteps[[diffusers.FlowMatchEulerDiscreteScheduler.set_timesteps]]

```python
set_timesteps(num_inference_steps: int | None = None, device: typing.Union[str, torch.device] = None, sigmas: list[float] | None = None, mu: float | None = None, timesteps: list[float] | None = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L283)

**パラメータ:**

num_inference_steps (`int`, *任意*) : 事前学習済みモデルでサンプルを生成する際に使用される拡散ステップ数。

device (`str` または `torch.device`、*任意*) : timesteps を移動先とするデバイスです。`None` の場合、timesteps は移動されません。

sigmas (`list[float]`, *任意*) : 各拡散ステップで使用するシグマの自定义値。`None` の場合、シグマは自動的に計算されます。

mu (`float`, *任意*) : 解像度依存のタイムステップシフトを実行する際に、シグマに適用されるシフト量を決定します。

timesteps (`list[float]`, *任意*) : 各拡散ステップで使用するタイムステップの自定义値。`None` の場合、タイムステップは自動的に計算されます。

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

#### ステップ[[diffusers.FlowMatchEulerDiscreteScheduler.step]]

```python
step(model_output: FloatTensor, timestep: typing.Union[float, torch.FloatTensor], sample: FloatTensor, s_churn: float = 0.0, s_tmin: float = 0.0, s_tmax: float = inf, s_noise: float = 1.0, generator: typing.Optional[torch.Generator] = None, per_token_timesteps: typing.Optional[torch.Tensor] = None, return_dict: bool = True)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L432)

**パラメータ:**

model_output (`torch.FloatTensor`) : 学習済み拡散モデルからの直接の出力。

timestep (`float`) : 拡散チェーンにおける現在の離散タイムステップ。

sample (`torch.FloatTensor`) : 拡散プロセスによって生成されたサンプルの現在のインスタンス。

s_churn (`float`) --

s_tmin (`float`) --

s_tmax (`float`) --

s_noise (`float`、デフォルトは 1.0) : サンプルに追加されるノイズのスケール係数。

generator (`torch.Generator`, *任意*) : 乱数生成器。

per_token_timesteps (`torch.Tensor`, *任意*) : サンプル内の各トークンに対するタイムステップ。

return_dict (`bool`、デフォルトは`True`) : `FlowMatchEulerDiscreteSchedulerOutput`を返すか、タプルを返すかを指定します。

**戻り値:** `FlowMatchEulerDiscreteSchedulerOutput` または `tuple`

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

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

#### stretch_shift_to_terminal[[diffusers.FlowMatchEulerDiscreteScheduler.stretch_shift_to_terminal]]

```python
stretch_shift_to_terminal(t: Tensor)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L262)

**パラメータ:**

t (`torch.Tensor`) : 伸縮とシフトを行うためのタイムステップのテンソル。

**戻り値:** `torch.Tensor`

最終値が`self.config.shift_terminal`に等しくなるよう調整されたタイムステップのテンソル。

タイムステップスケジュールを伸縮・シフトし、設定された`shift_terminal`設定値で終了することを保証します。

Reference: https://github.com/Lightricks/LTX-Video/blob/a01a171f8fe3d99dce2728d60a73fecf4d4238ae/ltx_video/schedulers/rf.py#L51

#### time_shift[[diffusers.FlowMatchEulerDiscreteScheduler.time_shift]]

```python
time_shift(mu: float, sigma: float, t: Tensor)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/schedulers/scheduling_flow_match_euler_discrete.py#L241)

**パラメータ:**

mu (`float`) : 時間シフト用の mu パラメータ。

sigma (`float`) : 時間シフト用の sigma パラメータ。

t (`torch.Tensor`) : 入力タイムステップ。

**戻り値:** `torch.Tensor`

時間シフトされたタイムステップ。

シグマに時間シフトを適用します。

