# MiniMaxH3Scheduler

`MiniMaxH3Scheduler` 是 [MiniMax-H3](https://huggingface.co/MiniMaxAI) 所使用的 rectified-flow Euler 调度器（`eta = 0`），采用指数 sigma 偏移：`sigma' = s * sigma / (1 + (s - 1) * sigma)`。

MiniMax-H3 流水线注册了**两个**，因为在每个步骤的单次 transformer 调用中，视频和音频潜变量分别遵循两个不同的调度：其中 `scheduler` 承载视频调度（在发布的检查点中为 `shift=12.0`），`audio_scheduler` 承载音频调度（`shift=3.0`）。

## MiniMaxH3Scheduler[[diffusers.MiniMaxH3Scheduler]]

#### diffusers.MiniMaxH3Scheduler[[diffusers.MiniMaxH3Scheduler]]

```python
diffusers.MiniMaxH3Scheduler(shift: float = 12.0, stochastic_sampling: bool = False, shift_provided_sigmas: bool | None = None, euler_update_form: str = 'blend')
```

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

**参数：**

shift (`float`，默认为 `12.0`)：应用于 sigma 网格的指数偏移，`sigma' = s*sigma / (1 + (s-1)*sigma)`。发布的检查点中，视频潜变量使用 `12.0`，音频潜变量使用 `3.0`。

stochastic_sampling (`bool`，默认为 `False`)：用重加噪更新替换 Euler 混合：预测干净样本，然后使用新的噪声将其重新加噪至下一个 sigma。少步 Pika H3 Flex 适配器是针对此更新进行训练的；基础检查点则不是。

shift_provided_sigmas (`bool`，*可选*)：指定传递给 [set_timesteps()](/docs/diffusers/v0.43.0/zh/api/schedulers/minimax_h3#diffusers.MiniMaxH3Scheduler.set_timesteps) 的显式 `sigmas` 是调度器会进行偏移的基础网格（类似于其 `linspace` 网格），还是按原样使用的完整调度。未设置时，将按原样使用并发出弃用警告；在 0.44.0 版本中，默认值将变为 `True`。

euler_update_form (`str`，默认为 `"blend"`)：Euler 更新的评估方式。`"blend"` 是 `x_t` / `x0` 的混合 `x_next = r*x_t + (1 - r)*x0`；`"velocity"` 是 `x_next = x_t + (sigma - sigma_next) * v`，以 float32 计算。两者是相同的更新，仅在 float32 舍入上存在差异；MiniMax-H3-Image 是使用 velocity 形式进行蒸馏的。

MiniMax-H3 所使用的、带有指数 sigma 偏移的 Rectified-flow Euler 调度器（`eta = 0`）。

#### index_for_timestep[[diffusers.MiniMaxH3Scheduler.index_for_timestep]]

```python
index_for_timestep(timestep: typing.Union[float, torch.Tensor])
```

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

**参数：**

timestep (`float` 或 `torch.Tensor`)：取自 `self.timesteps` 的值。由于调度在 `t` 上是严格递增的，因此匹配结果是唯一的。

**返回值：** `int`

`timestep` 的索引。

将时间步值映射到其在调度中的索引。

#### scale_noise[[diffusers.MiniMaxH3Scheduler.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_minimax_h3.py#L246)

**参数：**

sample (`torch.FloatTensor`)：干净的样本 `x_0`。

timestep (`float` 或 `torch.FloatTensor`)：目标时间，取值范围为 `[0, 1]`；当值为 `1` 时，`sample` 保持不变。

noise (`torch.FloatTensor`)：要混合的噪声。

**返回：** `torch.FloatTensor`

带噪声的样本。

MiniMax-H3 中 `t` 约定下的 Rectified-flow 前向过程：`x_t = t*x_0 + (1 - t)*noise`。

MiniMax-H3 使用此方法对其条件锚点添加噪声，其中 `t` 是 `noise_aug` 级别，而非调度表中的条目，因此 `timestep` 按字面值处理，并*不会*在 `self.timesteps` 中查找。

#### set_begin_index[[diffusers.MiniMaxH3Scheduler.set_begin_index]]

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

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

**参数：**

begin_index (`int`，默认为 `0`)：调度器的起始索引。

设置调度器的起始索引。

#### set_shift[[diffusers.MiniMaxH3Scheduler.set_shift]]

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

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

**参数：**

shift (`float`) : 用于下一个调度的指数偏移量。

覆盖已配置的 sigma shift；请在调用 [set_timesteps()](/docs/diffusers/v0.43.0/zh/api/schedulers/minimax_h3#diffusers.MiniMaxH3Scheduler.set_timesteps) 之前调用。

MiniMax-H3 在每次请求中通过 `flow_shift`（视频）/ `audio_flow_shift`（音频）暴露此参数。

#### set_timesteps[[diffusers.MiniMaxH3Scheduler.set_timesteps]]

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

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

**参数：**

num_inference_steps (`int`, *可选*) : sigma 网格点的数量，包含终端 `0`。当提供 `sigmas` 时，此参数将被忽略。

device (`str` 或 `torch.device`，*可选*)：调度张量被移动到的设备。网格本身始终在 CPU 上以 float32 构建，因此调度不依赖于加速器。

sigmas (`list[float]` 或 `torch.Tensor`，*可选*) : 一个显式的网格，严格递减并以 `0.0` 结尾。当 `shift_provided_sigmas=True` 时，它是 `[0, 1]` 区间内的基础网格，会像 `linspace` 网格一样经过 shift 变换；否则将按原样使用（已弃用的默认行为）。

构建 sigma / 时间步调度。

网格由 `linspace(1, 0, num_inference_steps)` 经过指数偏移生成，并合并连续的重复值；或者直接使用显式的 `sigmas`，当设置了 `shift_provided_sigmas` 时同样会进行偏移。终端值 `0` 本身已包含在网格中——偏移会将 `0` 精确映射为 `0`——因此调度包含 `num_inference_steps` 个 sigmas，并驱动 `num_inference_steps - 1` 次模型评估，其结果通过 `self.timesteps = 1 - sigmas[:-1]` 暴露。

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

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

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

**参数：**

model_output (`torch.FloatTensor`) : 转换器在 `timestep` 处的速度预测。

timestep (`float` 或 `torch.FloatTensor`)：当前时间步，是 `self.timesteps` 中的一个（因此 `timestep == 1 - sigma`）。

sample (`torch.FloatTensor`) : 当前样本 `x_t`。

generator (`torch.Generator`, *可选*) : 使用 `stochastic_sampling` 时从中抽取新噪声的生成器；否则不使用。

return_dict (`bool`，默认为 `True`)：是否返回 `MiniMaxH3SchedulerOutput` 而不是普通元组。

**返回：** `MiniMaxH3SchedulerOutput` 或 `tuple`

下一步的样本。

执行一步欧拉（`eta = 0`）步骤，或执行一步带有 `stochastic_sampling` 的重新加噪步骤。

模型输出是一个数据向速度，因此去噪估计为 `x0 = x_t + (1 - t) * v` — 注意这里的 `+`，与通常的 flow-match 约定相反。随后的更新是混合 `x_next = r*x_t + (1 - r)*x0`，其中 `r = sigma_next / sigma`，对于半精度样本在 float32 中计算。使用 `stochastic_sampling` 时，更新为 `x_next = (1 - sigma_next) * x0 + sigma_next * noise`，噪声来自 `generator`，所有计算均在 float32 中进行，因此最后一步（`sigma_next = 0`）返回 `x0`。当 `euler_update_form="velocity"` 时，相同的 Euler 更新在 float32 中计算为 `x_next = x_t + (sigma - sigma_next) * v`。

## MiniMaxH3SchedulerOutput[[diffusers.schedulers.scheduling_minimax_h3.MiniMaxH3SchedulerOutput]]

#### diffusers.schedulers.scheduling_minimax_h3.MiniMaxH3SchedulerOutput[[diffusers.schedulers.scheduling_minimax_h3.MiniMaxH3SchedulerOutput]]

```python
diffusers.schedulers.scheduling_minimax_h3.MiniMaxH3SchedulerOutput(prev_sample: FloatTensor)
```

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

**参数：**

prev_sample (`torch.FloatTensor`) : 去噪循环下一步的已计算样本 `x_{t+1}`。

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

