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.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
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 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
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, 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, lq_latents: Tensor | None = None, raw_latent_shape: tuple[int, ...] | None = None, noise_pred: Tensor | None = None, image_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
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.
Source code in fastvideo/pipelines/lora_pipeline.py
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 | |
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
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. download the model from the hub if it's not already downloaded 2. verify the model config and directory 3. based on the config, determine the pipeline class