Skip to content

Commit 7b6c8ae

Browse files
authored
[2/3][Preprocess] refactor pipeline registry & file structure (hao-ai-lab#639)
1 parent 6284eaa commit 7b6c8ae

17 files changed

Lines changed: 247 additions & 76 deletions

fastvideo/configs/configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def from_kwargs(cls, kwargs: dict[str,
138138

139139
def check_preprocess_config(self) -> None:
140140
if self.dataset_path == "":
141-
raise ValueError("dataset_path must be set for preprocessing mode")
141+
raise ValueError("dataset_path must be set for preprocess mode")
142142
if self.samples_per_file <= 0:
143143
raise ValueError("samples_per_file must be greater than 0")
144144
if self.flush_frequency <= 0:

fastvideo/fastvideo_args.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ExecutionMode(str, Enum):
2626
Inherits from str to allow string comparison for backward compatibility.
2727
"""
2828
INFERENCE = "inference"
29-
PREPROCESSING = "preprocessing"
29+
PREPROCESS = "preprocess"
3030
FINETUNING = "finetuning"
3131
DISTILLATION = "distillation"
3232

@@ -471,9 +471,8 @@ def check_fastvideo_args(self) -> None:
471471
"Mode is 'training' but inference_mode is True. Setting inference_mode to False."
472472
)
473473
self.inference_mode = False
474-
elif self.mode in [
475-
ExecutionMode.INFERENCE, ExecutionMode.PREPROCESSING
476-
] and not self.inference_mode:
474+
elif self.mode in [ExecutionMode.INFERENCE, ExecutionMode.PREPROCESS
475+
] and not self.inference_mode:
477476
logger.warning(
478477
"Mode is '%s' but inference_mode is False. Setting inference_mode to True.",
479478
self.mode)
@@ -510,10 +509,10 @@ def check_fastvideo_args(self) -> None:
510509
self.pipeline_config.check_pipeline_config()
511510

512511
# Add preprocessing config validation if needed
513-
if self.mode == ExecutionMode.PREPROCESSING:
512+
if self.mode == ExecutionMode.PREPROCESS:
514513
if self.preprocess_config is None:
515514
raise ValueError(
516-
"preprocess_config is not set in FastVideoArgs when mode is PREPROCESSING"
515+
"preprocess_config is not set in FastVideoArgs when mode is PREPROCESS"
517516
)
518517
if self.preprocess_config.model_path == "":
519518
self.preprocess_config.model_path = self.model_path

fastvideo/models/registry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import cloudpickle
1717
from torch import nn
1818

19-
from fastvideo.logger import logger
19+
from fastvideo.logger import init_logger
20+
21+
logger = init_logger(__name__)
2022

2123
# huggingface class name: (component_name, fastvideo module name, fastvideo class name)
2224
_TEXT_TO_VIDEO_DIT_MODELS = {

fastvideo/pipelines/__init__.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from fastvideo.pipelines.composed_pipeline_base import ComposedPipelineBase
1313
from fastvideo.pipelines.lora_pipeline import LoRAPipeline
1414
from fastvideo.pipelines.pipeline_batch_info import ForwardBatch, TrainingBatch
15-
from fastvideo.pipelines.pipeline_registry import PipelineRegistry
15+
from fastvideo.pipelines.pipeline_registry import (PipelineType,
16+
get_pipeline_registry)
1617
from fastvideo.utils import (maybe_download_model,
1718
verify_model_config_and_directory)
1819

@@ -24,7 +25,10 @@ class PipelineWithLoRA(LoRAPipeline, ComposedPipelineBase):
2425
pass
2526

2627

27-
def build_pipeline(fastvideo_args: FastVideoArgs) -> PipelineWithLoRA:
28+
def build_pipeline(
29+
fastvideo_args: FastVideoArgs,
30+
pipeline_type: PipelineType | str = PipelineType.BASIC
31+
) -> PipelineWithLoRA:
2832
"""
2933
Only works with valid hf diffusers configs. (model_index.json)
3034
We want to build a pipeline based on the inference args mode_path:
@@ -37,30 +41,37 @@ def build_pipeline(fastvideo_args: FastVideoArgs) -> PipelineWithLoRA:
3741
model_path = maybe_download_model(model_path)
3842
# fastvideo_args.downloaded_model_path = model_path
3943
logger.info("Model path: %s", model_path)
40-
config = verify_model_config_and_directory(model_path)
4144

42-
pipeline_architecture = config.get("_class_name")
43-
if pipeline_architecture is None:
45+
config = verify_model_config_and_directory(model_path)
46+
pipeline_name = config.get("_class_name")
47+
if pipeline_name is None:
4448
raise ValueError(
4549
"Model config does not contain a _class_name attribute. "
4650
"Only diffusers format is supported.")
4751

48-
pipeline_cls, pipeline_architecture = PipelineRegistry.resolve_pipeline_cls(
49-
pipeline_architecture)
52+
# Get the appropriate pipeline registry based on pipeline_type
53+
logger.info(
54+
"Building pipeline of type: %s", pipeline_type.value if isinstance(
55+
pipeline_type, PipelineType) else pipeline_type)
56+
pipeline_registry = get_pipeline_registry(pipeline_type)
57+
58+
if isinstance(pipeline_type, str):
59+
pipeline_type = PipelineType.from_string(pipeline_type)
5060

51-
# instantiate the pipeline
61+
pipeline_cls = pipeline_registry.resolve_pipeline_cls(
62+
pipeline_name, pipeline_type, fastvideo_args.workload_type)
63+
64+
# instantiate the pipelines
5265
pipeline = pipeline_cls(model_path, fastvideo_args)
53-
logger.info("Pipeline instantiated")
5466

55-
# pipeline is now initialized and ready to use
67+
logger.info("Pipelines instantiated")
68+
5669
return cast(PipelineWithLoRA, pipeline)
5770

5871

5972
__all__ = [
6073
"build_pipeline",
61-
"list_available_pipelines",
6274
"ComposedPipelineBase",
63-
"PipelineRegistry",
6475
"ForwardBatch",
6576
"LoRAPipeline",
6677
"TrainingBatch",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
"""
3+
Basic inference pipelines for fastvideo.
4+
5+
This package contains basic pipelines for video and image generation.
6+
"""
File renamed without changes.
File renamed without changes.
File renamed without changes.

fastvideo/pipelines/stepvideo/stepvideo_pipeline.py renamed to fastvideo/pipelines/basic/stepvideo/stepvideo_pipeline.py

File renamed without changes.

0 commit comments

Comments
 (0)