@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 139508a418
Fork 0

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 15, 03:30 UTC

[Misc] add handler HF_TOKEN is emptry string (#20369)

Signed-off-by: rongfu.leng <rongfu.leng@daocloud.io>

rongfu.leng committed Jul 3, 2025 at 00:14 UTC 139508a418a4185d50eef087d054b8115cb77542
1 file changed +22 -6
vllm/transformers_utils/config.py
+22 -6
@@ -56,6 +56,22 @@ MISTRAL_CONFIG_NAME = "params.json"
56
57 logger = init_logger(__name__)
58
59 +
60 +def _get_hf_token() -> Optional[str]:
61 + """
62 + Get the HuggingFace token from environment variable.
63 +
64 + Returns None if the token is not set, is an empty string,
65 + or contains only whitespace.
66 + This follows the same pattern as huggingface_hub library which
67 + treats empty string tokens as None to avoid authentication errors.
68 + """
69 + token = os.getenv('HF_TOKEN')
70 + if token and token.strip():
71 + return token
72 + return None
73 +
74 +
75 _CONFIG_REGISTRY_OVERRIDE_HF: dict[str, type[PretrainedConfig]] = {
76 "mllama": MllamaConfig
77 }
@@ -195,7 +211,7 @@ def file_or_path_exists(model: Union[str, Path], config_name: str,
211 return file_exists(str(model),
212 config_name,
213 revision=revision,
198 - token=os.getenv('HF_TOKEN', None))
214 + token=_get_hf_token())
215
216
217 def patch_rope_scaling(config: PretrainedConfig) -> None:
@@ -322,7 +338,7 @@ def get_config(
338 model,
339 revision=revision,
340 code_revision=code_revision,
325 - token=os.getenv('HF_TOKEN', None),
341 + token=_get_hf_token(),
342 **kwargs,
343 )
344
@@ -334,7 +350,7 @@ def get_config(
350 model,
351 revision=revision,
352 code_revision=code_revision,
337 - token=os.getenv('HF_TOKEN', None),
353 + token=_get_hf_token(),
354 **kwargs,
355 )
356 else:
@@ -344,7 +360,7 @@ def get_config(
360 trust_remote_code=trust_remote_code,
361 revision=revision,
362 code_revision=code_revision,
347 - token=os.getenv('HF_TOKEN', None),
363 + token=_get_hf_token(),
364 **kwargs,
365 )
366 except ValueError as e:
@@ -571,7 +587,7 @@ def get_sentence_transformer_tokenizer_config(model: str,
587 # If model is on HuggingfaceHub, get the repo files
588 repo_files = list_repo_files(model,
589 revision=revision,
574 - token=os.getenv('HF_TOKEN', None))
590 + token=_get_hf_token())
591 except Exception:
592 repo_files = []
593
@@ -862,7 +878,7 @@ def try_get_safetensors_metadata(
878 get_safetensors_metadata,
879 model,
880 revision=revision,
865 - token=os.getenv('HF_TOKEN', None),
881 + token=_get_hf_token(),
882 )
883
884 try: