From 415f921471cf23984e7c4d64fc3bde9620c513be Mon Sep 17 00:00:00 2001 From: anton-l Date: Wed, 12 Oct 2022 17:18:32 +0200 Subject: [PATCH 1/5] Add diffusers version and pipeline class to the Hub UA --- src/diffusers/modeling_flax_utils.py | 9 +++++++-- src/diffusers/modeling_utils.py | 8 +++++++- src/diffusers/pipeline_utils.py | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/diffusers/modeling_flax_utils.py b/src/diffusers/modeling_flax_utils.py index 28cd29d2264e..071f88283d59 100644 --- a/src/diffusers/modeling_flax_utils.py +++ b/src/diffusers/modeling_flax_utils.py @@ -27,7 +27,7 @@ from huggingface_hub.utils import EntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError from requests import HTTPError -from . import is_torch_available +from . import __version__, is_torch_available from .modeling_flax_pytorch_utils import convert_pytorch_state_dict_to_flax from .utils import ( CONFIG_NAME, @@ -289,7 +289,12 @@ def from_pretrained( from_auto_class = kwargs.pop("_from_auto", False) subfolder = kwargs.pop("subfolder", None) - user_agent = {"file_type": "model", "framework": "flax", "from_auto_class": from_auto_class} + user_agent = { + "diffusers": __version__, + "file_type": "model", + "framework": "flax", + "from_auto_class": from_auto_class, + } # Load config if we don't provide a configuration config_path = config if config is not None else pretrained_model_name_or_path diff --git a/src/diffusers/modeling_utils.py b/src/diffusers/modeling_utils.py index 8bb5e728c17b..5d28b8425a58 100644 --- a/src/diffusers/modeling_utils.py +++ b/src/diffusers/modeling_utils.py @@ -26,6 +26,7 @@ from huggingface_hub.utils import EntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError from requests import HTTPError +from . import __version__ from .utils import CONFIG_NAME, DIFFUSERS_CACHE, HUGGINGFACE_CO_RESOLVE_ENDPOINT, WEIGHTS_NAME, logging @@ -297,7 +298,12 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P subfolder = kwargs.pop("subfolder", None) device_map = kwargs.pop("device_map", None) - user_agent = {"file_type": "model", "framework": "pytorch", "from_auto_class": from_auto_class} + user_agent = { + "diffusers": __version__, + "file_type": "model", + "framework": "pytorch", + "from_auto_class": from_auto_class, + } # Load config if we don't provide a configuration config_path = pretrained_model_name_or_path diff --git a/src/diffusers/pipeline_utils.py b/src/diffusers/pipeline_utils.py index a7b6031d137a..7a5c877c62f5 100644 --- a/src/diffusers/pipeline_utils.py +++ b/src/diffusers/pipeline_utils.py @@ -29,6 +29,7 @@ from PIL import Image from tqdm.auto import tqdm +from . import __version__ from .configuration_utils import ConfigMixin from .dynamic_modules_utils import get_class_from_dynamic_module from .schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME @@ -373,6 +374,10 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P if custom_pipeline is not None: allow_patterns += [CUSTOM_PIPELINE_FILE_NAME] + user_agent = {"diffusers": __version__, "pipeline_class": config_dict["_class_name"]} + if custom_pipeline is not None: + user_agent["custom_pipeline"] = custom_pipeline + # download all allow_patterns cached_folder = snapshot_download( pretrained_model_name_or_path, @@ -383,6 +388,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P use_auth_token=use_auth_token, revision=revision, allow_patterns=allow_patterns, + user_agent=user_agent, ) else: cached_folder = pretrained_model_name_or_path From f639c518f59f0f59eb61b8772b117e7014eb6a17 Mon Sep 17 00:00:00 2001 From: anton-l Date: Wed, 12 Oct 2022 17:33:46 +0200 Subject: [PATCH 2/5] Fallback to class name for pipelines --- src/diffusers/pipeline_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diffusers/pipeline_utils.py b/src/diffusers/pipeline_utils.py index 7a5c877c62f5..987252e9d219 100644 --- a/src/diffusers/pipeline_utils.py +++ b/src/diffusers/pipeline_utils.py @@ -374,7 +374,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P if custom_pipeline is not None: allow_patterns += [CUSTOM_PIPELINE_FILE_NAME] - user_agent = {"diffusers": __version__, "pipeline_class": config_dict["_class_name"]} + requested_pipeline_class = config_dict.get("_class_name", cls.__name__) + user_agent = {"diffusers": __version__, "pipeline_class": requested_pipeline_class} if custom_pipeline is not None: user_agent["custom_pipeline"] = custom_pipeline From abbe58faa92b9e9ed71fd0184540e8ba8ec3ab7b Mon Sep 17 00:00:00 2001 From: Anton Lozhkov Date: Wed, 12 Oct 2022 18:08:54 +0200 Subject: [PATCH 3/5] Update src/diffusers/modeling_utils.py Co-authored-by: Patrick von Platen --- src/diffusers/modeling_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/diffusers/modeling_utils.py b/src/diffusers/modeling_utils.py index 5d28b8425a58..a1716202d3f6 100644 --- a/src/diffusers/modeling_utils.py +++ b/src/diffusers/modeling_utils.py @@ -302,7 +302,6 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P "diffusers": __version__, "file_type": "model", "framework": "pytorch", - "from_auto_class": from_auto_class, } # Load config if we don't provide a configuration From def8991e28947d1be796f4dbba0a9206d6d4e678 Mon Sep 17 00:00:00 2001 From: Anton Lozhkov Date: Wed, 12 Oct 2022 18:09:04 +0200 Subject: [PATCH 4/5] Update src/diffusers/modeling_flax_utils.py Co-authored-by: Patrick von Platen --- src/diffusers/modeling_flax_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/diffusers/modeling_flax_utils.py b/src/diffusers/modeling_flax_utils.py index 071f88283d59..f4ce4d7a788d 100644 --- a/src/diffusers/modeling_flax_utils.py +++ b/src/diffusers/modeling_flax_utils.py @@ -293,7 +293,6 @@ def from_pretrained( "diffusers": __version__, "file_type": "model", "framework": "flax", - "from_auto_class": from_auto_class, } # Load config if we don't provide a configuration From 6bec382120b4b5235b347df91ed5538373b72373 Mon Sep 17 00:00:00 2001 From: anton-l Date: Wed, 12 Oct 2022 18:16:18 +0200 Subject: [PATCH 5/5] Remove autoclass --- src/diffusers/modeling_flax_utils.py | 1 - src/diffusers/modeling_utils.py | 1 - 2 files changed, 2 deletions(-) diff --git a/src/diffusers/modeling_flax_utils.py b/src/diffusers/modeling_flax_utils.py index f4ce4d7a788d..6cb30a26f7d5 100644 --- a/src/diffusers/modeling_flax_utils.py +++ b/src/diffusers/modeling_flax_utils.py @@ -286,7 +286,6 @@ def from_pretrained( local_files_only = kwargs.pop("local_files_only", False) use_auth_token = kwargs.pop("use_auth_token", None) revision = kwargs.pop("revision", None) - from_auto_class = kwargs.pop("_from_auto", False) subfolder = kwargs.pop("subfolder", None) user_agent = { diff --git a/src/diffusers/modeling_utils.py b/src/diffusers/modeling_utils.py index a1716202d3f6..c62caf80286e 100644 --- a/src/diffusers/modeling_utils.py +++ b/src/diffusers/modeling_utils.py @@ -293,7 +293,6 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P local_files_only = kwargs.pop("local_files_only", False) use_auth_token = kwargs.pop("use_auth_token", None) revision = kwargs.pop("revision", None) - from_auto_class = kwargs.pop("_from_auto", False) torch_dtype = kwargs.pop("torch_dtype", None) subfolder = kwargs.pop("subfolder", None) device_map = kwargs.pop("device_map", None)