# PiflowScheduler

`PiflowScheduler` 是蒸馏版 Kandinsky 6 检查点所使用的少步调度器，适用于文本/图像到视频和音频的模型以及视频超分辨率模型，同时也适用于蒸馏版 Kandinsky S2V 1.0 检查点。它实现了 [π-Flow](https://huggingface.co/papers/2510.14974)：transformer 在每个潜在通道的少量网格点上预测 `n_grid` 个去噪估计值，调度器则在它们之间积分一个无网络策略。

参考实现可在 [Lakonik/LakonLab](https://github.com/Lakonik/LakonLab) 中找到。

## PiflowScheduler[[diffusers.PiflowScheduler]]

#### diffusers.PiflowScheduler[[diffusers.PiflowScheduler]]

```python
diffusers.PiflowScheduler(num_train_timesteps: int = 1000, shift: float = 5.0, n_grid: int = 10, eps: float = 1e-06, final_step_size_scale: float = 0.5, num_policy_substeps: int = 128)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/schedulers/scheduling_piflow.py#L144)

**参数：**

num_train_timesteps (`int`，*可选*，默认为 1000)：训练扩散步数。

shift (`float`，*可选*，默认值为 5.0)：Flow-matching 时间步偏移。

n_grid (`int`，*可选*，默认为 10)：扩展模型输出中的预测数量。

eps (`float`，*可选*，默认为 1e-6)：最小时间步长和策略分母。

final_step_size_scale (`float`，*可选*，默认值为 0.5)：最终原始时间步段的相对大小。

num_policy_substeps (`int`，*可选*，默认值为 128)：每个原始时间步单位内策略积分的最大子步数。

用于宽输出扩散 Transformer 的少步 PiFlow 调度器。

PiFlow 在少量网格点上评估去噪模型，并在这些评估点之间集成一个无网络策略。该调度器旨在用于蒸馏后的 Kandinsky 6 检查点，包括主视频/音频模型和视频超分辨率模型。它们的模型输出在每个样本通道中包含 `n_grid` 个预测值。

该调度器继承自 [SchedulerMixin](/docs/diffusers/v0.43.0/zh/api/schedulers/overview#diffusers.SchedulerMixin) 和 [ConfigMixin](/docs/diffusers/v0.43.0/zh/api/configuration#diffusers.ConfigMixin)。有关为所有调度器实现的通用方法（如加载、保存等），请参阅父类文档。

#### set_timesteps[[diffusers.PiflowScheduler.set_timesteps]]

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

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/schedulers/scheduling_piflow.py#L224)

**参数：**

num_inference_steps (`int`) : 模型评估次数。

device (`str` 或 `torch.device`，*可选*)：用于调度的设备。

sigmas (`list[float]`，*可选*)：不支持的自定义 sigma 调度。

mu (`float`, *可选*) : 不支持的动态偏移参数。

timesteps (`list[float]`, *可选*) : 不支持的自定义时间步调度。

设置蒸馏后的 PiFlow 时间步调度。

#### 步骤[[diffusers.PiflowScheduler.step]]

```python
step(model_output: FloatTensor, timestep: typing.Union[float, torch.FloatTensor], sample: FloatTensor, return_dict: bool = True)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/schedulers/scheduling_piflow.py#L331)

**参数：**

model_output (*torch.FloatTensor*) : 扩展后的模型输出，每个样本通道包含 `n_grid` 个预测值。

timestep (*float* 或 *torch.FloatTensor*)：当前调度器时间步。

sample (*torch.FloatTensor*)：当前的含噪样本。

return_dict (*bool*，*optional*，默认为 True)：是否返回 [*PiflowSchedulerOutput*]。

**返回：** [*PiflowSchedulerOutput*] 或 *tuple*

已更新的示例。

通过集成 PiFlow 策略来推进一步。

## PiflowSchedulerOutput[[diffusers.schedulers.scheduling_piflow.PiflowSchedulerOutput]]

#### diffusers.schedulers.scheduling_piflow.PiflowSchedulerOutput[[diffusers.schedulers.scheduling_piflow.PiflowSchedulerOutput]]

```python
diffusers.schedulers.scheduling_piflow.PiflowSchedulerOutput(prev_sample: Tensor)
```

[源代码](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/schedulers/scheduling_piflow.py#L30)

**参数：**

prev_sample (`torch.Tensor`) : 在下一个 PiFlow 网格点处计算的样本。应将其用作下一次去噪的输入。

调度器 `step` 函数输出的输出类。

