A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 9, 20:45 UTC
Cleanup some huggingface_hub-related stuff (#32788)
Lucain committed
Jan 22, 2026 at 04:38 UTC
24a163ed77a4dba8f46221c945943f8a3ff7ee27
3 files changed
+9
-50
vllm/lora/utils.py
+2
-12
@@ -5,12 +5,7 @@ import os
5
from typing import TYPE_CHECKING, Optional
6
7
import huggingface_hub
8
-from huggingface_hub.utils import (
9
- EntryNotFoundError,
10
- HfHubHTTPError,
11
- HFValidationError,
12
- RepositoryNotFoundError,
13
-)
8
+from huggingface_hub.utils import HfHubHTTPError, HFValidationError
9
from torch import nn
10
from transformers import PretrainedConfig
11
@@ -243,12 +238,7 @@ def get_adapter_absolute_path(lora_path: str) -> str:
238
# If the path does not exist locally, assume it's a Hugging Face repo.
239
try:
240
local_snapshot_path = huggingface_hub.snapshot_download(repo_id=lora_path)
246
- except (
247
- HfHubHTTPError,
248
- RepositoryNotFoundError,
249
- EntryNotFoundError,
250
- HFValidationError,
251
- ):
241
+ except (HfHubHTTPError, HFValidationError):
242
# Handle errors that may occur during the download
243
# Return original path instead of throwing error here
244
logger.exception("Error downloading the HuggingFace model")
vllm/transformers_utils/config.py
+2
-13
@@ -33,7 +33,6 @@ from .gguf_utils import (
33
split_remote_gguf,
34
)
35
from .repo_utils import (
36
- _get_hf_token,
36
file_or_path_exists,
37
get_hf_file_to_dict,
38
list_repo_files,
@@ -135,7 +134,6 @@ class HFConfigParser(ConfigParserBase):
134
revision=revision,
135
code_revision=code_revision,
136
trust_remote_code=trust_remote_code,
138
- token=_get_hf_token(),
137
**kwargs,
138
)
139
# Use custom model class if it's in our registry
@@ -157,7 +155,6 @@ class HFConfigParser(ConfigParserBase):
155
revision=revision,
156
code_revision=code_revision,
157
trust_remote_code=trust_remote_code,
160
- token=_get_hf_token(),
158
**kwargs,
159
)
160
else:
@@ -168,7 +165,6 @@ class HFConfigParser(ConfigParserBase):
165
trust_remote_code=trust_remote_code,
166
revision=revision,
167
code_revision=code_revision,
171
- token=_get_hf_token(),
168
**kwargs,
169
)
170
except ValueError as e:
@@ -218,7 +214,6 @@ class MistralConfigParser(ConfigParserBase):
214
model,
215
revision=revision,
216
code_revision=code_revision,
221
- token=_get_hf_token(),
217
**kwargs,
218
)
219
except OSError: # Not found
@@ -529,7 +524,6 @@ def maybe_override_with_speculators(
524
model if gguf_model_repo is None else gguf_model_repo,
525
revision=revision,
526
trust_remote_code=trust_remote_code,
532
- token=_get_hf_token(),
527
**kwargs,
528
)
529
speculators_config = config_dict.get("speculators_config")
@@ -871,9 +865,7 @@ def get_sentence_transformer_tokenizer_config(
865
if not encoder_dict and not Path(model).is_absolute():
866
try:
867
# If model is on HuggingfaceHub, get the repo files
874
- repo_files = list_repo_files(
875
- model, revision=revision, token=_get_hf_token()
876
- )
868
+ repo_files = list_repo_files(model, revision=revision)
869
except Exception:
870
repo_files = []
871
@@ -1042,10 +1034,7 @@ def try_get_safetensors_metadata(
1034
revision: str | None = None,
1035
):
1036
get_safetensors_metadata_partial = partial(
1045
- get_safetensors_metadata,
1046
- model,
1047
- revision=revision,
1048
- token=_get_hf_token(),
1037
+ get_safetensors_metadata, model, revision=revision
1038
)
1039
1040
try:
vllm/transformers_utils/repo_utils.py
+5
-25
@@ -12,10 +12,7 @@ from pathlib import Path
12
from typing import TypeVar
13
14
import huggingface_hub
15
-from huggingface_hub import (
16
- hf_hub_download,
17
- try_to_load_from_cache,
18
-)
15
+from huggingface_hub import hf_hub_download, try_to_load_from_cache
16
from huggingface_hub import list_repo_files as hf_list_repo_files
17
from huggingface_hub.utils import (
18
EntryNotFoundError,
@@ -31,21 +28,6 @@ from vllm.logger import init_logger
28
logger = init_logger(__name__)
29
30
34
-def _get_hf_token() -> str | None:
35
- """
36
- Get the HuggingFace token from environment variable.
37
-
38
- Returns None if the token is not set, is an empty string,
39
- or contains only whitespace.
40
- This follows the same pattern as huggingface_hub library which
41
- treats empty string tokens as None to avoid authentication errors.
42
- """
43
- token = os.getenv("HF_TOKEN")
44
- if token and token.strip():
45
- return token
46
- return None
47
-
48
-
31
_R = TypeVar("_R")
32
33
@@ -153,6 +135,8 @@ def file_exists(
135
revision: str | None = None,
136
token: str | bool | None = None,
137
) -> bool:
138
+ # `list_repo_files` is cached and retried on error, so this is more efficient than
139
+ # huggingface_hub.file_exists default implementation when looking for multiple files
140
file_list = list_repo_files(
141
repo_id, repo_type=repo_type, revision=revision, token=token
142
)
@@ -178,9 +162,7 @@ def file_or_path_exists(
162
# hf_hub. This will fail in offline mode.
163
164
# Call HF to check if the file exists
181
- return file_exists(
182
- str(model), config_name, revision=revision, token=_get_hf_token()
183
- )
165
+ return file_exists(str(model), config_name, revision=revision)
166
167
168
def get_model_path(model: str | Path, revision: str | None = None):
@@ -209,9 +191,7 @@ def get_hf_file_bytes(
191
file_path = try_get_local_file(model=model, file_name=file_name, revision=revision)
192
193
if file_path is None:
212
- hf_hub_file = hf_hub_download(
213
- model, file_name, revision=revision, token=_get_hf_token()
214
- )
194
+ hf_hub_file = hf_hub_download(model, file_name, revision=revision)
195
file_path = Path(hf_hub_file)
196
197
if file_path is not None and file_path.is_file():