Diffusers documentation

FlowMatchEulerDiscreteScheduler

You are viewing v0.32.0 version. A newer version v0.32.1 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

FlowMatchEulerDiscreteScheduler

FlowMatchEulerDiscreteScheduler is based on the flow-matching sampling introduced in Stable Diffusion 3.

FlowMatchEulerDiscreteScheduler

class diffusers.FlowMatchEulerDiscreteScheduler

< >

( num_train_timesteps: int = 1000 shift: float = 1.0 use_dynamic_shifting = False base_shift: typing.Optional[float] = 0.5 max_shift: typing.Optional[float] = 1.15 base_image_seq_len: typing.Optional[int] = 256 max_image_seq_len: typing.Optional[int] = 4096 invert_sigmas: bool = False shift_terminal: typing.Optional[float] = None use_karras_sigmas: typing.Optional[bool] = False use_exponential_sigmas: typing.Optional[bool] = False use_beta_sigmas: typing.Optional[bool] = False )

Parameters

  • num_train_timesteps (int, defaults to 1000) — The number of diffusion steps to train the model.
  • timestep_spacing (str, defaults to "linspace") — The way the timesteps should be scaled. Refer to Table 2 of the Common Diffusion Noise Schedules and Sample Steps are Flawed for more information.
  • shift (float, defaults to 1.0) — The shift value for the timestep schedule.

Euler scheduler.

This model inherits from SchedulerMixin and ConfigMixin. Check the superclass documentation for the generic methods the library implements for all schedulers such as loading and saving.

scale_noise

< >

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

Parameters

  • sample (torch.FloatTensor) — The input sample.
  • timestep (int, optional) — The current timestep in the diffusion chain.

Returns

torch.FloatTensor

A scaled input sample.

Forward process in flow-matching

set_begin_index

< >

( begin_index: int = 0 )

Parameters

  • begin_index (int) — The begin index for the scheduler.

Sets the begin index for the scheduler. This function should be run from pipeline before the inference.

set_timesteps

< >

( num_inference_steps: int = None device: typing.Union[str, torch.device] = None sigmas: typing.Optional[typing.List[float]] = None mu: typing.Optional[float] = None )

Parameters

  • num_inference_steps (int) — The number of diffusion steps used when generating samples with a pre-trained model.
  • device (str or torch.device, optional) — The device to which the timesteps should be moved to. If None, the timesteps are not moved.

Sets the discrete timesteps used for the diffusion chain (to be run before inference).

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._C.Generator] = None return_dict: bool = True ) EulerDiscreteSchedulerOutput or tuple

Parameters

  • model_output (torch.FloatTensor) — The direct output from learned diffusion model.
  • timestep (float) — The current discrete timestep in the diffusion chain.
  • sample (torch.FloatTensor) — A current instance of a sample created by the diffusion process.
  • s_churn (float) —
  • s_tmin (float) —
  • s_tmax (float) —
  • s_noise (float, defaults to 1.0) — Scaling factor for noise added to the sample.
  • generator (torch.Generator, optional) — A random number generator.
  • return_dict (bool) — Whether or not to return a EulerDiscreteSchedulerOutput or tuple.

Returns

EulerDiscreteSchedulerOutput or tuple

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

Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusion process from the learned model outputs (most often the predicted noise).

stretch_shift_to_terminal

< >

( t: Tensor ) torch.Tensor

Parameters

  • t (torch.Tensor) — A tensor of timesteps to be stretched and shifted.

Returns

torch.Tensor

A tensor of adjusted timesteps such that the final value equals self.config.shift_terminal.

Stretches and shifts the timestep schedule to ensure it terminates at the configured shift_terminal config value.

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

< > Update on GitHub