pipelines ¶
Diffusion pipelines for fastvideo.
This package contains diffusion pipelines for generating videos and images.
Classes¶
fastvideo.pipelines.ComposedPipelineBase ¶
ComposedPipelineBase(model_path: str, fastvideo_args: FastVideoArgs | TrainingArgs, required_config_modules: list[str] | None = None, loaded_modules: dict[str, Module] | None = None)
Bases: ABC
Base class for pipelines composed of multiple stages.
This class provides the framework for creating pipelines by composing multiple stages together. Each stage is responsible for a specific part of the diffusion process, and the pipeline orchestrates the execution of these stages.
Initialize the pipeline. After init, the pipeline should be ready to use. The pipeline should be stateless and not hold any batch state.
Source code in fastvideo/pipelines/composed_pipeline_base.py
Attributes¶
fastvideo.pipelines.ComposedPipelineBase.required_config_modules property ¶
List of modules that are required by the pipeline. The names should match the diffusers directory and model_index.json file. These modules will be loaded using the PipelineComponentLoader and made available in the modules dictionary. Access these modules using the get_module method.
class ConcretePipeline(ComposedPipelineBase): _required_config_modules = ["vae", "text_encoder", "transformer", "scheduler", "tokenizer"]
@property
def required_config_modules(self):
return self._required_config_modules
fastvideo.pipelines.ComposedPipelineBase.stages property ¶
stages: list[PipelineStage]
List of stages in the pipeline.
Methods:¶
fastvideo.pipelines.ComposedPipelineBase.create_pipeline_stages abstractmethod ¶
create_pipeline_stages(fastvideo_args: FastVideoArgs)
fastvideo.pipelines.ComposedPipelineBase.create_training_stages ¶
create_training_stages(training_args: TrainingArgs)
fastvideo.pipelines.ComposedPipelineBase.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Generate a video or image using the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The batch to generate from. | required |
fastvideo_args | FastVideoArgs | The inference arguments. | required |
Returns: ForwardBatch: The batch with the generated video or image.
Source code in fastvideo/pipelines/composed_pipeline_base.py
fastvideo.pipelines.ComposedPipelineBase.from_pretrained classmethod ¶
from_pretrained(model_path: str, device: str | None = None, torch_dtype: dtype | None = None, pipeline_config: str | PipelineConfig | None = None, args: Namespace | None = None, required_config_modules: list[str] | None = None, loaded_modules: dict[str, Module] | None = None, **kwargs) -> ComposedPipelineBase
Load a pipeline from a pretrained model. loaded_modules: Optional[Dict[str, torch.nn.Module]] = None, If provided, loaded_modules will be used instead of loading from config/pretrained weights.
Source code in fastvideo/pipelines/composed_pipeline_base.py
fastvideo.pipelines.ComposedPipelineBase.get_hf_download_allow_patterns classmethod ¶
Return Hub patterns for the manifest and selected components.
Source code in fastvideo/pipelines/composed_pipeline_base.py
fastvideo.pipelines.ComposedPipelineBase.get_hf_download_component_dirs classmethod ¶
Return component directories for an opt-in partial Hub download.
fastvideo.pipelines.ComposedPipelineBase.initialize_pipeline ¶
initialize_pipeline(fastvideo_args: FastVideoArgs)
fastvideo.pipelines.ComposedPipelineBase.load_modules ¶
load_modules(fastvideo_args: FastVideoArgs, loaded_modules: dict[str, Module] | None = None) -> dict[str, Any]
Load the modules from the config. loaded_modules: Optional[Dict[str, torch.nn.Module]] = None, If provided, loaded_modules will be used instead of loading from config/pretrained weights.
Source code in fastvideo/pipelines/composed_pipeline_base.py
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 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 | |
fastvideo.pipelines.ForwardBatch dataclass ¶
ForwardBatch(data_type: str, generator: Generator | list[Generator] | None = None, image_path: str | None = None, image_embeds: list[Tensor] = list(), pil_image: Tensor | Image | None = None, last_image: Tensor | Image | None = None, references: list[Any] | None = None, preprocessed_image: Tensor | None = None, prompt: str | list[str] | None = None, negative_prompt: str | list[str] | None = None, prompt_path: str | None = None, output_path: str = 'outputs/', output_video_name: str | None = None, video_path: str | None = None, video_latent: Tensor | None = None, refine_from: str | None = None, t_thresh: float = 0.5, spatial_refine_only: bool = False, num_cond_frames: int = 0, stage1_video: list[Image] | None = None, prompt_embeds: list[Tensor] = list(), negative_prompt_embeds: list[Tensor] | None = None, prompt_attention_mask: list[Tensor] | None = None, negative_attention_mask: list[Tensor] | None = None, clip_embedding_pos: list[Tensor] | None = None, clip_embedding_neg: list[Tensor] | None = None, max_sequence_length: int | None = None, prompt_template: dict[str, Any] | None = None, do_classifier_free_guidance: bool = False, use_embedded_guidance: bool = False, true_cfg_scale: float = 1.0, batch_size: int | None = None, num_videos_per_prompt: int = 1, seed: int | None = None, seeds: list[int] | None = None, is_prompt_processed: bool = False, latents: Tensor | None = None, audio_latents: Tensor | None = None, lq_latents: Tensor | None = None, raw_latent_shape: tuple[int, ...] | None = None, noise_pred: Tensor | None = None, image_latent: Tensor | None = None, first_frame_latent: Tensor | None = None, mouse_cond: Tensor | None = None, keyboard_cond: Tensor | None = None, grid_sizes: Tensor | None = None, num_iterations: int | None = None, use_base_model: bool = False, pose: str | None = None, camera_states: Tensor | None = None, gt_latents: Tensor | None = None, conditioning_mask: Tensor | None = None, camera_trajectory: str | None = None, action_list: list[str] | None = None, action_speed_list: list[float] | None = None, c2ws_plucker_emb: Tensor | None = None, action_path: str | None = None, trajectory_type: str | None = None, movement_distance: float | None = None, camera_rotation: str | None = None, height_latents: list[int] | int | None = None, width_latents: list[int] | int | None = None, num_frames: list[int] | int = 1, height: list[int] | int | None = None, width: list[int] | int | None = None, height_sr: list[int] | int | None = None, width_sr: list[int] | int | None = None, fps: list[int] | int | None = None, timesteps: Tensor | None = None, timestep: Tensor | float | int | None = None, step_index: int | None = None, boundary_ratio: float | None = None, num_inference_steps: int = 50, num_inference_steps_sr: int = 50, guidance_scale: float = 1.0, batch_cfg: bool = False, guidance_scale_2: float | None = None, cfg_normalization: bool = False, cfg_truncation: float | None = 1.0, guidance_rescale: float = 0.0, eta: float = 0.0, sigmas: list[float] | None = None, enable_teacache: bool = False, ltx2_cfg_scale_video: float = 1.0, ltx2_cfg_scale_audio: float = 1.0, ltx2_modality_scale_video: float = 1.0, ltx2_modality_scale_audio: float = 1.0, ltx2_rescale_scale: float = 0.0, ltx2_stg_scale_video: float = 0.0, ltx2_stg_scale_audio: float = 0.0, ltx2_stg_blocks_video: list[int] = list(), ltx2_stg_blocks_audio: list[int] = list(), ltx2_images: list[tuple[str, int, float]] | None = None, ltx2_image_crf: float = 33.0, ltx2_conditioning_latent_stage1: Tensor | None = None, ltx2_conditioning_latent_stage2: Tensor | None = None, ltx2_video_conditions: list[tuple[list[str], int, float]] | None = None, audio_start_in_s: float | None = None, audio_end_in_s: float | None = None, init_audio: Any = None, init_audio_strength: float | None = None, init_noise_level: float | None = None, inpaint_audio: Any = None, inpaint_mask: Any = None, n_tokens: int | None = None, extra_step_kwargs: dict[str, Any] = dict(), modules: dict[str, Any] = dict(), output: Tensor | None = None, return_trajectory_latents: bool = False, return_trajectory_decoded: bool = False, trajectory_timesteps: list[Tensor] | None = None, trajectory_latents: Tensor | None = None, trajectory_decoded: list[Tensor] | None = None, continuation_state: ContinuationState | None = None, return_continuation_state: bool = False, extra: dict[str, Any] = dict(), save_video: bool = True, return_frames: bool = False, is_cfg_negative: bool = False, VSA_sparsity: float = 0.0, logging_info: PipelineLoggingInfo = PipelineLoggingInfo())
Complete state passed through the pipeline execution.
This dataclass contains all information needed during the diffusion pipeline execution, allowing methods to update specific components without needing to manage numerous individual parameters.
Methods:¶
fastvideo.pipelines.ForwardBatch.__post_init__ ¶
Initialize dependent fields after dataclass initialization.
Source code in fastvideo/pipelines/pipeline_batch_info.py
fastvideo.pipelines.LoRAPipeline ¶
Bases: ComposedPipelineBase
Pipeline that supports injecting LoRA adapters into the diffusion transformer. TODO: support training.
Source code in fastvideo/pipelines/lora_pipeline.py
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 | |
Methods:¶
fastvideo.pipelines.LoRAPipeline.convert_to_lora_layers ¶
Unified method to convert the transformer to a LoRA transformer.
Source code in fastvideo/pipelines/lora_pipeline.py
fastvideo.pipelines.LoRAPipeline.set_lora_adapter ¶
set_lora_adapter(lora_nickname: str, lora_path: str | None = None, strength: float = 1.0, accumulate: bool = False)
Load a LoRA adapter into the pipeline and merge it into the transformer. Args: lora_nickname: The "nick name" of the adapter when referenced in the pipeline. lora_path: The path to the adapter, either a local path or a Hugging Face repo id. strength: Scale for the low-rank adapter. Hybrid adapters must set this at construction so their dense payload receives the same scale. accumulate: Add this adapter to an already merged pure low-rank adapter.
Source code in fastvideo/pipelines/lora_pipeline.py
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 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 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
fastvideo.pipelines.LoRAPipeline.unmerge_lora_weights ¶
Unmerge LoRA weights when the transformer's quantized weights remain valid.
Source code in fastvideo/pipelines/lora_pipeline.py
fastvideo.pipelines.PipelineWithLoRA ¶
Bases: LoRAPipeline, ComposedPipelineBase
Type for a pipeline that has both ComposedPipelineBase and LoRAPipeline functionality.
Source code in fastvideo/pipelines/lora_pipeline.py
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 | |
Functions:¶
fastvideo.pipelines.build_pipeline ¶
build_pipeline(fastvideo_args: FastVideoArgs, pipeline_type: PipelineType | str = BASIC) -> PipelineWithLoRA
Only works with valid hf diffusers configs. (model_index.json) We want to build a pipeline based on the inference args mode_path: 1. resolve the pipeline class from the small Hub manifest 2. download the required model components if needed 3. verify the selected model components and build the pipeline