scheduling_flow_unipc_multistep ¶
Classes¶
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler ¶
FlowUniPCMultistepScheduler(num_train_timesteps: int = 1000, solver_order: int = 2, prediction_type: str = 'flow_prediction', shift: float | None = 1.0, use_dynamic_shifting=False, thresholding: bool = False, dynamic_thresholding_ratio: float = 0.995, sample_max_value: float = 1.0, predict_x0: bool = True, solver_type: str = 'bh2', lower_order_final: bool = True, disable_corrector: tuple = (), solver_p: SchedulerMixin = None, timestep_spacing: str = 'linspace', steps_offset: int = 0, final_sigmas_type: str | None = 'zero', **kwargs)
Bases: SchedulerMixin, ConfigMixin, BaseScheduler
UniPCMultistepScheduler is a training-free framework designed for the fast sampling of diffusion models.
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 |
solver_order | `int`, default `2` | The UniPC order which can be any positive integer. The effective order of accuracy is | 2 |
prediction_type | `str`, defaults to "flow_prediction" | Prediction type of the scheduler function; must be | 'flow_prediction' |
thresholding | `bool`, defaults to `False` | Whether to use the "dynamic thresholding" method. This is unsuitable for latent-space diffusion models such as Stable Diffusion. | False |
dynamic_thresholding_ratio | `float`, defaults to 0.995 | The ratio for the dynamic thresholding method. Valid only when | 0.995 |
sample_max_value | `float`, defaults to 1.0 | The threshold value for dynamic thresholding. Valid only when | 1.0 |
predict_x0 | `bool`, defaults to `True` | Whether to use the updating algorithm on the predicted x0. | True |
solver_type | `str`, default `bh2` | Solver type for UniPC. It is recommended to use | 'bh2' |
lower_order_final | `bool`, default `True` | Whether to use lower-order solvers in the final steps. Only valid for < 15 inference steps. This can stabilize the sampling of DPMSolver for steps < 15, especially for steps <= 10. | True |
disable_corrector | `list`, default `[]` | Decides which step to disable the corrector to mitigate the misalignment between | () |
solver_p | `SchedulerMixin`, default `None` | Any other scheduler that if specified, the algorithm becomes | None |
use_karras_sigmas | `bool`, *optional*, defaults to `False` | Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If | required |
use_exponential_sigmas | `bool`, *optional*, defaults to `False` | Whether to use exponential sigmas for step sizes in the noise schedule during the sampling process. | required |
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. | 'linspace' |
steps_offset | `int`, defaults to 0 | An offset added to the inference steps, as required by some model families. | 0 |
final_sigmas_type | `str`, defaults to `"zero"` | The final | 'zero' |
Source code in fastvideo/models/schedulers/scheduling_flow_unipc_multistep.py
Attributes¶
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.begin_index property ¶
The index for the first timestep. It should be set from pipeline with set_begin_index method.
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.step_index property ¶
The index counter for current timestep. It will increase 1 after each scheduler step.
Methods:¶
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.convert_model_output ¶
Convert the model output to the corresponding type the UniPC algorithm needs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output | `torch.Tensor` | The direct output from the learned diffusion model. | required |
timestep | `int` | The current discrete timestep in the diffusion chain. | required |
sample | `torch.Tensor` | A current instance of a sample created by the diffusion process. | None |
Returns:
| Type | Description |
|---|---|
Tensor |
|
Source code in fastvideo/models/schedulers/scheduling_flow_unipc_multistep.py
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.multistep_uni_c_bh_update ¶
multistep_uni_c_bh_update(this_model_output: Tensor, *args, last_sample: Tensor = None, this_sample: Tensor = None, order: int | None = None, **kwargs) -> Tensor
One step for the UniC (B(h) version).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
this_model_output | `torch.Tensor` | The model outputs at | required |
this_timestep | `int` | The current timestep | required |
last_sample | `torch.Tensor` | The generated sample before the last predictor | None |
this_sample | `torch.Tensor` | The generated sample after the last predictor | None |
order | `int` | The | None |
Returns:
| Type | Description |
|---|---|
Tensor |
|
Source code in fastvideo/models/schedulers/scheduling_flow_unipc_multistep.py
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 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.multistep_uni_p_bh_update ¶
multistep_uni_p_bh_update(model_output: Tensor, *args, sample: Tensor = None, order: int | None = None, **kwargs) -> Tensor
One step for the UniP (B(h) version). Alternatively, self.solver_p is used if is specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output | `torch.Tensor` | The direct output from the learned diffusion model at the current timestep. | required |
prev_timestep | `int` | The previous discrete timestep in the diffusion chain. | required |
sample | `torch.Tensor` | A current instance of a sample created by the diffusion process. | None |
order | `int` | The order of UniP at this timestep (corresponds to the p in UniPC-p). | None |
Returns:
| Type | Description |
|---|---|
Tensor |
|
Source code in fastvideo/models/schedulers/scheduling_flow_unipc_multistep.py
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 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 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 | |
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.scale_model_input ¶
Ensures interchangeability with schedulers that need to scale the denoising model input depending on the current timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample | `torch.Tensor` | The input sample. | required |
Returns:
| Type | Description |
|---|---|
Tensor |
|
Source code in fastvideo/models/schedulers/scheduling_flow_unipc_multistep.py
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.set_begin_index ¶
set_begin_index(begin_index: int = 0)
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_unipc_multistep.py
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.set_timesteps ¶
set_timesteps(num_inference_steps: int | None = None, device: str | device = None, sigmas: list[float] | None = None, mu: float | None | None = None, shift: float | None | None = None, use_karras_sigmas: bool | None = None, use_kerras_sigma: bool | None = None)
Sets the discrete timesteps used for the diffusion chain (to be run before inference). Args: num_inference_steps (int): Total number of the spacing of the time steps. device (str or torch.device, optional): The device to which the timesteps should be moved to. If None, the timesteps are not moved.
Source code in fastvideo/models/schedulers/scheduling_flow_unipc_multistep.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
fastvideo.models.schedulers.scheduling_flow_unipc_multistep.FlowUniPCMultistepScheduler.step ¶
step(model_output: Tensor, timestep: int | Tensor, sample: Tensor, return_dict: bool = True, generator=None) -> SchedulerOutput | tuple
Predict the sample from the previous timestep by reversing the SDE. This function propagates the sample with the multistep UniPC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output | `torch.Tensor` | The direct output from learned diffusion model. | required |
timestep | `int` | The current discrete timestep in the diffusion chain. | required |
sample | `torch.Tensor` | A current instance of a sample created by the diffusion process. | required |
return_dict | `bool` | Whether or not to return a [ | True |
Returns:
| Type | Description |
|---|---|
SchedulerOutput | tuple | [ |
Source code in fastvideo/models/schedulers/scheduling_flow_unipc_multistep.py
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |