Skip to content

Commit 87cffd5

Browse files
MNT Update HF Hub download kwargs (huggingface#2492)
1 parent 1083964 commit 87cffd5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/peft/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from typing import Optional, Union
2020

2121
from huggingface_hub import hf_hub_download
22-
from transformers.utils import PushToHubMixin
22+
from transformers.utils import PushToHubMixin, http_user_agent
2323

2424
from .utils import CONFIG_NAME, PeftType, TaskType
2525

@@ -190,6 +190,8 @@ def from_pretrained(cls, pretrained_model_name_or_path: str, subfolder: Optional
190190
)
191191

192192
hf_hub_download_kwargs, class_kwargs, _ = cls._split_kwargs(kwargs)
193+
if "user_agent" not in hf_hub_download_kwargs:
194+
hf_hub_download_kwargs["user_agent"] = http_user_agent()
193195

194196
if os.path.isfile(os.path.join(path, CONFIG_NAME)):
195197
config_file = os.path.join(path, CONFIG_NAME)

src/peft/utils/save_and_load.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from huggingface_hub import file_exists, hf_hub_download
2323
from huggingface_hub.errors import EntryNotFoundError, LocalEntryNotFoundError
2424
from safetensors.torch import load_file as safe_load_file
25+
from transformers.utils import http_user_agent
2526

2627
from peft.mapping import PEFT_TYPE_TO_PREFIX_MAPPING
2728

@@ -510,6 +511,9 @@ def get_hub_filename(use_safetensors=True):
510511
else weights_name
511512
)
512513

514+
if "user_agent" not in hf_hub_download_kwargs:
515+
hf_hub_download_kwargs["user_agent"] = http_user_agent()
516+
513517
if os.path.exists(os.path.join(path, SAFETENSORS_WEIGHTS_NAME)):
514518
filename = os.path.join(path, SAFETENSORS_WEIGHTS_NAME)
515519
use_safetensors = True

0 commit comments

Comments
 (0)