[BugFix] HFValidationError with cloud storage URIs when HF_HUB_OFFLINE=1 (#39155)
Signed-off-by: Injae Ryou <injaeryou@gmail.com>
This commit is contained in:
@@ -613,3 +613,31 @@ def test_ir_op_priority():
|
||||
)
|
||||
def test_expand_json_human_readable_numbers(input_json, expected_json):
|
||||
assert _expand_json_human_readable_numbers(input_json) == expected_json
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"uri",
|
||||
["s3://bucket/model", "gs://bucket/model", "az://container/model"],
|
||||
)
|
||||
def test_cloud_storage_uri_skips_get_model_path(uri, monkeypatch):
|
||||
"""Cloud storage URIs should not be passed to get_model_path()
|
||||
when HF_HUB_OFFLINE=1, as they are not valid HF repo IDs."""
|
||||
import huggingface_hub
|
||||
|
||||
monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_OFFLINE", True)
|
||||
|
||||
args = EngineArgs(model=uri)
|
||||
# model should remain the original cloud URI, not raise
|
||||
assert args.model == uri
|
||||
|
||||
|
||||
def test_cloud_storage_tokenizer_skips_get_model_path(monkeypatch):
|
||||
"""Cloud storage tokenizer URI should not be passed to
|
||||
get_model_path() when HF_HUB_OFFLINE=1."""
|
||||
import huggingface_hub
|
||||
|
||||
monkeypatch.setattr(huggingface_hub.constants, "HF_HUB_OFFLINE", True)
|
||||
|
||||
args = EngineArgs(model="s3://bucket/model", tokenizer="s3://bucket/tokenizer")
|
||||
assert args.model == "s3://bucket/model"
|
||||
assert args.tokenizer == "s3://bucket/tokenizer"
|
||||
|
||||
@@ -754,6 +754,26 @@ def test_s3_url_different_models_create_different_directories(mock_pull_files):
|
||||
assert os.path.exists(config2.tokenizer) and os.path.isdir(config2.tokenizer)
|
||||
|
||||
|
||||
@patch("vllm.transformers_utils.runai_utils.ObjectStorageModel.pull_files")
|
||||
def test_s3_url_different_model_and_tokenizer(mock_pull_files):
|
||||
"""Test that when model and tokenizer are different cloud URIs,
|
||||
pull_files receives the correct URI for each."""
|
||||
mock_pull_files.return_value = None
|
||||
|
||||
model_url = "s3://bucket/model/"
|
||||
tokenizer_url = "s3://bucket/tokenizer/"
|
||||
|
||||
config = MockConfig(model=model_url, tokenizer=tokenizer_url)
|
||||
ModelConfig.maybe_pull_model_tokenizer_for_runai(config, model_url, tokenizer_url)
|
||||
|
||||
# pull_files should be called twice: once for model, once for tokenizer
|
||||
assert mock_pull_files.call_count == 2
|
||||
# First call: model URI with allow_pattern
|
||||
assert mock_pull_files.call_args_list[0][0][0] == model_url
|
||||
# Second call: tokenizer URI with ignore_pattern
|
||||
assert mock_pull_files.call_args_list[1][0][0] == tokenizer_url
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("model_id", "expected_attn_type", "expected_result", "reason"),
|
||||
[
|
||||
|
||||
@@ -888,7 +888,7 @@ class ModelConfig:
|
||||
if is_runai_obj_uri(tokenizer):
|
||||
object_storage_tokenizer = ObjectStorageModel(url=tokenizer)
|
||||
object_storage_tokenizer.pull_files(
|
||||
model,
|
||||
tokenizer,
|
||||
ignore_pattern=["*.pt", "*.safetensors", "*.bin", "*.tensors", "*.pth"],
|
||||
)
|
||||
self.tokenizer = object_storage_tokenizer.dir
|
||||
|
||||
@@ -747,15 +747,20 @@ class EngineArgs:
|
||||
load_general_plugins()
|
||||
# when use hf offline,replace model and tokenizer id to local model path
|
||||
if huggingface_hub.constants.HF_HUB_OFFLINE:
|
||||
model_id = self.model
|
||||
self.model = get_model_path(self.model, self.revision)
|
||||
if model_id is not self.model:
|
||||
logger.info(
|
||||
"HF_HUB_OFFLINE is True, replace model_id [%s] to model_path [%s]",
|
||||
model_id,
|
||||
self.model,
|
||||
)
|
||||
if self.tokenizer is not None:
|
||||
# Skip cloud storage URIs (s3://, gs://, az://) — they are not
|
||||
# HF repo IDs and will be resolved later by
|
||||
# ModelConfig.maybe_pull_model_tokenizer_for_runai().
|
||||
if not is_cloud_storage(self.model):
|
||||
model_id = self.model
|
||||
self.model = get_model_path(self.model, self.revision)
|
||||
if model_id is not self.model:
|
||||
logger.info(
|
||||
"HF_HUB_OFFLINE is True, replace model_id "
|
||||
"[%s] to model_path [%s]",
|
||||
model_id,
|
||||
self.model,
|
||||
)
|
||||
if self.tokenizer is not None and not is_cloud_storage(self.tokenizer):
|
||||
tokenizer_id = self.tokenizer
|
||||
self.tokenizer = get_model_path(self.tokenizer, self.tokenizer_revision)
|
||||
if tokenizer_id is not self.tokenizer:
|
||||
|
||||
Reference in New Issue
Block a user