[CI] Don't try and download files that we already know don't exist (#46854)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Harry Mellor committed
Jun 27, 2026 at 00:56 UTC
3f674774970225a4aaaa7272a56b3a4c4604eaa7
3 files changed
+55
-9
tests/transformers_utils/test_repo_utils.py
+29
@@ -7,9 +7,11 @@ from pathlib import Path
7
from unittest.mock import MagicMock, call, patch
8
9
import pytest
10
+from huggingface_hub import _CACHED_NO_EXIST
11
12
from vllm.transformers_utils.repo_utils import (
13
any_pattern_in_repo_files,
14
+ get_hf_file_to_dict,
15
is_mistral_model_repo,
16
list_filtered_repo_files,
17
)
@@ -115,6 +117,33 @@ def test_one_filtered_repo_files(allow_patterns: list[str], expected_bool: bool)
117
)
118
119
120
+@pytest.mark.parametrize(
121
+ ("cache_result", "should_download"),
122
+ [
123
+ # HF Hub recorded a prior 404: don't re-probe the Hub.
124
+ (_CACHED_NO_EXIST, False),
125
+ # File not in cache and existence unknown: preserve download behavior.
126
+ (None, True),
127
+ ],
128
+)
129
+def test_get_hf_file_to_dict_honors_no_exist_marker(
130
+ cache_result: object, should_download: bool
131
+):
132
+ with (
133
+ patch(
134
+ "vllm.transformers_utils.repo_utils.try_to_load_from_cache",
135
+ MagicMock(return_value=cache_result),
136
+ ),
137
+ patch(
138
+ "vllm.transformers_utils.repo_utils._try_download_from_hf_hub",
139
+ MagicMock(return_value=None),
140
+ ) as mock_download,
141
+ ):
142
+ result = get_hf_file_to_dict("processor_config.json", "some/repo")
143
+ assert result is None
144
+ assert mock_download.call_count == int(should_download)
145
+
146
+
147
@pytest.mark.parametrize(
148
("files", "expected_bool"),
149
[
vllm/transformers_utils/config.py
+3
-3
@@ -896,9 +896,9 @@ def get_sentence_transformer_tokenizer_config(
896
encoder_dict = None
897
898
for config_file in sentence_transformer_config_files:
899
- if (
900
- try_get_local_file(model=model, file_name=config_file, revision=revision)
901
- is not None
899
+ if isinstance(
900
+ try_get_local_file(model=model, file_name=config_file, revision=revision),
901
+ Path,
902
):
903
encoder_dict = get_hf_file_to_dict(config_file, model, revision)
904
if encoder_dict:
vllm/transformers_utils/repo_utils.py
+23
-6
@@ -9,7 +9,7 @@ import time
9
from collections.abc import Callable
10
from functools import cache
11
from pathlib import Path
12
-from typing import TypeVar
12
+from typing import Any, TypeVar
13
14
import huggingface_hub
15
from huggingface_hub import HfApi, try_to_load_from_cache
@@ -218,8 +218,11 @@ def file_or_path_exists(
218
# NB: file_exists will only check for the existence of the config file on
219
# hf_hub. This will fail in offline mode.
220
221
- # Call HF to check if the file exists
222
- return file_exists(str(model), config_name, revision=revision)
221
+ if cached_filepath is None:
222
+ # The config file is not cached - check if it exists on hf_hub
223
+ return file_exists(str(model), config_name, revision=revision)
224
+ # The config file is known to not exist in cache - we can return False
225
+ return False
226
227
228
def get_model_path(model: str | Path, revision: str | None = None):
@@ -288,7 +291,7 @@ def get_hf_file_bytes(
291
if file_path is None:
292
file_path = _try_download_from_hf_hub(model, file_name, revision)
293
291
- if file_path is not None and file_path.is_file():
294
+ if isinstance(file_path, Path) and file_path.is_file():
295
with open(file_path, "rb") as file:
296
return file.read()
297
@@ -297,7 +300,20 @@ def get_hf_file_bytes(
300
301
def try_get_local_file(
302
model: str | Path, file_name: str, revision: str | None = "main"
300
-) -> Path | None:
303
+) -> Path | Any | None:
304
+ """
305
+ Try to get a local file from the HuggingFace repository.
306
+
307
+ The possible return values are:
308
+
309
+ - A `Path` object if the local file is found
310
+ - The `huggingface_hub._CACHED_NO_EXIST` sentinel if the file is known to not exist
311
+ - `None` if the file is not found and we cannot determine if it exists or not
312
+
313
+ Callers of this method should handle the `_CACHED_NO_EXIST` sentinel appropriately.
314
+ Checking if the return value `is not None` is not sufficient because it does not
315
+ distinguish between the file not existing and the file not being found.
316
+ """
317
file_path = Path(model) / file_name
318
if file_path.is_file():
319
return file_path
@@ -308,6 +324,7 @@ def try_get_local_file(
324
)
325
if isinstance(cached_filepath, str):
326
return Path(cached_filepath)
327
+ return cached_filepath
328
except ValueError:
329
...
330
return None
@@ -335,7 +352,7 @@ def get_hf_file_to_dict(
352
if file_path is None:
353
file_path = _try_download_from_hf_hub(model, file_name, revision)
354
338
- if file_path is not None and file_path.is_file():
355
+ if isinstance(file_path, Path) and file_path.is_file():
356
with open(file_path) as file:
357
return json.load(file)
358