Skip to content

Commit 16fed0e

Browse files
anton-lPrathik Rao
authored andcommitted
Add diffusers version and pipeline class to the Hub UA
1 parent ac50fe1 commit 16fed0e

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/diffusers/modeling_flax_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from huggingface_hub.utils import EntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError
2828
from requests import HTTPError
2929

30-
from . import is_torch_available
30+
from . import __version__, is_torch_available
3131
from .modeling_flax_pytorch_utils import convert_pytorch_state_dict_to_flax
3232
from .utils import (
3333
CONFIG_NAME,
@@ -289,7 +289,12 @@ def from_pretrained(
289289
from_auto_class = kwargs.pop("_from_auto", False)
290290
subfolder = kwargs.pop("subfolder", None)
291291

292-
user_agent = {"file_type": "model", "framework": "flax", "from_auto_class": from_auto_class}
292+
user_agent = {
293+
"diffusers": __version__,
294+
"file_type": "model",
295+
"framework": "flax",
296+
"from_auto_class": from_auto_class,
297+
}
293298

294299
# Load config if we don't provide a configuration
295300
config_path = config if config is not None else pretrained_model_name_or_path

src/diffusers/modeling_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from huggingface_hub.utils import EntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError
2727
from requests import HTTPError
2828

29+
from . import __version__
2930
from .utils import CONFIG_NAME, DIFFUSERS_CACHE, HUGGINGFACE_CO_RESOLVE_ENDPOINT, WEIGHTS_NAME, logging
3031

3132

@@ -297,7 +298,12 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
297298
subfolder = kwargs.pop("subfolder", None)
298299
device_map = kwargs.pop("device_map", None)
299300

300-
user_agent = {"file_type": "model", "framework": "pytorch", "from_auto_class": from_auto_class}
301+
user_agent = {
302+
"diffusers": __version__,
303+
"file_type": "model",
304+
"framework": "pytorch",
305+
"from_auto_class": from_auto_class,
306+
}
301307

302308
# Load config if we don't provide a configuration
303309
config_path = pretrained_model_name_or_path

src/diffusers/pipeline_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from PIL import Image
3030
from tqdm.auto import tqdm
3131

32+
from . import __version__
3233
from .configuration_utils import ConfigMixin
3334
from .dynamic_modules_utils import get_class_from_dynamic_module
3435
from .schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
@@ -375,6 +376,10 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
375376
if custom_pipeline is not None:
376377
allow_patterns += [CUSTOM_PIPELINE_FILE_NAME]
377378

379+
user_agent = {"diffusers": __version__, "pipeline_class": config_dict["_class_name"]}
380+
if custom_pipeline is not None:
381+
user_agent["custom_pipeline"] = custom_pipeline
382+
378383
# download all allow_patterns
379384
cached_folder = snapshot_download(
380385
pretrained_model_name_or_path,
@@ -385,6 +390,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P
385390
use_auth_token=use_auth_token,
386391
revision=revision,
387392
allow_patterns=allow_patterns,
393+
user_agent=user_agent,
388394
)
389395
else:
390396
cached_folder = pretrained_model_name_or_path

0 commit comments

Comments
 (0)