From 165460941f5e82b8ddb344515163b43e537f9c3f Mon Sep 17 00:00:00 2001 From: Injae Ryou Date: Thu, 28 May 2026 00:53:32 +0900 Subject: [PATCH] [BugFix] HFValidationError with cloud storage URIs when HF_HUB_OFFLINE=1 (#39155) Signed-off-by: Injae Ryou --- tests/engine/test_arg_utils.py | 28 ++++++++++++++++++++++++++++ tests/test_config.py | 20 ++++++++++++++++++++ vllm/config/model.py | 2 +- vllm/engine/arg_utils.py | 23 ++++++++++++++--------- 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/tests/engine/test_arg_utils.py b/tests/engine/test_arg_utils.py index f595ca6ecb..9b21f3eebc 100644 --- a/tests/engine/test_arg_utils.py +++ b/tests/engine/test_arg_utils.py @@ -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" diff --git a/tests/test_config.py b/tests/test_config.py index 5c01d652a1..c0bd4b14ff 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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"), [ diff --git a/vllm/config/model.py b/vllm/config/model.py index 547ec342f9..811798859b 100644 --- a/vllm/config/model.py +++ b/vllm/config/model.py @@ -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 diff --git a/vllm/engine/arg_utils.py b/vllm/engine/arg_utils.py index 79c6e0ae92..0490cbc3e4 100644 --- a/vllm/engine/arg_utils.py +++ b/vllm/engine/arg_utils.py @@ -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: