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
@@ -8,6 +8,7 @@ tqdm
|
||||
blake3
|
||||
py-cpuinfo
|
||||
transformers >= 5.5.3
|
||||
huggingface_hub >= 1.26.0
|
||||
tokenizers >= 0.21.1 # Required for fast incremental detokenization.
|
||||
safetensors >= 0.6.2 # MXFP4/MXFP6 dtype support (F8_E8M0, F4) added in 0.6.0: https://github.com/huggingface/safetensors/pull/611
|
||||
protobuf >= 5.29.6, !=6.30.*, !=6.31.*, !=6.32.*, !=6.33.0.*, !=6.33.1.*, !=6.33.2.*, !=6.33.3.*, !=6.33.4.* # Required by LlamaTokenizer, gRPC. CVE-2026-0994
|
||||
|
||||
@@ -341,8 +341,9 @@ httpx==0.27.2
|
||||
# schemathesis
|
||||
httpx-sse==0.4.3
|
||||
# via mcp
|
||||
huggingface-hub==1.22.0
|
||||
huggingface-hub==1.26.0
|
||||
# via
|
||||
# -r requirements/test/../common.txt
|
||||
# accelerate
|
||||
# datasets
|
||||
# evaluate
|
||||
|
||||
@@ -360,8 +360,10 @@ httpx==0.27.2
|
||||
# schemathesis
|
||||
httpx-sse==0.4.3
|
||||
# via mcp
|
||||
huggingface-hub==1.22.0
|
||||
huggingface-hub==1.26.0
|
||||
# via
|
||||
# -c requirements/common.txt
|
||||
# -r requirements/test/../common.txt
|
||||
# accelerate
|
||||
# datasets
|
||||
# evaluate
|
||||
|
||||
@@ -351,8 +351,10 @@ httpx==0.27.2
|
||||
# schemathesis
|
||||
httpx-sse==0.4.3
|
||||
# via mcp
|
||||
huggingface-hub==1.22.0
|
||||
huggingface-hub==1.26.0
|
||||
# via
|
||||
# -c requirements/common.txt
|
||||
# -r requirements/test/../common.txt
|
||||
# accelerate
|
||||
# datasets
|
||||
# evaluate
|
||||
|
||||
@@ -224,8 +224,10 @@ httpx==0.28.1
|
||||
# schemathesis
|
||||
httpx-sse==0.4.3
|
||||
# via mcp
|
||||
huggingface-hub==1.22.0
|
||||
huggingface-hub==1.26.0
|
||||
# via
|
||||
# -c requirements/common.txt
|
||||
# -r requirements/test/../common.txt
|
||||
# accelerate
|
||||
# datasets
|
||||
# evaluate
|
||||
|
||||
@@ -47,6 +47,7 @@ from vllm.transformers_utils.model_arch_config_convertor import (
|
||||
MODEL_ARCH_CONFIG_CONVERTORS,
|
||||
ModelArchConfigConvertorBase,
|
||||
)
|
||||
from vllm.transformers_utils.repo_utils import resolve_revision
|
||||
from vllm.transformers_utils.runai_utils import ObjectStorageModel, is_runai_obj_uri
|
||||
from vllm.transformers_utils.utils import maybe_model_redirect
|
||||
from vllm.utils.import_utils import LazyLoader
|
||||
@@ -529,6 +530,7 @@ class ModelConfig:
|
||||
self.served_model_name = get_served_model_name(
|
||||
self.model, self.served_model_name
|
||||
)
|
||||
requested_revision = self.revision
|
||||
self.model = maybe_model_redirect(self.model)
|
||||
# The tokenizer is consistent with the model by default.
|
||||
if self.tokenizer is None:
|
||||
@@ -558,6 +560,31 @@ class ModelConfig:
|
||||
|
||||
self.maybe_pull_model_tokenizer_for_runai(self.model, self.tokenizer)
|
||||
|
||||
# If loading model/tokenizer from HF Hub, resolve the revision once
|
||||
# to prevent resolving it multiple times downstream.
|
||||
can_resolve_model_revision = (
|
||||
self.hf_config_path is None or self.hf_config_path == self.model
|
||||
)
|
||||
if can_resolve_model_revision:
|
||||
self.revision = resolve_revision(
|
||||
self.model,
|
||||
self.revision,
|
||||
self.hf_token,
|
||||
)
|
||||
|
||||
if (
|
||||
can_resolve_model_revision
|
||||
and self.tokenizer == self.model
|
||||
and self.tokenizer_revision == requested_revision
|
||||
):
|
||||
self.tokenizer_revision = self.revision
|
||||
else:
|
||||
self.tokenizer_revision = resolve_revision(
|
||||
self.tokenizer,
|
||||
self.tokenizer_revision,
|
||||
self.hf_token,
|
||||
)
|
||||
|
||||
if self.override_attention_dtype is not None and not current_platform.is_rocm():
|
||||
warnings.warn(
|
||||
"override-attention-dtype is set but not using ROCm platform",
|
||||
|
||||
@@ -544,6 +544,8 @@ class UltravoxModel(nn.Module, SupportsMultiModal, SupportsPP, SupportsLoRA):
|
||||
[self.config.audio_token_index],
|
||||
)
|
||||
|
||||
# The towers live in their own Hub repos, so the revision of the
|
||||
# Ultravox repo does not apply to them.
|
||||
self.secondary_weights = []
|
||||
if config.audio_model_id is not None:
|
||||
# this prefix is not for initialization, but for loading weights
|
||||
@@ -551,7 +553,7 @@ class UltravoxModel(nn.Module, SupportsMultiModal, SupportsPP, SupportsLoRA):
|
||||
self.secondary_weights.append(
|
||||
DefaultModelLoader.Source(
|
||||
model_or_path=config.audio_model_id,
|
||||
revision=vllm_config.model_config.revision,
|
||||
revision=None,
|
||||
prefix="audio_tower.",
|
||||
)
|
||||
)
|
||||
@@ -561,7 +563,7 @@ class UltravoxModel(nn.Module, SupportsMultiModal, SupportsPP, SupportsLoRA):
|
||||
self.secondary_weights.append(
|
||||
DefaultModelLoader.Source(
|
||||
model_or_path=config.text_model_id,
|
||||
revision=vllm_config.model_config.revision,
|
||||
revision=None,
|
||||
prefix="language_model.",
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
|
||||
@@ -5553,7 +5553,10 @@ class GPUModelRunner(
|
||||
)
|
||||
|
||||
if weights_path is not None:
|
||||
# The revision belongs to the model we are reloading away from,
|
||||
# so it must not be carried over to the new path.
|
||||
self.model_config.model = weights_path
|
||||
self.model_config.revision = None
|
||||
weights_iterator = model_loader.get_all_weights(self.model_config, model)
|
||||
weights_iterator = cast(
|
||||
Iterable[tuple[str, torch.Tensor]], weights_iterator
|
||||
|
||||
Reference in New Issue
Block a user