From 581a425130bf8c23f747ca2f3559223d437b07c4 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sat, 24 Jan 2026 03:49:29 +0100 Subject: [PATCH 1/4] tag loader_id from Automodel --- src/diffusers/models/auto_model.py | 11 +++++++++-- .../modular_pipelines/modular_pipeline_utils.py | 6 +++--- src/diffusers/utils/__init__.py | 1 + src/diffusers/utils/constants.py | 8 ++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/diffusers/models/auto_model.py b/src/diffusers/models/auto_model.py index c96b4fa88c49..80e59d72a28b 100644 --- a/src/diffusers/models/auto_model.py +++ b/src/diffusers/models/auto_model.py @@ -18,7 +18,7 @@ from huggingface_hub.utils import validate_hf_hub_args from ..configuration_utils import ConfigMixin -from ..utils import logging +from ..utils import logging, DIFFUSERS_LOAD_ID_FIELDS from ..utils.dynamic_modules_utils import get_class_from_dynamic_module, resolve_trust_remote_code @@ -220,4 +220,11 @@ def from_pretrained(cls, pretrained_model_or_path: Optional[Union[str, os.PathLi raise ValueError(f"AutoModel can't find a model linked to {orig_class_name}.") kwargs = {**load_config_kwargs, **kwargs} - return model_cls.from_pretrained(pretrained_model_or_path, **kwargs) + model = model_cls.from_pretrained(pretrained_model_or_path, **kwargs) + + load_id_kwargs = {"pretrained_model_name_or_path": pretrained_model_or_path, **kwargs} + parts = [load_id_kwargs.get(field, "null") for field in DIFFUSERS_LOAD_ID_FIELDS] + load_id = "|".join("null" if p is None else p for p in parts) + model._diffusers_load_id = load_id + + return model \ No newline at end of file diff --git a/src/diffusers/modular_pipelines/modular_pipeline_utils.py b/src/diffusers/modular_pipelines/modular_pipeline_utils.py index aa421a53727b..2948e5bb0950 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline_utils.py +++ b/src/diffusers/modular_pipelines/modular_pipeline_utils.py @@ -22,7 +22,7 @@ from ..configuration_utils import ConfigMixin, FrozenDict from ..loaders.single_file_utils import _is_single_file_path_or_url -from ..utils import is_torch_available, logging +from ..utils import DIFFUSERS_LOAD_ID_FIELDS, is_torch_available, logging if is_torch_available(): @@ -185,7 +185,7 @@ def loading_fields(cls) -> List[str]: """ Return the names of all loading‐related fields (i.e. those whose field.metadata["loading"] is True). """ - return [f.name for f in fields(cls) if f.metadata.get("loading", False)] + return DIFFUSERS_LOAD_ID_FIELDS.copy() @property def load_id(self) -> str: @@ -197,7 +197,7 @@ def load_id(self) -> str: return "null" parts = [getattr(self, k) for k in self.loading_fields()] parts = ["null" if p is None else p for p in parts] - return "|".join(p for p in parts if p) + return "|".join(parts) @classmethod def decode_load_id(cls, load_id: str) -> Dict[str, Optional[str]]: diff --git a/src/diffusers/utils/__init__.py b/src/diffusers/utils/__init__.py index e726bbb46913..86a08384ddd9 100644 --- a/src/diffusers/utils/__init__.py +++ b/src/diffusers/utils/__init__.py @@ -37,6 +37,7 @@ USE_PEFT_BACKEND, WEIGHTS_INDEX_NAME, WEIGHTS_NAME, + DIFFUSERS_LOAD_ID_FIELDS, ) from .deprecation_utils import _maybe_remap_transformers_class, deprecate from .doc_utils import replace_example_docstring diff --git a/src/diffusers/utils/constants.py b/src/diffusers/utils/constants.py index c46fa4363483..cd4dd1d9ded8 100644 --- a/src/diffusers/utils/constants.py +++ b/src/diffusers/utils/constants.py @@ -73,3 +73,11 @@ ENCODE_ENDPOINT_SD_V1 = "https://qc6479g0aac6qwy9.us-east-1.aws.endpoints.huggingface.cloud/" ENCODE_ENDPOINT_SD_XL = "https://xjqqhmyn62rog84g.us-east-1.aws.endpoints.huggingface.cloud/" ENCODE_ENDPOINT_FLUX = "https://ptccx55jz97f9zgo.us-east-1.aws.endpoints.huggingface.cloud/" + + +DIFFUSERS_LOAD_ID_FIELDS = [ + "pretrained_model_name_or_path", + "subfolder", + "variant", + "revision", +] \ No newline at end of file From 1f57b175ae5acd5cbe28a9918f5c4a5b97001940 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sat, 24 Jan 2026 03:50:01 +0100 Subject: [PATCH 2/4] style --- src/diffusers/models/auto_model.py | 4 ++-- src/diffusers/modular_pipelines/modular_pipeline_utils.py | 2 +- src/diffusers/utils/__init__.py | 2 +- src/diffusers/utils/constants.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/diffusers/models/auto_model.py b/src/diffusers/models/auto_model.py index 80e59d72a28b..0a5b7fff1c66 100644 --- a/src/diffusers/models/auto_model.py +++ b/src/diffusers/models/auto_model.py @@ -18,7 +18,7 @@ from huggingface_hub.utils import validate_hf_hub_args from ..configuration_utils import ConfigMixin -from ..utils import logging, DIFFUSERS_LOAD_ID_FIELDS +from ..utils import DIFFUSERS_LOAD_ID_FIELDS, logging from ..utils.dynamic_modules_utils import get_class_from_dynamic_module, resolve_trust_remote_code @@ -227,4 +227,4 @@ def from_pretrained(cls, pretrained_model_or_path: Optional[Union[str, os.PathLi load_id = "|".join("null" if p is None else p for p in parts) model._diffusers_load_id = load_id - return model \ No newline at end of file + return model diff --git a/src/diffusers/modular_pipelines/modular_pipeline_utils.py b/src/diffusers/modular_pipelines/modular_pipeline_utils.py index 2948e5bb0950..15dc0913fec6 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline_utils.py +++ b/src/diffusers/modular_pipelines/modular_pipeline_utils.py @@ -15,7 +15,7 @@ import inspect import re from collections import OrderedDict -from dataclasses import dataclass, field, fields +from dataclasses import dataclass, field from typing import Any, Dict, List, Literal, Optional, Type, Union import torch diff --git a/src/diffusers/utils/__init__.py b/src/diffusers/utils/__init__.py index 86a08384ddd9..3f736e2ee39b 100644 --- a/src/diffusers/utils/__init__.py +++ b/src/diffusers/utils/__init__.py @@ -23,6 +23,7 @@ DEFAULT_HF_PARALLEL_LOADING_WORKERS, DEPRECATED_REVISION_ARGS, DIFFUSERS_DYNAMIC_MODULE_NAME, + DIFFUSERS_LOAD_ID_FIELDS, FLAX_WEIGHTS_NAME, GGUF_FILE_EXTENSION, HF_ENABLE_PARALLEL_LOADING, @@ -37,7 +38,6 @@ USE_PEFT_BACKEND, WEIGHTS_INDEX_NAME, WEIGHTS_NAME, - DIFFUSERS_LOAD_ID_FIELDS, ) from .deprecation_utils import _maybe_remap_transformers_class, deprecate from .doc_utils import replace_example_docstring diff --git a/src/diffusers/utils/constants.py b/src/diffusers/utils/constants.py index cd4dd1d9ded8..4f94df656a65 100644 --- a/src/diffusers/utils/constants.py +++ b/src/diffusers/utils/constants.py @@ -80,4 +80,4 @@ "subfolder", "variant", "revision", -] \ No newline at end of file +] From 372222a4b6ddbbf57def87b230c3a21d96dc4652 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sat, 24 Jan 2026 05:42:51 +0100 Subject: [PATCH 3/4] load_components by default only load components that are not already loaded --- src/diffusers/modular_pipelines/modular_pipeline.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index d857fd040955..38fc0dbd3f50 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -2142,6 +2142,7 @@ def load_components(self, names: Optional[Union[List[str], str]] = None, **kwarg name for name in self._component_specs.keys() if self._component_specs[name].default_creation_method == "from_pretrained" + and getattr(self, name, None) is None ] elif isinstance(names, str): names = [names] From e77f1c56dcb84096b69510fb7619124fc6e871e5 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sat, 24 Jan 2026 05:56:09 +0100 Subject: [PATCH 4/4] by default, skip loading the componeneets does not have the repo id --- src/diffusers/modular_pipelines/modular_pipeline.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index 38fc0dbd3f50..ba1b8d232e7c 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -2142,6 +2142,7 @@ def load_components(self, names: Optional[Union[List[str], str]] = None, **kwarg name for name in self._component_specs.keys() if self._component_specs[name].default_creation_method == "from_pretrained" + and self._component_specs[name].pretrained_model_name_or_path is not None and getattr(self, name, None) is None ] elif isinstance(names, str):