From bea02ccba39e90153e0502eb47a730bebd6d6242 Mon Sep 17 00:00:00 2001 From: DN6 Date: Thu, 18 Sep 2025 23:31:07 +0530 Subject: [PATCH 01/10] update --- src/diffusers/loaders/single_file_utils.py | 9 ++- .../modular_pipelines/modular_pipeline.py | 60 ++++++++++--------- .../modular_pipeline_utils.py | 43 ++++++++----- 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/src/diffusers/loaders/single_file_utils.py b/src/diffusers/loaders/single_file_utils.py index ef6c41e3ce97..2b67f91dc205 100644 --- a/src/diffusers/loaders/single_file_utils.py +++ b/src/diffusers/loaders/single_file_utils.py @@ -387,6 +387,14 @@ def is_valid_url(url): return False +def _validate_single_file_path(pretrained_model_name_or_path): + if os.path.isfile(pretrained_model_name_or_path): + return True + + repo_id, weight_name = _extract_repo_id_and_weights_name(pretrained_model_name_or_path) + return bool(repo_id and weight_name) + + def _extract_repo_id_and_weights_name(pretrained_model_name_or_path): if not is_valid_url(pretrained_model_name_or_path): raise ValueError("Invalid `pretrained_model_name_or_path` provided. Please set it to a valid URL.") @@ -398,7 +406,6 @@ def _extract_repo_id_and_weights_name(pretrained_model_name_or_path): pretrained_model_name_or_path = pretrained_model_name_or_path.replace(prefix, "") match = re.match(pattern, pretrained_model_name_or_path) if not match: - logger.warning("Unable to identify the repo_id and weights_name from the provided URL.") return repo_id, weights_name repo_id = f"{match.group(1)}/{match.group(2)}" diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index 78226a49b122..6e858587947c 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -22,7 +22,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union import torch -from huggingface_hub import create_repo +from huggingface_hub import create_pretrained_model_name_or_path from huggingface_hub.utils import validate_hf_hub_args from tqdm.auto import tqdm from typing_extensions import Self @@ -325,7 +325,7 @@ def from_pretrained( ) if not (has_remote_code and trust_remote_code): raise ValueError( - "Selected model repository does not happear to have any custom code or does not have a valid `config.json` file." + "Selected model pretrained_model_name_or_pathsitory does not happear to have any custom code or does not have a valid `config.json` file." ) class_ref = config["auto_map"][cls.__name__] @@ -366,7 +366,7 @@ def init_pipeline( collection: Optional[str] = None, ) -> "ModularPipeline": """ - create a ModularPipeline, optionally accept modular_repo to load from hub. + create a ModularPipeline, optionally accept modular_pretrained_model_name_or_path to load from hub. """ pipeline_class_name = MODULAR_PIPELINE_MAPPING.get(self.model_name, ModularPipeline.__name__) diffusers_module = importlib.import_module("diffusers") @@ -1481,7 +1481,7 @@ def __init__( pretrained_model_name_or_path: Path to a pretrained pipeline configuration. Can be None if the pipeline does not require any additional loading config. If provided, will first try to load component specs (only for from_pretrained components) and config values from `modular_model_index.json`, then - fallback to `model_index.json` for compatibility with standard non-modular repositories. + fallback to `model_index.json` for compatibility with standard non-modular pretrained_model_name_or_pathsitories. components_manager: Optional ComponentsManager for managing multiple component cross different pipelines and apply offloading strategies. @@ -1494,7 +1494,7 @@ def __init__( pipeline = ModularPipeline(blocks=my_custom_blocks) # Initialize from pretrained configuration - pipeline = ModularPipeline(blocks=my_blocks, pretrained_model_name_or_path="my-repo/modular-pipeline") + pipeline = ModularPipeline(blocks=my_blocks, pretrained_model_name_or_path="my-pretrained_model_name_or_path/modular-pipeline") # Initialize with components manager pipeline = ModularPipeline( @@ -1528,7 +1528,7 @@ def __init__( self._component_specs = {spec.name: deepcopy(spec) for spec in self.blocks.expected_components} self._config_specs = {spec.name: deepcopy(spec) for spec in self.blocks.expected_configs} - # update component_specs and config_specs from modular_repo + # update component_specs and config_specs from modular_pretrained_model_name_or_path if pretrained_model_name_or_path is not None: cache_dir = kwargs.pop("cache_dir", None) force_download = kwargs.pop("force_download", False) @@ -1573,7 +1573,7 @@ def __init__( config_dict = DiffusionPipeline.load_config(pretrained_model_name_or_path, **load_config_kwargs) except EnvironmentError as e: - logger.debug(f" model_index.json not found in the repo: {e}") + logger.debug(f" model_index.json not found in the pretrained_model_name_or_path: {e}") config_dict = None # update component_specs and config_specs based on model_index.json @@ -1582,7 +1582,7 @@ def __init__( if name in self._component_specs and isinstance(value, (tuple, list)) and len(value) == 2: library, class_name = value component_spec_dict = { - "repo": pretrained_model_name_or_path, + "pretrained_model_name_or_path": pretrained_model_name_or_path, "subfolder": name, "type_hint": (library, class_name), } @@ -1633,13 +1633,13 @@ def from_pretrained( **kwargs, ): """ - Load a ModularPipeline from a huggingface hub repo. + Load a ModularPipeline from a huggingface hub pretrained_model_name_or_path. Args: pretrained_model_name_or_path (`str` or `os.PathLike`, optional): Path to a pretrained pipeline configuration. It will first try to load config from `modular_model_index.json`, then fallback to `model_index.json` for compatibility with standard - non-modular repositories. If the repo does not contain any pipeline config, it will be set to None + non-modular pretrained_model_name_or_pathsitories. If the pretrained_model_name_or_path does not contain any pipeline config, it will be set to None during initialization. trust_remote_code (`bool`, optional): Whether to trust remote code when loading the pipeline, need to be set to True if you want to create @@ -1679,7 +1679,7 @@ def from_pretrained( # try to load modular_model_index.json config_dict = cls.load_config(pretrained_model_name_or_path, **load_config_kwargs) except EnvironmentError as e: - logger.debug(f" modular_model_index.json not found in the repo: {e}") + logger.debug(f" modular_model_index.json not found in the pretrained_model_name_or_path: {e}") config_dict = None if config_dict is not None: @@ -1692,7 +1692,7 @@ def from_pretrained( config_dict = DiffusionPipeline.load_config(pretrained_model_name_or_path, **load_config_kwargs) except EnvironmentError as e: - logger.debug(f" model_index.json not found in the repo: {e}") + logger.debug(f" model_index.json not found in the pretrained_model_name_or_path: {e}") if config_dict is not None: logger.debug(" try to determine the modular pipeline class from model_index.json") @@ -1731,11 +1731,15 @@ def save_pretrained(self, save_directory: Union[str, os.PathLike], push_to_hub: private = kwargs.pop("private", None) create_pr = kwargs.pop("create_pr", False) token = kwargs.pop("token", None) - repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1]) - repo_id = create_repo(repo_id, exist_ok=True, private=private, token=token).repo_id + pretrained_model_name_or_path_id = kwargs.pop( + "pretrained_model_name_or_path_id", save_directory.split(os.path.sep)[-1] + ) + pretrained_model_name_or_path_id = create_pretrained_model_name_or_path( + pretrained_model_name_or_path_id, exist_ok=True, private=private, token=token + ).pretrained_model_name_or_path_id # Create a new empty model card and eventually tag it - model_card = load_or_create_model_card(repo_id, token=token, is_pipeline=True) + model_card = load_or_create_model_card(pretrained_model_name_or_path_id, token=token, is_pipeline=True) model_card = populate_model_card(model_card) model_card.save(os.path.join(save_directory, "README.md")) @@ -1745,7 +1749,7 @@ def save_pretrained(self, save_directory: Union[str, os.PathLike], push_to_hub: if push_to_hub: self._upload_folder( save_directory, - repo_id, + pretrained_model_name_or_path_id, token=token, commit_message=commit_message, create_pr=create_pr, @@ -1809,7 +1813,7 @@ def register_components(self, **kwargs): library, class_name = None, None # extract the loading spec from the updated component spec that'll be used as part of modular_model_index.json config - # e.g. {"repo": "stabilityai/stable-diffusion-2-1", + # e.g. {"pretrained_model_name_or_path": "stabilityai/stable-diffusion-2-1", # "type_hint": ("diffusers", "UNet2DConditionModel"), # "subfolder": "unet", # "variant": None, @@ -2113,7 +2117,7 @@ def load_components(self, names: Optional[Union[List[str], str]] = None, **kwarg **kwargs: additional kwargs to be passed to `from_pretrained()`.Can be: - a single value to be applied to all components to be loaded, e.g. torch_dtype=torch.bfloat16 - a dict, e.g. torch_dtype={"unet": torch.bfloat16, "default": torch.float32} - - if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. `repo`, + - if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. `pretrained_model_name_or_path`, `variant`, `revision`, etc. """ @@ -2377,10 +2381,10 @@ def _component_spec_to_dict(component_spec: ComponentSpec) -> Any: - "type_hint": Tuple[str, str] Library name and class name of the component. (e.g. ("diffusers", "UNet2DConditionModel")) - All loading fields defined by `component_spec.loading_fields()`, typically: - - "repo": Optional[str] - The model repository (e.g., "stabilityai/stable-diffusion-xl"). + - "pretrained_model_name_or_path": Optional[str] + The model pretrained_model_name_or_pathsitory (e.g., "stabilityai/stable-diffusion-xl"). - "subfolder": Optional[str] - A subfolder within the repo where this component lives. + A subfolder within the pretrained_model_name_or_path where this component lives. - "variant": Optional[str] An optional variant identifier for the model. - "revision": Optional[str] @@ -2397,11 +2401,11 @@ def _component_spec_to_dict(component_spec: ComponentSpec) -> Any: Example: >>> from diffusers.pipelines.modular_pipeline_utils import ComponentSpec >>> from diffusers import UNet2DConditionModel >>> spec = ComponentSpec( - ... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... repo="path/to/repo", ... + ... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... pretrained_model_name_or_path="path/to/pretrained_model_name_or_path", ... subfolder="subfolder", ... variant=None, ... revision=None, ... default_creation_method="from_pretrained", ... ) >>> ModularPipeline._component_spec_to_dict(spec) { - "type_hint": ("diffusers", "UNet2DConditionModel"), "repo": "path/to/repo", "subfolder": "subfolder", + "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/pretrained_model_name_or_path", "subfolder": "subfolder", "variant": None, "revision": None, } """ @@ -2431,10 +2435,10 @@ def _dict_to_component_spec( - "type_hint": Tuple[str, str] Library name and class name of the component. (e.g. ("diffusers", "UNet2DConditionModel")) - All loading fields defined by `component_spec.loading_fields()`, typically: - - "repo": Optional[str] - The model repository (e.g., "stabilityai/stable-diffusion-xl"). + - "pretrained_model_name_or_path": Optional[str] + The model pretrained_model_name_or_pathsitory (e.g., "stabilityai/stable-diffusion-xl"). - "subfolder": Optional[str] - A subfolder within the repo where this component lives. + A subfolder within the pretrained_model_name_or_path where this component lives. - "variant": Optional[str] An optional variant identifier for the model. - "revision": Optional[str] @@ -2451,10 +2455,10 @@ def _dict_to_component_spec( ComponentSpec: A reconstructed ComponentSpec object. Example: - >>> spec_dict = { ... "type_hint": ("diffusers", "UNet2DConditionModel"), ... "repo": + >>> spec_dict = { ... "type_hint": ("diffusers", "UNet2DConditionModel"), ... "pretrained_model_name_or_path": "stabilityai/stable-diffusion-xl", ... "subfolder": "unet", ... "variant": None, ... "revision": None, ... } >>> ModularPipeline._dict_to_component_spec("unet", spec_dict) ComponentSpec( - name="unet", type_hint=UNet2DConditionModel, config=None, repo="stabilityai/stable-diffusion-xl", + name="unet", type_hint=UNet2DConditionModel, config=None, pretrained_model_name_or_path="stabilityai/stable-diffusion-xl", subfolder="unet", variant=None, revision=None, default_creation_method="from_pretrained" ) """ diff --git a/src/diffusers/modular_pipelines/modular_pipeline_utils.py b/src/diffusers/modular_pipelines/modular_pipeline_utils.py index b15126868634..7d969c66b7da 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline_utils.py +++ b/src/diffusers/modular_pipelines/modular_pipeline_utils.py @@ -21,6 +21,7 @@ import torch from ..configuration_utils import ConfigMixin, FrozenDict +from ..loaders.single_file_utils import _validate_single_file_path from ..utils import is_torch_available, logging @@ -80,10 +81,10 @@ class ComponentSpec: type_hint: Type of the component (e.g. UNet2DConditionModel) description: Optional description of the component config: Optional config dict for __init__ creation - repo: Optional repo path for from_pretrained creation - subfolder: Optional subfolder in repo - variant: Optional variant in repo - revision: Optional revision in repo + pretrained_model_name_or_path: Optional pretrained_model_name_or_path path for from_pretrained creation + subfolder: Optional subfolder in pretrained_model_name_or_path + variant: Optional variant in pretrained_model_name_or_path + revision: Optional revision in pretrained_model_name_or_path default_creation_method: Preferred creation method - "from_config" or "from_pretrained" """ @@ -92,7 +93,7 @@ class ComponentSpec: description: Optional[str] = None config: Optional[FrozenDict] = None # YiYi Notes: should we change it to pretrained_model_name_or_path for consistency? a bit long for a field name - repo: Optional[Union[str, List[str]]] = field(default=None, metadata={"loading": True}) + pretrained_model_name_or_path: Optional[Union[str, List[str]]] = field(default=None, metadata={"loading": True}) subfolder: Optional[str] = field(default="", metadata={"loading": True}) variant: Optional[str] = field(default=None, metadata={"loading": True}) revision: Optional[str] = field(default=None, metadata={"loading": True}) @@ -182,7 +183,7 @@ def loading_fields(cls) -> List[str]: @property def load_id(self) -> str: """ - Unique identifier for this spec's pretrained load, composed of repo|subfolder|variant|revision (no empty + Unique identifier for this spec's pretrained load, composed of pretrained_model_name_or_path|subfolder|variant|revision (no empty segments). """ if self.default_creation_method == "from_config": @@ -197,12 +198,12 @@ def decode_load_id(cls, load_id: str) -> Dict[str, Optional[str]]: Decode a load_id string back into a dictionary of loading fields and values. Args: - load_id: The load_id string to decode, format: "repo|subfolder|variant|revision" + load_id: The load_id string to decode, format: "pretrained_model_name_or_path|subfolder|variant|revision" where None values are represented as "null" Returns: Dict mapping loading field names to their values. e.g. { - "repo": "path/to/repo", "subfolder": "subfolder", "variant": "variant", "revision": "revision" + "pretrained_model_name_or_path": "path/to/pretrained_model_name_or_path", "subfolder": "subfolder", "variant": "variant", "revision": "revision" } If a segment value is "null", it's replaced with None. Returns None if load_id is "null" (indicating component not created with `load` method). """ @@ -260,33 +261,43 @@ def create(self, config: Optional[Union[FrozenDict, Dict[str, Any]]] = None, **k def load(self, **kwargs) -> Any: """Load component using from_pretrained.""" - # select loading fields from kwargs passed from user: e.g. repo, subfolder, variant, revision, note the list could change + # select loading fields from kwargs passed from user: e.g. pretrained_model_name_or_path, subfolder, variant, revision, note the list could change passed_loading_kwargs = {key: kwargs.pop(key) for key in self.loading_fields() if key in kwargs} # merge loading field value in the spec with user passed values to create load_kwargs load_kwargs = {key: passed_loading_kwargs.get(key, getattr(self, key)) for key in self.loading_fields()} - # repo is a required argument for from_pretrained, a.k.a. pretrained_model_name_or_path - repo = load_kwargs.pop("repo", None) - if repo is None: + # pretrained_model_name_or_path is a required argument for from_pretrained, a.k.a. pretrained_model_name_or_path + pretrained_model_name_or_path = load_kwargs.pop("pretrained_model_name_or_path", None) + if pretrained_model_name_or_path is None: raise ValueError( - "`repo` info is required when using `load` method (you can directly set it in `repo` field of the ComponentSpec or pass it as an argument)" + "`pretrained_model_name_or_path` info is required when using `load` method (you can directly set it in `pretrained_model_name_or_path` field of the ComponentSpec or pass it as an argument)" ) + is_single_file = _validate_single_file_path(pretrained_model_name_or_path) + if is_single_file and self.type_hint is None: + raise ValueError("type_hint is required when loading a single file model") if self.type_hint is None: try: from diffusers import AutoModel - component = AutoModel.from_pretrained(repo, **load_kwargs, **kwargs) + component = AutoModel.from_pretrained(pretrained_model_name_or_path, **load_kwargs, **kwargs) except Exception as e: raise ValueError(f"Unable to load {self.name} without `type_hint`: {e}") # update type_hint if AutoModel load successfully self.type_hint = component.__class__ else: + # determine load method + load_method = ( + getattr(self.type_hint, "from_single_file") + if is_single_file + else getattr(self.type_hint, "from_pretrained") + ) + try: - component = self.type_hint.from_pretrained(repo, **load_kwargs, **kwargs) + component = load_method(pretrained_model_name_or_path, **load_kwargs, **kwargs) except Exception as e: raise ValueError(f"Unable to load {self.name} using load method: {e}") - self.repo = repo + self.pretrained_model_name_or_path = pretrained_model_name_or_path for k, v in load_kwargs.items(): setattr(self, k, v) component._diffusers_load_id = self.load_id From af48d815d89b1d7b70fddb544d2e447bd621fcf0 Mon Sep 17 00:00:00 2001 From: DN6 Date: Wed, 24 Sep 2025 16:31:07 +0530 Subject: [PATCH 02/10] update --- .../modular_pipelines/modular_pipeline.py | 32 ++++++++----------- .../modular_pipeline_utils.py | 2 +- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index 6e858587947c..f1ebcd1014c2 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -22,7 +22,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union import torch -from huggingface_hub import create_pretrained_model_name_or_path +from huggingface_hub import create_repo from huggingface_hub.utils import validate_hf_hub_args from tqdm.auto import tqdm from typing_extensions import Self @@ -325,7 +325,7 @@ def from_pretrained( ) if not (has_remote_code and trust_remote_code): raise ValueError( - "Selected model pretrained_model_name_or_pathsitory does not happear to have any custom code or does not have a valid `config.json` file." + "Selected model repository does not happear to have any custom code or does not have a valid `config.json` file." ) class_ref = config["auto_map"][cls.__name__] @@ -1481,7 +1481,7 @@ def __init__( pretrained_model_name_or_path: Path to a pretrained pipeline configuration. Can be None if the pipeline does not require any additional loading config. If provided, will first try to load component specs (only for from_pretrained components) and config values from `modular_model_index.json`, then - fallback to `model_index.json` for compatibility with standard non-modular pretrained_model_name_or_pathsitories. + fallback to `model_index.json` for compatibility with standard non-modular repositories. components_manager: Optional ComponentsManager for managing multiple component cross different pipelines and apply offloading strategies. @@ -1494,7 +1494,7 @@ def __init__( pipeline = ModularPipeline(blocks=my_custom_blocks) # Initialize from pretrained configuration - pipeline = ModularPipeline(blocks=my_blocks, pretrained_model_name_or_path="my-pretrained_model_name_or_path/modular-pipeline") + pipeline = ModularPipeline(blocks=my_blocks, pretrained_model_name_or_path="my-repo/modular-pipeline") # Initialize with components manager pipeline = ModularPipeline( @@ -1528,7 +1528,7 @@ def __init__( self._component_specs = {spec.name: deepcopy(spec) for spec in self.blocks.expected_components} self._config_specs = {spec.name: deepcopy(spec) for spec in self.blocks.expected_configs} - # update component_specs and config_specs from modular_pretrained_model_name_or_path + # update component_specs and config_specs from modular_repo if pretrained_model_name_or_path is not None: cache_dir = kwargs.pop("cache_dir", None) force_download = kwargs.pop("force_download", False) @@ -1573,7 +1573,7 @@ def __init__( config_dict = DiffusionPipeline.load_config(pretrained_model_name_or_path, **load_config_kwargs) except EnvironmentError as e: - logger.debug(f" model_index.json not found in the pretrained_model_name_or_path: {e}") + logger.debug(f" model_index.json not found in the repo: {e}") config_dict = None # update component_specs and config_specs based on model_index.json @@ -1633,7 +1633,7 @@ def from_pretrained( **kwargs, ): """ - Load a ModularPipeline from a huggingface hub pretrained_model_name_or_path. + Load a ModularPipeline from a huggingface hub repo. Args: pretrained_model_name_or_path (`str` or `os.PathLike`, optional): @@ -1679,7 +1679,7 @@ def from_pretrained( # try to load modular_model_index.json config_dict = cls.load_config(pretrained_model_name_or_path, **load_config_kwargs) except EnvironmentError as e: - logger.debug(f" modular_model_index.json not found in the pretrained_model_name_or_path: {e}") + logger.debug(f" modular_model_index.json not found in the repo: {e}") config_dict = None if config_dict is not None: @@ -1692,7 +1692,7 @@ def from_pretrained( config_dict = DiffusionPipeline.load_config(pretrained_model_name_or_path, **load_config_kwargs) except EnvironmentError as e: - logger.debug(f" model_index.json not found in the pretrained_model_name_or_path: {e}") + logger.debug(f" model_index.json not found in the repo: {e}") if config_dict is not None: logger.debug(" try to determine the modular pipeline class from model_index.json") @@ -1731,15 +1731,11 @@ def save_pretrained(self, save_directory: Union[str, os.PathLike], push_to_hub: private = kwargs.pop("private", None) create_pr = kwargs.pop("create_pr", False) token = kwargs.pop("token", None) - pretrained_model_name_or_path_id = kwargs.pop( - "pretrained_model_name_or_path_id", save_directory.split(os.path.sep)[-1] - ) - pretrained_model_name_or_path_id = create_pretrained_model_name_or_path( - pretrained_model_name_or_path_id, exist_ok=True, private=private, token=token - ).pretrained_model_name_or_path_id + repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1]) + repo_id = create_repo(repo_id, exist_ok=True, private=private, token=token).repo_id # Create a new empty model card and eventually tag it - model_card = load_or_create_model_card(pretrained_model_name_or_path_id, token=token, is_pipeline=True) + model_card = load_or_create_model_card(repo_id, token=token, is_pipeline=True) model_card = populate_model_card(model_card) model_card.save(os.path.join(save_directory, "README.md")) @@ -1749,7 +1745,7 @@ def save_pretrained(self, save_directory: Union[str, os.PathLike], push_to_hub: if push_to_hub: self._upload_folder( save_directory, - pretrained_model_name_or_path_id, + repo_id, token=token, commit_message=commit_message, create_pr=create_pr, @@ -2405,7 +2401,7 @@ def _component_spec_to_dict(component_spec: ComponentSpec) -> Any: subfolder="subfolder", ... variant=None, ... revision=None, ... default_creation_method="from_pretrained", ... ) >>> ModularPipeline._component_spec_to_dict(spec) { - "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/pretrained_model_name_or_path", "subfolder": "subfolder", + "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", "variant": None, "revision": None, } """ diff --git a/src/diffusers/modular_pipelines/modular_pipeline_utils.py b/src/diffusers/modular_pipelines/modular_pipeline_utils.py index 7d969c66b7da..aa22d963c683 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline_utils.py +++ b/src/diffusers/modular_pipelines/modular_pipeline_utils.py @@ -203,7 +203,7 @@ def decode_load_id(cls, load_id: str) -> Dict[str, Optional[str]]: Returns: Dict mapping loading field names to their values. e.g. { - "pretrained_model_name_or_path": "path/to/pretrained_model_name_or_path", "subfolder": "subfolder", "variant": "variant", "revision": "revision" + "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", "variant": "variant", "revision": "revision" } If a segment value is "null", it's replaced with None. Returns None if load_id is "null" (indicating component not created with `load` method). """ From 0a7bde92008f7c5e1dee9bd1d9ff552495e8b164 Mon Sep 17 00:00:00 2001 From: DN6 Date: Wed, 24 Sep 2025 16:33:09 +0530 Subject: [PATCH 03/10] update --- src/diffusers/modular_pipelines/modular_pipeline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index f1ebcd1014c2..0b316676afd9 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -366,7 +366,7 @@ def init_pipeline( collection: Optional[str] = None, ) -> "ModularPipeline": """ - create a ModularPipeline, optionally accept modular_pretrained_model_name_or_path to load from hub. + create a ModularPipeline, optionally accept pretrained_model_name_or_path to load from hub. """ pipeline_class_name = MODULAR_PIPELINE_MAPPING.get(self.model_name, ModularPipeline.__name__) diffusers_module = importlib.import_module("diffusers") @@ -1639,7 +1639,7 @@ def from_pretrained( pretrained_model_name_or_path (`str` or `os.PathLike`, optional): Path to a pretrained pipeline configuration. It will first try to load config from `modular_model_index.json`, then fallback to `model_index.json` for compatibility with standard - non-modular pretrained_model_name_or_pathsitories. If the pretrained_model_name_or_path does not contain any pipeline config, it will be set to None + non-modular repositories. If the pretrained_model_name_or_path does not contain any pipeline config, it will be set to None during initialization. trust_remote_code (`bool`, optional): Whether to trust remote code when loading the pipeline, need to be set to True if you want to create From c1c0e9a481e2e5f09d9792fb606e10996463f280 Mon Sep 17 00:00:00 2001 From: DN6 Date: Mon, 29 Sep 2025 12:35:55 +0530 Subject: [PATCH 04/10] update --- src/diffusers/modular_pipelines/modular_pipeline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index 0b316676afd9..27b8ab0e42d1 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -2397,7 +2397,7 @@ def _component_spec_to_dict(component_spec: ComponentSpec) -> Any: Example: >>> from diffusers.pipelines.modular_pipeline_utils import ComponentSpec >>> from diffusers import UNet2DConditionModel >>> spec = ComponentSpec( - ... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... pretrained_model_name_or_path="path/to/pretrained_model_name_or_path", ... + ... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... pretrained_model_name_or_path="path/to/repo", ... subfolder="subfolder", ... variant=None, ... revision=None, ... default_creation_method="from_pretrained", ... ) >>> ModularPipeline._component_spec_to_dict(spec) { @@ -2432,7 +2432,7 @@ def _dict_to_component_spec( Library name and class name of the component. (e.g. ("diffusers", "UNet2DConditionModel")) - All loading fields defined by `component_spec.loading_fields()`, typically: - "pretrained_model_name_or_path": Optional[str] - The model pretrained_model_name_or_pathsitory (e.g., "stabilityai/stable-diffusion-xl"). + The model repository (e.g., "stabilityai/stable-diffusion-xl"). - "subfolder": Optional[str] A subfolder within the pretrained_model_name_or_path where this component lives. - "variant": Optional[str] From a707e314ad76f01df93761286d3a237c0778b983 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 20 Oct 2025 09:44:50 +0000 Subject: [PATCH 05/10] Apply style fixes --- .../modular_pipelines/modular_pipeline.py | 30 ++++++++++--------- .../modular_pipeline_utils.py | 7 +++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index 27b8ab0e42d1..8bd37e7a78b3 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -1639,8 +1639,8 @@ def from_pretrained( pretrained_model_name_or_path (`str` or `os.PathLike`, optional): Path to a pretrained pipeline configuration. It will first try to load config from `modular_model_index.json`, then fallback to `model_index.json` for compatibility with standard - non-modular repositories. If the pretrained_model_name_or_path does not contain any pipeline config, it will be set to None - during initialization. + non-modular repositories. If the pretrained_model_name_or_path does not contain any pipeline config, it + will be set to None during initialization. trust_remote_code (`bool`, optional): Whether to trust remote code when loading the pipeline, need to be set to True if you want to create pipeline blocks based on the custom code in `pretrained_model_name_or_path` @@ -2113,8 +2113,8 @@ def load_components(self, names: Optional[Union[List[str], str]] = None, **kwarg **kwargs: additional kwargs to be passed to `from_pretrained()`.Can be: - a single value to be applied to all components to be loaded, e.g. torch_dtype=torch.bfloat16 - a dict, e.g. torch_dtype={"unet": torch.bfloat16, "default": torch.float32} - - if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. `pretrained_model_name_or_path`, - `variant`, `revision`, etc. + - if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. + `pretrained_model_name_or_path`, `variant`, `revision`, etc. """ if names is None: @@ -2397,12 +2397,12 @@ def _component_spec_to_dict(component_spec: ComponentSpec) -> Any: Example: >>> from diffusers.pipelines.modular_pipeline_utils import ComponentSpec >>> from diffusers import UNet2DConditionModel >>> spec = ComponentSpec( - ... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... pretrained_model_name_or_path="path/to/repo", ... - subfolder="subfolder", ... variant=None, ... revision=None, ... - default_creation_method="from_pretrained", + ... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... + pretrained_model_name_or_path="path/to/repo", ... subfolder="subfolder", ... variant=None, ... + revision=None, ... default_creation_method="from_pretrained", ... ) >>> ModularPipeline._component_spec_to_dict(spec) { - "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", - "variant": None, "revision": None, + "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", + "subfolder": "subfolder", "variant": None, "revision": None, } """ if component_spec.default_creation_method != "from_pretrained": @@ -2451,11 +2451,13 @@ def _dict_to_component_spec( ComponentSpec: A reconstructed ComponentSpec object. Example: - >>> spec_dict = { ... "type_hint": ("diffusers", "UNet2DConditionModel"), ... "pretrained_model_name_or_path": - "stabilityai/stable-diffusion-xl", ... "subfolder": "unet", ... "variant": None, ... "revision": None, ... - } >>> ModularPipeline._dict_to_component_spec("unet", spec_dict) ComponentSpec( - name="unet", type_hint=UNet2DConditionModel, config=None, pretrained_model_name_or_path="stabilityai/stable-diffusion-xl", - subfolder="unet", variant=None, revision=None, default_creation_method="from_pretrained" + >>> spec_dict = { ... "type_hint": ("diffusers", "UNet2DConditionModel"), ... + "pretrained_model_name_or_path": "stabilityai/stable-diffusion-xl", ... "subfolder": "unet", ... "variant": + None, ... "revision": None, ... } >>> ModularPipeline._dict_to_component_spec("unet", spec_dict) + ComponentSpec( + name="unet", type_hint=UNet2DConditionModel, config=None, + pretrained_model_name_or_path="stabilityai/stable-diffusion-xl", subfolder="unet", variant=None, + revision=None, default_creation_method="from_pretrained" ) """ # make a shallow copy so we can pop() safely diff --git a/src/diffusers/modular_pipelines/modular_pipeline_utils.py b/src/diffusers/modular_pipelines/modular_pipeline_utils.py index aa22d963c683..379cabc44789 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline_utils.py +++ b/src/diffusers/modular_pipelines/modular_pipeline_utils.py @@ -183,8 +183,8 @@ def loading_fields(cls) -> List[str]: @property def load_id(self) -> str: """ - Unique identifier for this spec's pretrained load, composed of pretrained_model_name_or_path|subfolder|variant|revision (no empty - segments). + Unique identifier for this spec's pretrained load, composed of + pretrained_model_name_or_path|subfolder|variant|revision (no empty segments). """ if self.default_creation_method == "from_config": return "null" @@ -203,7 +203,8 @@ def decode_load_id(cls, load_id: str) -> Dict[str, Optional[str]]: Returns: Dict mapping loading field names to their values. e.g. { - "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", "variant": "variant", "revision": "revision" + "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", "variant": "variant", + "revision": "revision" } If a segment value is "null", it's replaced with None. Returns None if load_id is "null" (indicating component not created with `load` method). """ From 8733fef39dd41a2220732ed0f7b0db4f3736a153 Mon Sep 17 00:00:00 2001 From: Dhruv Nair Date: Thu, 23 Oct 2025 18:56:14 +0200 Subject: [PATCH 06/10] update --- docs/source/en/modular_diffusers/guiders.md | 2 +- .../en/modular_diffusers/modular_pipeline.md | 4 +-- docs/source/zh/modular_diffusers/guiders.md | 2 +- .../zh/modular_diffusers/modular_pipeline.md | 4 +-- src/diffusers/loaders/single_file_utils.py | 6 ++-- .../modular_pipelines/modular_pipeline.py | 30 ++++++++++--------- .../modular_pipeline_utils.py | 27 +++++++++++------ ...st_modular_pipeline_stable_diffusion_xl.py | 8 +++-- 8 files changed, 48 insertions(+), 35 deletions(-) diff --git a/docs/source/en/modular_diffusers/guiders.md b/docs/source/en/modular_diffusers/guiders.md index fd0d27844205..6abe4fad2736 100644 --- a/docs/source/en/modular_diffusers/guiders.md +++ b/docs/source/en/modular_diffusers/guiders.md @@ -159,7 +159,7 @@ Change the [`~ComponentSpec.default_creation_method`] to `from_pretrained` and u ```py guider_spec = t2i_pipeline.get_component_spec("guider") guider_spec.default_creation_method="from_pretrained" -guider_spec.repo="YiYiXu/modular-loader-t2i-guider" +guider_spec.pretrained_model_name_or_path="YiYiXu/modular-loader-t2i-guider" guider_spec.subfolder="pag_guider" pag_guider = guider_spec.load() t2i_pipeline.update_components(guider=pag_guider) diff --git a/docs/source/en/modular_diffusers/modular_pipeline.md b/docs/source/en/modular_diffusers/modular_pipeline.md index 0e0a7bd75d51..34cd8f72b5b7 100644 --- a/docs/source/en/modular_diffusers/modular_pipeline.md +++ b/docs/source/en/modular_diffusers/modular_pipeline.md @@ -313,14 +313,14 @@ unet_spec ComponentSpec( name='unet', type_hint=, - repo='RunDiffusion/Juggernaut-XL-v9', + pretrained_model_name_or_path='RunDiffusion/Juggernaut-XL-v9', subfolder='unet', variant='fp16', default_creation_method='from_pretrained' ) # modify to load from a different repository -unet_spec.repo = "stabilityai/stable-diffusion-xl-base-1.0" +unet_spec.pretrained_model_name_or_path = "stabilityai/stable-diffusion-xl-base-1.0" # load component with modified spec unet = unet_spec.load(torch_dtype=torch.float16) diff --git a/docs/source/zh/modular_diffusers/guiders.md b/docs/source/zh/modular_diffusers/guiders.md index 1006460a2bec..50436f90c4a5 100644 --- a/docs/source/zh/modular_diffusers/guiders.md +++ b/docs/source/zh/modular_diffusers/guiders.md @@ -157,7 +157,7 @@ guider.push_to_hub("YiYiXu/modular-loader-t2i-guider", subfolder="pag_guider") ```py guider_spec = t2i_pipeline.get_component_spec("guider") guider_spec.default_creation_method="from_pretrained" -guider_spec.repo="YiYiXu/modular-loader-t2i-guider" +guider_spec.pretrained_model_name_or_path="YiYiXu/modular-loader-t2i-guider" guider_spec.subfolder="pag_guider" pag_guider = guider_spec.load() t2i_pipeline.update_components(guider=pag_guider) diff --git a/docs/source/zh/modular_diffusers/modular_pipeline.md b/docs/source/zh/modular_diffusers/modular_pipeline.md index daf61ecf40d9..a57fdf227506 100644 --- a/docs/source/zh/modular_diffusers/modular_pipeline.md +++ b/docs/source/zh/modular_diffusers/modular_pipeline.md @@ -313,14 +313,14 @@ unet_spec ComponentSpec( name='unet', type_hint=, - repo='RunDiffusion/Juggernaut-XL-v9', + pretrained_model_name_or_path='RunDiffusion/Juggernaut-XL-v9', subfolder='unet', variant='fp16', default_creation_method='from_pretrained' ) # 修改以从不同的仓库加载 -unet_spec.repo = "stabilityai/stable-diffusion-xl-base-1.0" +unet_spec.pretrained_model_name_or_path = "stabilityai/stable-diffusion-xl-base-1.0" # 使用修改后的规范加载组件 unet = unet_spec.load(torch_dtype=torch.float16) diff --git a/src/diffusers/loaders/single_file_utils.py b/src/diffusers/loaders/single_file_utils.py index 2b67f91dc205..f88bb9407988 100644 --- a/src/diffusers/loaders/single_file_utils.py +++ b/src/diffusers/loaders/single_file_utils.py @@ -387,9 +387,9 @@ def is_valid_url(url): return False -def _validate_single_file_path(pretrained_model_name_or_path): - if os.path.isfile(pretrained_model_name_or_path): - return True +def _is_single_file_path_or_url(pretrained_model_name_or_path): + if not os.path.isfile(pretrained_model_name_or_path) or not is_valid_url(pretrained_model_name_or_path): + return False repo_id, weight_name = _extract_repo_id_and_weights_name(pretrained_model_name_or_path) return bool(repo_id and weight_name) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index 0b316676afd9..8e686d740f93 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -1639,8 +1639,8 @@ def from_pretrained( pretrained_model_name_or_path (`str` or `os.PathLike`, optional): Path to a pretrained pipeline configuration. It will first try to load config from `modular_model_index.json`, then fallback to `model_index.json` for compatibility with standard - non-modular repositories. If the pretrained_model_name_or_path does not contain any pipeline config, it will be set to None - during initialization. + non-modular repositories. If the pretrained_model_name_or_path does not contain any pipeline config, it + will be set to None during initialization. trust_remote_code (`bool`, optional): Whether to trust remote code when loading the pipeline, need to be set to True if you want to create pipeline blocks based on the custom code in `pretrained_model_name_or_path` @@ -2113,8 +2113,8 @@ def load_components(self, names: Optional[Union[List[str], str]] = None, **kwarg **kwargs: additional kwargs to be passed to `from_pretrained()`.Can be: - a single value to be applied to all components to be loaded, e.g. torch_dtype=torch.bfloat16 - a dict, e.g. torch_dtype={"unet": torch.bfloat16, "default": torch.float32} - - if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. `pretrained_model_name_or_path`, - `variant`, `revision`, etc. + - if potentially override ComponentSpec if passed a different loading field in kwargs, e.g. + `pretrained_model_name_or_path`, `variant`, `revision`, etc. """ if names is None: @@ -2397,12 +2397,12 @@ def _component_spec_to_dict(component_spec: ComponentSpec) -> Any: Example: >>> from diffusers.pipelines.modular_pipeline_utils import ComponentSpec >>> from diffusers import UNet2DConditionModel >>> spec = ComponentSpec( - ... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... pretrained_model_name_or_path="path/to/pretrained_model_name_or_path", ... - subfolder="subfolder", ... variant=None, ... revision=None, ... - default_creation_method="from_pretrained", + ... name="unet", ... type_hint=UNet2DConditionModel, ... config=None, ... + pretrained_model_name_or_path="path/to/pretrained_model_name_or_path", ... subfolder="subfolder", ... + variant=None, ... revision=None, ... default_creation_method="from_pretrained", ... ) >>> ModularPipeline._component_spec_to_dict(spec) { - "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", - "variant": None, "revision": None, + "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", + "subfolder": "subfolder", "variant": None, "revision": None, } """ if component_spec.default_creation_method != "from_pretrained": @@ -2451,11 +2451,13 @@ def _dict_to_component_spec( ComponentSpec: A reconstructed ComponentSpec object. Example: - >>> spec_dict = { ... "type_hint": ("diffusers", "UNet2DConditionModel"), ... "pretrained_model_name_or_path": - "stabilityai/stable-diffusion-xl", ... "subfolder": "unet", ... "variant": None, ... "revision": None, ... - } >>> ModularPipeline._dict_to_component_spec("unet", spec_dict) ComponentSpec( - name="unet", type_hint=UNet2DConditionModel, config=None, pretrained_model_name_or_path="stabilityai/stable-diffusion-xl", - subfolder="unet", variant=None, revision=None, default_creation_method="from_pretrained" + >>> spec_dict = { ... "type_hint": ("diffusers", "UNet2DConditionModel"), ... + "pretrained_model_name_or_path": "stabilityai/stable-diffusion-xl", ... "subfolder": "unet", ... "variant": + None, ... "revision": None, ... } >>> ModularPipeline._dict_to_component_spec("unet", spec_dict) + ComponentSpec( + name="unet", type_hint=UNet2DConditionModel, config=None, + pretrained_model_name_or_path="stabilityai/stable-diffusion-xl", subfolder="unet", variant=None, + revision=None, default_creation_method="from_pretrained" ) """ # make a shallow copy so we can pop() safely diff --git a/src/diffusers/modular_pipelines/modular_pipeline_utils.py b/src/diffusers/modular_pipelines/modular_pipeline_utils.py index aa22d963c683..aa421a53727b 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline_utils.py +++ b/src/diffusers/modular_pipelines/modular_pipeline_utils.py @@ -21,7 +21,7 @@ import torch from ..configuration_utils import ConfigMixin, FrozenDict -from ..loaders.single_file_utils import _validate_single_file_path +from ..loaders.single_file_utils import _is_single_file_path_or_url from ..utils import is_torch_available, logging @@ -92,13 +92,20 @@ class ComponentSpec: type_hint: Optional[Type] = None description: Optional[str] = None config: Optional[FrozenDict] = None - # YiYi Notes: should we change it to pretrained_model_name_or_path for consistency? a bit long for a field name pretrained_model_name_or_path: Optional[Union[str, List[str]]] = field(default=None, metadata={"loading": True}) subfolder: Optional[str] = field(default="", metadata={"loading": True}) variant: Optional[str] = field(default=None, metadata={"loading": True}) revision: Optional[str] = field(default=None, metadata={"loading": True}) default_creation_method: Literal["from_config", "from_pretrained"] = "from_pretrained" + # Deprecated + repo: Optional[Union[str, List[str]]] = field(default=None, metadata={"loading": False}) + + def __post_init__(self): + repo_value = self.repo + if repo_value is not None and self.pretrained_model_name_or_path is None: + object.__setattr__(self, "pretrained_model_name_or_path", repo_value) + def __hash__(self): """Make ComponentSpec hashable, using load_id as the hash value.""" return hash((self.name, self.load_id, self.default_creation_method)) @@ -183,8 +190,8 @@ def loading_fields(cls) -> List[str]: @property def load_id(self) -> str: """ - Unique identifier for this spec's pretrained load, composed of pretrained_model_name_or_path|subfolder|variant|revision (no empty - segments). + Unique identifier for this spec's pretrained load, composed of + pretrained_model_name_or_path|subfolder|variant|revision (no empty segments). """ if self.default_creation_method == "from_config": return "null" @@ -203,7 +210,8 @@ def decode_load_id(cls, load_id: str) -> Dict[str, Optional[str]]: Returns: Dict mapping loading field names to their values. e.g. { - "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", "variant": "variant", "revision": "revision" + "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", "variant": "variant", + "revision": "revision" } If a segment value is "null", it's replaced with None. Returns None if load_id is "null" (indicating component not created with `load` method). """ @@ -260,20 +268,21 @@ def create(self, config: Optional[Union[FrozenDict, Dict[str, Any]]] = None, **k # YiYi TODO: add guard for type of model, if it is supported by from_pretrained def load(self, **kwargs) -> Any: """Load component using from_pretrained.""" - # select loading fields from kwargs passed from user: e.g. pretrained_model_name_or_path, subfolder, variant, revision, note the list could change passed_loading_kwargs = {key: kwargs.pop(key) for key in self.loading_fields() if key in kwargs} # merge loading field value in the spec with user passed values to create load_kwargs load_kwargs = {key: passed_loading_kwargs.get(key, getattr(self, key)) for key in self.loading_fields()} - # pretrained_model_name_or_path is a required argument for from_pretrained, a.k.a. pretrained_model_name_or_path + pretrained_model_name_or_path = load_kwargs.pop("pretrained_model_name_or_path", None) if pretrained_model_name_or_path is None: raise ValueError( "`pretrained_model_name_or_path` info is required when using `load` method (you can directly set it in `pretrained_model_name_or_path` field of the ComponentSpec or pass it as an argument)" ) - is_single_file = _validate_single_file_path(pretrained_model_name_or_path) + is_single_file = _is_single_file_path_or_url(pretrained_model_name_or_path) if is_single_file and self.type_hint is None: - raise ValueError("type_hint is required when loading a single file model") + raise ValueError( + f"`type_hint` is required when loading a single file model but is missing for component: {self.name}" + ) if self.type_hint is None: try: diff --git a/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py b/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py index d05f818135ab..87730812f60a 100644 --- a/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py +++ b/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py @@ -51,7 +51,7 @@ class SDXLModularTests: pipeline_class = StableDiffusionXLModularPipeline pipeline_blocks_class = StableDiffusionXLAutoBlocks - repo = "hf-internal-testing/tiny-sdxl-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-sdxl-modular" params = frozenset( [ "prompt", @@ -66,7 +66,9 @@ class SDXLModularTests: batch_params = frozenset(["prompt", "negative_prompt", "image", "mask_image"]) def get_pipeline(self, components_manager=None, torch_dtype=torch.float32): - pipeline = self.pipeline_blocks_class().init_pipeline(self.repo, components_manager=components_manager) + pipeline = self.pipeline_blocks_class().init_pipeline( + self.pretrained_model_name_or_path, components_manager=components_manager + ) pipeline.load_components(torch_dtype=torch_dtype) return pipeline @@ -157,7 +159,7 @@ def test_ip_adapter(self, expected_max_diff: float = 1e-4, expected_pipe_slice=N blocks = self.pipeline_blocks_class() _ = blocks.sub_blocks.pop("ip_adapter") - pipe = blocks.init_pipeline(self.repo) + pipe = blocks.init_pipeline(self.pretrained_model_name_or_path) pipe.load_components(torch_dtype=torch.float32) pipe = pipe.to(torch_device) pipe.set_progress_bar_config(disable=None) From d391ace1cab3fc0c123bfec31f5ad463100c11e6 Mon Sep 17 00:00:00 2001 From: DN6 Date: Fri, 28 Nov 2025 15:52:22 +0530 Subject: [PATCH 07/10] update --- src/diffusers/modular_pipelines/modular_pipeline.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index bb76e2787533..a6336de71a52 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -2405,9 +2405,9 @@ def _component_spec_to_dict(component_spec: ComponentSpec) -> Any: variant=None, ... revision=None, ... default_creation_method="from_pretrained", ... ) >>> ModularPipeline._component_spec_to_dict(spec) { "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", - "subfolder": "subfolder", "variant": None, "revision": None, - "type_hint": ("diffusers", "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", - "subfolder": "subfolder", "variant": None, "revision": None, + "subfolder": "subfolder", "variant": None, "revision": None, "type_hint": ("diffusers", + "UNet2DConditionModel"), "pretrained_model_name_or_path": "path/to/repo", "subfolder": "subfolder", + "variant": None, "revision": None, } """ if component_spec.default_creation_method != "from_pretrained": From 2cd7256ecb19354c8eb27ffa12cd4b9a8864a5da Mon Sep 17 00:00:00 2001 From: DN6 Date: Fri, 28 Nov 2025 18:29:02 +0530 Subject: [PATCH 08/10] update --- .../test_modular_pipeline_stable_diffusion_xl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py b/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py index b58236949c02..7b55933e4caf 100644 --- a/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py +++ b/tests/modular_pipelines/stable_diffusion_xl/test_modular_pipeline_stable_diffusion_xl.py @@ -278,7 +278,7 @@ class TestSDXLModularPipelineFast( pipeline_class = StableDiffusionXLModularPipeline pipeline_blocks_class = StableDiffusionXLAutoBlocks - repo = "hf-internal-testing/tiny-sdxl-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-sdxl-modular" params = frozenset( [ "prompt", @@ -325,7 +325,7 @@ class TestSDXLImg2ImgModularPipelineFast( pipeline_class = StableDiffusionXLModularPipeline pipeline_blocks_class = StableDiffusionXLAutoBlocks - repo = "hf-internal-testing/tiny-sdxl-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-sdxl-modular" params = frozenset( [ "prompt", @@ -378,7 +378,7 @@ class SDXLInpaintingModularPipelineFastTests( pipeline_class = StableDiffusionXLModularPipeline pipeline_blocks_class = StableDiffusionXLAutoBlocks - repo = "hf-internal-testing/tiny-sdxl-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-sdxl-modular" params = frozenset( [ "prompt", From 207847552dbf790c11d291820c1b0b69499715d5 Mon Sep 17 00:00:00 2001 From: DN6 Date: Fri, 28 Nov 2025 18:52:39 +0530 Subject: [PATCH 09/10] update --- tests/modular_pipelines/test_modular_pipelines_common.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/modular_pipelines/test_modular_pipelines_common.py b/tests/modular_pipelines/test_modular_pipelines_common.py index 327ae77d59a5..5c1c4051ab95 100644 --- a/tests/modular_pipelines/test_modular_pipelines_common.py +++ b/tests/modular_pipelines/test_modular_pipelines_common.py @@ -43,7 +43,7 @@ def pipeline_class(self) -> Union[Callable, ModularPipeline]: ) @property - def repo(self) -> str: + def pretrained_model_name_or_path(self) -> str: raise NotImplementedError( "You need to set the attribute `repo` in the child test class. See existing pipeline tests for reference." ) @@ -103,7 +103,9 @@ def teardown_method(self): backend_empty_cache(torch_device) def get_pipeline(self, components_manager=None, torch_dtype=torch.float32): - pipeline = self.pipeline_blocks_class().init_pipeline(self.repo, components_manager=components_manager) + pipeline = self.pipeline_blocks_class().init_pipeline( + self.pretrained_model_name_or_path, components_manager=components_manager + ) pipeline.load_components(torch_dtype=torch_dtype) pipeline.set_progress_bar_config(disable=None) return pipeline From 15fb54de111e91b50fa6fc08789161cbbd6994b2 Mon Sep 17 00:00:00 2001 From: DN6 Date: Fri, 28 Nov 2025 21:34:32 +0530 Subject: [PATCH 10/10] update --- tests/modular_pipelines/flux/test_modular_pipeline_flux.py | 6 +++--- .../qwen/test_modular_pipeline_qwenimage.py | 6 +++--- tests/modular_pipelines/test_modular_pipelines_common.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/modular_pipelines/flux/test_modular_pipeline_flux.py b/tests/modular_pipelines/flux/test_modular_pipeline_flux.py index b136763e08bc..854b5218c617 100644 --- a/tests/modular_pipelines/flux/test_modular_pipeline_flux.py +++ b/tests/modular_pipelines/flux/test_modular_pipeline_flux.py @@ -36,7 +36,7 @@ class TestFluxModularPipelineFast(ModularPipelineTesterMixin): pipeline_class = FluxModularPipeline pipeline_blocks_class = FluxAutoBlocks - repo = "hf-internal-testing/tiny-flux-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-flux-modular" params = frozenset(["prompt", "height", "width", "guidance_scale"]) batch_params = frozenset(["prompt"]) @@ -62,7 +62,7 @@ def test_float16_inference(self): class TestFluxImg2ImgModularPipelineFast(ModularPipelineTesterMixin): pipeline_class = FluxModularPipeline pipeline_blocks_class = FluxAutoBlocks - repo = "hf-internal-testing/tiny-flux-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-flux-modular" params = frozenset(["prompt", "height", "width", "guidance_scale", "image"]) batch_params = frozenset(["prompt", "image"]) @@ -128,7 +128,7 @@ def test_float16_inference(self): class TestFluxKontextModularPipelineFast(ModularPipelineTesterMixin): pipeline_class = FluxKontextModularPipeline pipeline_blocks_class = FluxKontextAutoBlocks - repo = "hf-internal-testing/tiny-flux-kontext-pipe" + pretrained_model_name_or_path = "hf-internal-testing/tiny-flux-kontext-pipe" params = frozenset(["prompt", "height", "width", "guidance_scale", "image"]) batch_params = frozenset(["prompt", "image"]) diff --git a/tests/modular_pipelines/qwen/test_modular_pipeline_qwenimage.py b/tests/modular_pipelines/qwen/test_modular_pipeline_qwenimage.py index 772fa19927fb..8d7600781b24 100644 --- a/tests/modular_pipelines/qwen/test_modular_pipeline_qwenimage.py +++ b/tests/modular_pipelines/qwen/test_modular_pipeline_qwenimage.py @@ -32,7 +32,7 @@ class TestQwenImageModularPipelineFast(ModularPipelineTesterMixin, ModularGuiderTesterMixin): pipeline_class = QwenImageModularPipeline pipeline_blocks_class = QwenImageAutoBlocks - repo = "hf-internal-testing/tiny-qwenimage-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-qwenimage-modular" params = frozenset(["prompt", "height", "width", "negative_prompt", "attention_kwargs", "image", "mask_image"]) batch_params = frozenset(["prompt", "negative_prompt", "image", "mask_image"]) @@ -58,7 +58,7 @@ def test_inference_batch_single_identical(self): class TestQwenImageEditModularPipelineFast(ModularPipelineTesterMixin, ModularGuiderTesterMixin): pipeline_class = QwenImageEditModularPipeline pipeline_blocks_class = QwenImageEditAutoBlocks - repo = "hf-internal-testing/tiny-qwenimage-edit-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-qwenimage-edit-modular" params = frozenset(["prompt", "height", "width", "negative_prompt", "attention_kwargs", "image", "mask_image"]) batch_params = frozenset(["prompt", "negative_prompt", "image", "mask_image"]) @@ -84,7 +84,7 @@ def test_guider_cfg(self): class TestQwenImageEditPlusModularPipelineFast(ModularPipelineTesterMixin, ModularGuiderTesterMixin): pipeline_class = QwenImageEditPlusModularPipeline pipeline_blocks_class = QwenImageEditPlusAutoBlocks - repo = "hf-internal-testing/tiny-qwenimage-edit-plus-modular" + pretrained_model_name_or_path = "hf-internal-testing/tiny-qwenimage-edit-plus-modular" # No `mask_image` yet. params = frozenset(["prompt", "height", "width", "negative_prompt", "attention_kwargs", "image"]) diff --git a/tests/modular_pipelines/test_modular_pipelines_common.py b/tests/modular_pipelines/test_modular_pipelines_common.py index 5c1c4051ab95..a33951dac538 100644 --- a/tests/modular_pipelines/test_modular_pipelines_common.py +++ b/tests/modular_pipelines/test_modular_pipelines_common.py @@ -45,7 +45,7 @@ def pipeline_class(self) -> Union[Callable, ModularPipeline]: @property def pretrained_model_name_or_path(self) -> str: raise NotImplementedError( - "You need to set the attribute `repo` in the child test class. See existing pipeline tests for reference." + "You need to set the attribute `pretrained_model_name_or_path` in the child test class. See existing pipeline tests for reference." ) @property