scheduling_flow_match_euler_discrete ¶
Classes¶
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler ¶
FlowMatchEulerDiscreteScheduler(num_train_timesteps: int = 1000, shift: float = 1.0, use_dynamic_shifting: bool = False, base_shift: float | None = 0.5, max_shift: float | None = 1.15, base_image_seq_len: int | None = 256, max_image_seq_len: int | None = 4096, invert_sigmas: bool = False, shift_terminal: float | None = None, use_karras_sigmas: bool | None = False, use_exponential_sigmas: bool | None = False, use_beta_sigmas: bool | None = False, time_shift_type: str = 'exponential', stochastic_sampling: bool = False, final_sigmas_type: str = 'sigma_min', sigma_max: float | None = None, sigma_min: float | None = None, sigma_data: float | None = None, use_reference_discrete_timesteps: bool = False)
Bases: SchedulerMixin, ConfigMixin, BaseScheduler
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_train_timesteps | `int`, defaults to 1000 | The number of diffusion steps to train the model. | 1000 |
shift | `float`, defaults to 1.0 | The shift value for the timestep schedule. | 1.0 |
use_dynamic_shifting | `bool`, defaults to False | Whether to apply timestep shifting on-the-fly based on the image resolution. | False |
base_shift | `float`, defaults to 0.5 | Value to stabilize image generation. Increasing | 0.5 |
max_shift | `float`, defaults to 1.15 | Value change allowed to latent vectors. Increasing | 1.15 |
base_image_seq_len | `int`, defaults to 256 | The base image sequence length. | 256 |
max_image_seq_len | `int`, defaults to 4096 | The maximum image sequence length. | 4096 |
invert_sigmas | `bool`, defaults to False | Whether to invert the sigmas. | False |
shift_terminal | `float`, defaults to None | The end value of the shifted timestep schedule. | None |
use_karras_sigmas | `bool`, defaults to False | Whether to use Karras sigmas for step sizes in the noise schedule during sampling. | False |
use_exponential_sigmas | `bool`, defaults to False | Whether to use exponential sigmas for step sizes in the noise schedule during sampling. | False |
use_beta_sigmas | `bool`, defaults to False | Whether to use beta sigmas for step sizes in the noise schedule during sampling. | False |
time_shift_type | `str`, defaults to "exponential" | The type of dynamic resolution-dependent timestep shifting to apply. Either "exponential" or "linear". | 'exponential' |
stochastic_sampling | `bool`, defaults to False | Whether to use stochastic sampling. | False |
final_sigmas_type | `str`, defaults to "sigma_min" | The type of final sigmas to use. Either "sigma_min" or "zero". | 'sigma_min' |
sigma_max | `float`, *optional* | The maximum sigma value for the noise schedule. | None |
sigma_min | `float`, *optional* | The minimum sigma value for the noise schedule. | None |
sigma_data | `float`, *optional* | The sigma data value for scaling. | None |
use_reference_discrete_timesteps | `bool`, defaults to False | Some reference schedulers (e.g. Z-Image) construct the timestep schedule by linspacing | False |
Source code in fastvideo/models/schedulers/scheduling_flow_match_euler_discrete.py
Attributes¶
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.begin_index property ¶
begin_index: int | None
The index for the first timestep. It should be set from pipeline with set_begin_index method.
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.shift property ¶
shift: float
The value used for shifting.
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.step_index property ¶
step_index: int | None
The index counter for current timestep. It will increase 1 after each scheduler step.
Methods:¶
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.add_noise ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clean_latent | Tensor | the clean latent with shape [B, C, H, W], where B is batch_size or batch_size * num_frames | required |
noise | Tensor | the noise with shape [B, C, H, W] | required |
timestep | IntTensor | the timestep with shape [1] or [bs * num_frames] or [bs, num_frames] | required |
Returns:
| Type | Description |
|---|---|
Tensor | the corrupted latent with shape [B, C, H, W] |
Source code in fastvideo/models/schedulers/scheduling_flow_match_euler_discrete.py
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.scale_noise ¶
scale_noise(sample: FloatTensor, timestep: float | FloatTensor, noise: FloatTensor | None = None) -> FloatTensor
Forward process in flow-matching
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample | `torch.FloatTensor` | The input sample. | required |
timestep | `int`, *optional* | The current timestep in the diffusion chain. | required |
Returns:
| Type | Description |
|---|---|
FloatTensor |
|
Source code in fastvideo/models/schedulers/scheduling_flow_match_euler_discrete.py
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.set_begin_index ¶
set_begin_index(begin_index: int = 0) -> None
Sets the begin index for the scheduler. This function should be run from pipeline before the inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
begin_index | `int` | The begin index for the scheduler. | 0 |
Source code in fastvideo/models/schedulers/scheduling_flow_match_euler_discrete.py
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.set_timesteps ¶
set_timesteps(num_inference_steps: int | None = None, device: str | device = None, sigmas: list[float] | None = None, mu: float | None = None, timesteps: list[float] | None = None) -> None
Sets the discrete timesteps used for the diffusion chain (to be run before inference).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_inference_steps | `int`, *optional* | The number of diffusion steps used when generating samples with a pre-trained model. | None |
device | `str` or `torch.device`, *optional* | The device to which the timesteps should be moved to. If | None |
sigmas | `List[float]`, *optional* | Custom values for sigmas to be used for each diffusion step. If | None |
mu | `float`, *optional* | Determines the amount of shifting applied to sigmas when performing resolution-dependent timestep shifting. | None |
timesteps | `List[float]`, *optional* | Custom values for timesteps to be used for each diffusion step. If | None |
Source code in fastvideo/models/schedulers/scheduling_flow_match_euler_discrete.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.step ¶
step(model_output: FloatTensor, timestep: int | Tensor, sample: FloatTensor, s_churn: float = 0.0, s_tmin: float = 0.0, s_tmax: float = float('inf'), s_noise: float = 1.0, generator: Generator | None = None, per_token_timesteps: Tensor | None = None, return_dict: bool = True) -> FlowMatchEulerDiscreteSchedulerOutput | tuple[FloatTensor, ...]
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).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output | `torch.FloatTensor` | The direct output from learned diffusion model. | required |
timestep | `int` or `torch.Tensor` | The current discrete timestep in the diffusion chain. | required |
sample | `torch.FloatTensor` | A current instance of a sample created by the diffusion process. | required |
s_churn | `float` | | 0.0 |
s_tmin | `float` | | 0.0 |
s_tmax | `float` | | float('inf') |
s_noise | `float`, defaults to 1.0 | Scaling factor for noise added to the sample. | 1.0 |
generator | `torch.Generator`, *optional* | A random number generator. | None |
per_token_timesteps | `torch.Tensor`, *optional* | The timesteps for each token in the sample. | None |
return_dict | `bool` | Whether or not to return a [ | True |
Returns:
| Type | Description |
|---|---|
FlowMatchEulerDiscreteSchedulerOutput | tuple[FloatTensor, ...] | [ |
Source code in fastvideo/models/schedulers/scheduling_flow_match_euler_discrete.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler.stretch_shift_to_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
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t | `torch.Tensor` | A tensor of timesteps to be stretched and shifted. | required |
Returns:
| Type | Description |
|---|---|
Tensor |
|
Source code in fastvideo/models/schedulers/scheduling_flow_match_euler_discrete.py
fastvideo.models.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteSchedulerOutput dataclass ¶
Bases: BaseOutput
Output class for the scheduler's step function output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_sample | `torch.FloatTensor` of shape `(batch_size, num_channels, height, width)` for images | Computed sample | required |