# FlowMatchHeunDiscreteScheduler

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

## FlowMatchHeunDiscreteScheduler[[diffusers.FlowMatchHeunDiscreteScheduler]]

#### diffusers.FlowMatchHeunDiscreteScheduler[[diffusers.FlowMatchHeunDiscreteScheduler]]

```python
diffusers.FlowMatchHeunDiscreteScheduler(num_train_timesteps: int = 1000, shift: float = 1.0)
```

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

**パラメータ:**

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

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

Heun スケジューラ。

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

#### index_for_timestep[[diffusers.FlowMatchHeunDiscreteScheduler.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_heun_discrete.py#L179)

**パラメータ:**

timestep (`float` または `torch.FloatTensor`) : スケジュール内で検索するタイムステップの値。

schedule_timesteps (`torch.FloatTensor`、*任意*) : 検索対象のタイムステップスケジュール。`None` の場合、`self.timesteps` を使用します。

**戻り値:** `int`

スケジュールにおけるタイムステップのインデックス。

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

#### scale_noise[[diffusers.FlowMatchHeunDiscreteScheduler.scale_noise]]

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

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

**パラメータ:**

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

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

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

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

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

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

#### set_begin_index[[diffusers.FlowMatchHeunDiscreteScheduler.set_begin_index]]

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

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

**パラメータ:**

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

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

#### set_timesteps[[diffusers.FlowMatchHeunDiscreteScheduler.set_timesteps]]

```python
set_timesteps(num_inference_steps: int, device: typing.Union[str, torch.device] = None)
```

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

**パラメータ:**

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

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

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

#### ステップ[[diffusers.FlowMatchHeunDiscreteScheduler.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, return_dict: bool = True)
```

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

**パラメータ:**

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

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

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

s_churn (`float`) : サンプリング中に追加されるノイズの量を制御する確率性パラメータです。値を大きくするとランダム性が増します。

s_tmin (`float`) : 確率的性を適用するための最小タイムステップの閾値です。この値を超えるタイムステップにのみノイズが追加されます。

s_tmax (`float`) : 確率的性を適用するための最大タイムステップの閾値。この値未満のタイムステップにのみノイズが追加されます。

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

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

return_dict (`bool`) : `FlowMatchHeunDiscreteSchedulerOutput` のタプルを返すかどうか。

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

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

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

