FlowMatchEulerDiscreteScheduler
is based on the flow-matching sampling introduced in Stable Diffusion 3.
( num_train_timesteps: int = 1000 shift: float = 1.0 use_dynamic_shifting: bool = 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 time_shift_type: str = 'exponential' )
Parameters
int
, defaults to 1000) —
The number of diffusion steps to train the model. float
, defaults to 1.0) —
The shift value for the timestep schedule. bool
, defaults to False) —
Whether to apply timestep shifting on-the-fly based on the image resolution. float
, defaults to 0.5) —
Value to stabilize image generation. Increasing base_shift
reduces variation and image is more consistent
with desired output. float
, defaults to 1.15) —
Value change allowed to latent vectors. Increasing max_shift
encourages more variation and image may be
more exaggerated or stylized. int
, defaults to 256) —
The base image sequence length. int
, defaults to 4096) —
The maximum image sequence length. bool
, defaults to False) —
Whether to invert the sigmas. float
, defaults to None) —
The end value of the shifted timestep schedule. bool
, defaults to False) —
Whether to use Karras sigmas for step sizes in the noise schedule during sampling. bool
, defaults to False) —
Whether to use exponential sigmas for step sizes in the noise schedule during sampling. bool
, defaults to False) —
Whether to use beta sigmas for step sizes in the noise schedule during sampling. str
, defaults to “exponential”) —
The type of dynamic resolution-dependent timestep shifting to apply. Either “exponential” or “linear”. 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.
( sample: FloatTensor timestep: typing.Union[float, torch.FloatTensor] noise: typing.Optional[torch.FloatTensor] = None ) → torch.FloatTensor
Forward process in flow-matching
( begin_index: int = 0 )
Sets the begin index for the scheduler. This function should be run from pipeline before the inference.
( num_inference_steps: typing.Optional[int] = None device: typing.Union[str, torch.device] = None sigmas: typing.Optional[typing.List[float]] = None mu: typing.Optional[float] = None timesteps: typing.Optional[typing.List[float]] = None )
Parameters
int
, optional) —
The number of diffusion steps used when generating samples with a pre-trained model. str
or torch.device
, optional) —
The device to which the timesteps should be moved to. If None
, the timesteps are not moved. List[float]
, optional) —
Custom values for sigmas to be used for each diffusion step. If None
, the sigmas are computed
automatically. float
, optional) —
Determines the amount of shifting applied to sigmas when performing resolution-dependent timestep
shifting. List[float]
, optional) —
Custom values for timesteps to be used for each diffusion step. If None
, the timesteps are computed
automatically. Sets the discrete timesteps used for the diffusion chain (to be run before inference).
( 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 ) → FlowMatchEulerDiscreteSchedulerOutput
or tuple
Parameters
torch.FloatTensor
) —
The direct output from learned diffusion model. float
) —
The current discrete timestep in the diffusion chain. torch.FloatTensor
) —
A current instance of a sample created by the diffusion process. float
) — float
) — float
) — float
, defaults to 1.0) —
Scaling factor for noise added to the sample. torch.Generator
, optional) —
A random number generator. bool
) —
Whether or not to return a
FlowMatchEulerDiscreteSchedulerOutput
or tuple. Returns
FlowMatchEulerDiscreteSchedulerOutput
or tuple
If return_dict is True
,
FlowMatchEulerDiscreteSchedulerOutput
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).
( t: Tensor ) → torch.Tensor
Stretches and shifts the timestep schedule to ensure it terminates at the configured shift_terminal
config
value.