Diffusers documentation
MiniMaxH3Scheduler
MiniMaxH3Scheduler
MiniMaxH3Scheduler 是 MiniMax-H3 所使用的 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
class diffusers.MiniMaxH3Scheduler
< source >( shift: float = 12.0stochastic_sampling: bool = Falseshift_provided_sigmas: bool | None = Noneeuler_update_form: str = 'blend' )
参数
- 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() 的显式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
< source >( timestep: typing.Union[float, torch.Tensor] ) → int
将时间步值映射到其在调度中的索引。
scale_noise
< source >( sample: FloatTensortimestep: typing.Union[float, torch.FloatTensor]noise: FloatTensor ) → torch.FloatTensor
MiniMax-H3 中 t 约定下的 Rectified-flow 前向过程:x_t = t*x_0 + (1 - t)*noise。
MiniMax-H3 使用此方法对其条件锚点添加噪声,其中 t 是 noise_aug 级别,而非调度表中的条目,因此 timestep 按字面值处理,不会在 self.timesteps 中进行查找。
设置调度器的起始索引。
覆盖已配置的 sigma shift;请在调用 set_timesteps() 之前调用。
MiniMax-H3 在每次请求中通过 flow_shift(视频)/ audio_flow_shift(音频)暴露此参数。
set_timesteps
< source >( num_inference_steps: int | None = Nonedevice: typing.Union[str, torch.device, NoneType] = Nonesigmas: typing.Union[list[float], torch.Tensor, NoneType] = None )
参数
- 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] 暴露。
步骤
< source >( model_output: FloatTensortimestep: typing.Union[float, torch.FloatTensor]sample: FloatTensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = True ) → MiniMaxH3SchedulerOutput or tuple
参数
- model_output (
torch.FloatTensor) — Transformer 在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
class diffusers.schedulers.scheduling_minimax_h3.MiniMaxH3SchedulerOutput
< source >( prev_sample: FloatTensor )
调度器 step 函数输出的输出类。