From 581a425130bf8c23f747ca2f3559223d437b07c4 Mon Sep 17 00:00:00 2001 From: yiyixuxu Date: Sat, 24 Jan 2026 03:49:29 +0100 Subject: [PATCH] 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 c96b4fa88c..80e59d72a2 100644 --- a/src/diffusers/models/auto_model.py +++ b/src/diffusers/models/auto_model.py @@ -18,7 +18,7 @@ from typing import Optional, Union 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 @@ class AutoModel(ConfigMixin): 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 aa421a5372..2948e5bb09 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline_utils.py +++ b/src/diffusers/modular_pipelines/modular_pipeline_utils.py @@ -22,7 +22,7 @@ import torch 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 @@ class ComponentSpec: """ 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 @@ class ComponentSpec: 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 e726bbb469..86a08384dd 100644 --- a/src/diffusers/utils/__init__.py +++ b/src/diffusers/utils/__init__.py @@ -37,6 +37,7 @@ from .constants import ( 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 c46fa43634..cd4dd1d9de 100644 --- a/src/diffusers/utils/constants.py +++ b/src/diffusers/utils/constants.py @@ -73,3 +73,11 @@ DECODE_ENDPOINT_HUNYUAN_VIDEO = "https://o7ywnmrahorts457.us-east-1.aws.endpoint 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