# 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/v0.43.0/src/diffusers/schedulers/scheduling_flow_match_heun_discrete.py#L43)

**参数：**

num_train_timesteps (`int`，默认为 1000)：用于训练模型的扩散步数。

shift (`float`，默认值为 1.0)：时间步调度的偏移值。

Heun 调度器。

该模型继承自 [SchedulerMixin](/docs/diffusers/v0.43.0/zh/api/schedulers/overview#diffusers.SchedulerMixin) 和 [ConfigMixin](/docs/diffusers/v0.43.0/zh/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/v0.43.0/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/v0.43.0/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/v0.43.0/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/v0.43.0/src/diffusers/schedulers/scheduling_flow_match_heun_discrete.py#L139)

**参数：**

num_inference_steps (`int`) : 使用预训练模型生成样本时所用的扩散步数。

device (`str` 或 `torch.device`，*可选*)：时间步应移动到的设备。如果为 `None`，则不移动时间步。

设置扩散链所使用的离散时间步（需在推理之前运行）。

#### 步骤[[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/v0.43.0/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`

If return_dict is `True`, `FlowMatchHeunDiscreteSchedulerOutput` is returned, otherwise a tuple is returned where the first element is the sample tensor.

通过逆向 SDE 预测上一时间步的样本。此函数将扩散过程从学习到的模型输出（通常是预测的噪声）进行传播。

