Diffusers documentation

FlowMatchEulerDiscreteScheduler

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

FlowMatchEulerDiscreteScheduler

FlowMatchEulerDiscreteScheduler 基于 Stable Diffusion 3 中引入的 flow-matching 采样方法。

FlowMatchEulerDiscreteScheduler

类 diffusers.FlowMatchEulerDiscreteScheduler

< >

( num_train_timesteps: int = 1000shift: float = 1.0use_dynamic_shifting: bool = Falsebase_shift: float | None = 0.5max_shift: float | None = 1.15base_image_seq_len: int = 256max_image_seq_len: int = 4096invert_sigmas: bool = Falseshift_terminal: float = Noneuse_karras_sigmas: bool = Falseuse_exponential_sigmas: bool = Falseuse_beta_sigmas: bool = Falsetime_shift_type: typing.Literal['exponential', 'linear'] = 'exponential'stochastic_sampling: bool = False )

参数

  • num_train_timesteps (int,默认为 1000) — 用于训练模型的扩散步数。
  • shift (float,默认为 1.0) — 时间步调度的 shift 值。
  • use_dynamic_shifting (bool,默认为 False) — 是否根据图像分辨率动态应用 timestep shifting。
  • base_shift (float,默认为 0.5) — 用于稳定图像生成的值。增大 base_shift 会减少变化,使图像与期望输出更加一致。
  • max_shift (float,默认为 1.15) — 允许对潜在向量进行的数值变化。增大 max_shift 会鼓励产生更多变化,图像可能会更加夸张或风格化。
  • base_image_seq_len (int,默认为 256) — 基础图像序列长度。
  • max_image_seq_len (int,默认为 4096) — 图像序列的最大长度。
  • invert_sigmas (bool,默认为 False) — 是否反转 sigmas。
  • shift_terminal (float,默认为 None) — 移位时间步调度的结束值。
  • use_karras_sigmas (bool,默认为 False) — 在采样过程中,噪声调度的步长是否使用 Karras sigmas。
  • use_exponential_sigmas (bool,默认为 False) — 在采样过程中,噪声调度的步长是否使用指数 sigmas。
  • use_beta_sigmas (bool,默认为 False) — 在采样过程中,噪声调度的步长是否使用 beta sigmas。
  • time_shift_type (str,默认为 “exponential”) — 要应用的动态分辨率相关时间步偏移类型。可以是 “exponential” 或 “linear”。
  • stochastic_sampling (bool,默认为 False) — 是否使用随机采样。

Euler 调度器。

该模型继承自 SchedulerMixin 和 ConfigMixin。有关该库为所有调度器实现的通用方法(例如加载和保存),请参阅父类文档。

index_for_timestep

< >

( timestep: typing.Union[float, torch.FloatTensor]schedule_timesteps: typing.Optional[torch.FloatTensor] = None ) → int

参数

  • timestep (float 或 torch.FloatTensor) — 用于查找索引的时间步。
  • schedule_timesteps (torch.FloatTensor,可选) — 用于验证的调度时间步。如果为 None,则使用调度器的时间步。

返回值

int

时间步的索引。

获取给定时间步的索引。

scale_noise

< >

( sample: FloatTensortimestep: typing.Union[float, torch.FloatTensor]noise: typing.Optional[torch.FloatTensor] = None ) → torch.FloatTensor

参数

  • sample (torch.FloatTensor) — 输入样本。
  • timestep (torch.FloatTensor) — 扩散链中的当前时间步。
  • noise (torch.FloatTensor) — 噪声张量。

返回值

torch.FloatTensor

经过缩放的输入样本。

流匹配中的前向过程

set_begin_index

< >

( begin_index: int = 0 )

参数

  • begin_index (int,默认为 0) — 调度器的起始索引。

设置调度器的起始索引。此函数应在推理之前从流水线中运行。

set_shift

< >

( shift: float )

参数

  • shift (float) — 要设置的 shift 值。

设置调度器的 shift 值。

set_timesteps

< >

( num_inference_steps: int | None = Nonedevice: typing.Union[str, torch.device] = Nonesigmas: list[float] | None = Nonemu: float | None = Nonetimesteps: list[float] | None = None )

参数

  • num_inference_steps (int, 可选) — 使用预训练模型生成样本时所用的扩散步数。
  • device (str 或 torch.device,可选) — 时间步应移动到的设备。如果为 None,则不移动时间步。
  • sigmas (list[float],可选) — 用于每个扩散步骤的自定义 sigmas 值。如果为 None,则自动计算 sigmas。
  • mu (float, 可选) — 确定在执行分辨率相关的 timestep 偏移时,对 sigmas 应用的偏移量。
  • timesteps (list[float],可选) — 用于每个扩散步的自定义时间步值。如果为 None,则时间步会自动计算。

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

步骤

< >

( model_output: FloatTensortimestep: typing.Union[float, torch.FloatTensor]sample: FloatTensors_churn: float = 0.0s_tmin: float = 0.0s_tmax: float = infs_noise: float = 1.0generator: typing.Optional[torch.Generator] = Noneper_token_timesteps: typing.Optional[torch.Tensor] = Nonereturn_dict: bool = True ) → FlowMatchEulerDiscreteSchedulerOutput or tuple

参数

  • model_output (torch.FloatTensor) — 学习到的扩散模型的直接输出。
  • timestep (float) — 扩散链中的当前离散时间步。
  • sample (torch.FloatTensor) — 扩散过程生成的样本的当前实例。
  • s_churn (float) —
  • s_tmin (float) —
  • s_tmax (float) —
  • s_noise (float,默认为 1.0) — 添加到样本的噪声的缩放因子。
  • generator (torch.Generator,可选) — 随机数生成器。
  • per_token_timesteps(torch.Tensor,可选)— 样本中每个 token 的时间步。
  • return_dict (bool,默认为 True) — 是否返回 FlowMatchEulerDiscreteSchedulerOutput 或元组。

返回值

FlowMatchEulerDiscreteSchedulerOutput 或 tuple

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

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

stretch_shift_to_terminal

< >

( t: Tensor ) → torch.Tensor

参数

  • t (torch.Tensor) — 一个用于拉伸和偏移的时间步张量。

返回值

torch.Tensor

一个经过调整的 timesteps 张量,其最终值等于 self.config.shift_terminal。

拉伸并平移时间步调度,以确保其在配置的 shift_terminal 配置值处终止。

参考:https://github.com/Lightricks/LTX-Video/blob/a01a171f8fe3d99dce2728d60a73fecf4d4238ae/ltx_video/schedulers/rf.py#L51

time_shift

< >

( mu: floatsigma: floatt: Tensor ) → torch.Tensor

参数

  • mu (float) — 用于时间偏移的 mu 参数。
  • sigma (float) — 用于时间偏移的 sigma 参数。
  • t (torch.Tensor) — 输入的时间步。

返回值

torch.Tensor

时间偏移的时间步。

对 sigmas 应用时间偏移。

Update on GitHub