Resolve revision to commit_hash once per model load, via huggingface_hub's resolve_revision (#49990)
Signed-off-by: Wauplin <lucainp@gmail.com> Signed-off-by: Lucain <lucainp@gmail.com> Signed-off-by: Lucain Pouget <lucain@huggingface.co> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
co-authored by
OpenAI Codex
Claude Opus 5
Harry Mellor
parent
a9b39d6dcb
commit
397094da17
@@ -49,6 +49,44 @@ def hf_fs() -> "huggingface_hub.HfFileSystem":
|
||||
)
|
||||
|
||||
|
||||
def resolve_revision(
|
||||
repo_id: str,
|
||||
revision: str | None = None,
|
||||
token: str | bool | None = None,
|
||||
) -> str | 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:
|
||||
The resolved revision, or `revision` unchanged if it cannot be resolved
|
||||
(local path, ModelScope, or any Hub error).
|
||||
"""
|
||||
if Path(repo_id).exists() or envs.VLLM_USE_MODELSCOPE:
|
||||
return revision
|
||||
|
||||
try:
|
||||
return hf_api().resolve_revision(
|
||||
repo_id,
|
||||
revision=revision,
|
||||
local_files_only=huggingface_hub.constants.HF_HUB_OFFLINE,
|
||||
token=token,
|
||||
)
|
||||
except Exception:
|
||||
logger.debug(
|
||||
"Failed to resolve revision for %s; falling back to %s.",
|
||||
repo_id,
|
||||
revision,
|
||||
exc_info=True,
|
||||
)
|
||||
return revision
|
||||
|
||||
|
||||
_R = TypeVar("_R")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user