vllm.transformers_utils.repo_utils ¶
Utilities for model repo interaction.
Functions:
-
get_hf_file_bytes–Get file contents from HuggingFace repository as bytes.
-
get_hf_file_to_dict–Downloads a file from the Hugging Face Hub and returns
-
hf_api–Return a shared HfApi instance tagged with vLLM's library info.
-
hf_fs–Return a fresh HfFileSystem tagged with vLLM's library info.
-
resolve_revision–Best-effort attempt to resolve a Hub revision to a commit hash.
-
try_get_local_file–Try to get a local file from the HuggingFace repository.
-
with_retry–Call
func, retrying transient failures.
_try_download_from_hf_hub(model, file_name, revision) ¶
Try to download a file from HuggingFace Hub.
Returns the local path on success, None on failure. Skips download if model is a local directory.
Source code in vllm/transformers_utils/repo_utils.py
get_hf_file_bytes(file_name, model, revision='main') ¶
Get file contents from HuggingFace repository as bytes.
Source code in vllm/transformers_utils/repo_utils.py
get_hf_file_to_dict(file_name, model, revision='main') ¶
Downloads a file from the Hugging Face Hub and returns its contents as a dictionary.
Parameters: - file_name (str): The name of the file to download. - model (str): The name of the model on the Hugging Face Hub. - revision (str): The specific version of the model.
Returns: - config_dict (dict): A dictionary containing the contents of the downloaded file.
Source code in vllm/transformers_utils/repo_utils.py
hf_api() ¶
Return a shared HfApi instance tagged with vLLM's library info.
hf_fs() ¶
Return a fresh HfFileSystem tagged with vLLM's library info.
resolve_revision(repo_id, revision=None, token=None) ¶
Best-effort attempt to resolve a Hub revision to a commit hash.
Resolving the commit hash once prevents repeated HTTP calls downstream and avoids races if the branch moves while the model is loading.
HfApi.resolve_revision returns a ResolvedRevision: a str equal to the requested revision that also carries the commit hash, so downstream error messages stay readable and offline loads reuse the cached refs/ entry.
Returns:
-
str | None–The resolved revision, or
revisionunchanged if it cannot be resolved -
str | None–(local path, ModelScope, or any Hub error).
Source code in vllm/transformers_utils/repo_utils.py
try_get_local_file(model, file_name, revision='main') ¶
Try to get a local file from the HuggingFace repository.
The possible return values are:
- A
Pathobject if the local file is found - The
huggingface_hub._CACHED_NO_EXISTsentinel if the file is known to not exist Noneif the file is not found and we cannot determine if it exists or not
Callers of this method should handle the _CACHED_NO_EXIST sentinel appropriately. Checking if the return value is not None is not sufficient because it does not distinguish between the file not existing and the file not being found.
Source code in vllm/transformers_utils/repo_utils.py
with_retry(func, log_msg, max_retries=2, retry_delay=2, fatal_errors=()) ¶
Call func, retrying transient failures.
Parameters:
-
(func¶Callable[[], _R]) –The call to make.
-
(log_msg¶str) –Prefix for the message logged when a call fails.
-
(max_retries¶int, default:2) –How many times to call
funcbefore giving up. -
(retry_delay¶int, default:2) –Seconds to wait after the first failure, doubled each time.
-
(fatal_errors¶tuple[type[Exception], ...], default:()) –Exceptions that are a definitive answer rather than a transient failure. These are raised immediately, without logging.