From f2b744f690e71756e0752255f3580b75f845ff95 Mon Sep 17 00:00:00 2001 From: Philipp Schmid <32632186+philschmid@users.noreply.github.com> Date: Fri, 19 Mar 2021 16:26:32 +0100 Subject: [PATCH] Add transformers id to hub requests (#10811) * add uuid.hext to user_agent * add log * changed order of it * renamed as session id * renamed variable * reverted naming of the const --- src/transformers/file_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/transformers/file_utils.py b/src/transformers/file_utils.py index 2aafdeec645..127a8c9eb0c 100644 --- a/src/transformers/file_utils.py +++ b/src/transformers/file_utils.py @@ -37,6 +37,7 @@ from pathlib import Path from types import ModuleType from typing import Any, BinaryIO, Dict, List, Optional, Tuple, Union from urllib.parse import urlparse +from uuid import uuid4 from zipfile import ZipFile, is_zipfile import numpy as np @@ -217,6 +218,7 @@ if ( PYTORCH_PRETRAINED_BERT_CACHE = os.getenv("PYTORCH_PRETRAINED_BERT_CACHE", default_cache_path) PYTORCH_TRANSFORMERS_CACHE = os.getenv("PYTORCH_TRANSFORMERS_CACHE", PYTORCH_PRETRAINED_BERT_CACHE) TRANSFORMERS_CACHE = os.getenv("TRANSFORMERS_CACHE", PYTORCH_TRANSFORMERS_CACHE) +SESSION_ID = uuid4().hex DISABLE_TELEMETRY = os.getenv("DISABLE_TELEMETRY", False) WEIGHTS_NAME = "pytorch_model.bin" @@ -1215,7 +1217,7 @@ def http_user_agent(user_agent: Union[Dict, str, None] = None) -> str: """ Formats a user-agent string with basic info about a request. """ - ua = "transformers/{}; python/{}".format(__version__, sys.version.split()[0]) + ua = f"transformers/{__version__}; python/{sys.version.split()[0]}; session_id/{SESSION_ID}" if is_torch_available(): ua += f"; torch/{_torch_version}" if is_tf_available():