Skip to content

Commit 550d97e

Browse files
authored
[Misc] Avoid calling unnecessary hf_list_repo_files for local model path (#13348)
Signed-off-by: isotr0py <[email protected]>
1 parent fbbe1fb commit 550d97e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

vllm/transformers_utils/config.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ def list_repo_files(
115115
token: Union[str, bool, None] = None,
116116
) -> list[str]:
117117

118-
def lookup_files():
118+
def lookup_files() -> list[str]:
119+
# directly list files if model is local
120+
if (local_path := Path(repo_id)).exists():
121+
return [
122+
str(file.relative_to(local_path))
123+
for file in local_path.rglob('*') if file.is_file()
124+
]
125+
# if model is remote, use hf_hub api to list files
119126
try:
120127
if VLLM_USE_MODELSCOPE:
121128
from vllm.transformers_utils.utils import (
@@ -154,8 +161,8 @@ def file_exists(
154161
# In offline mode the result can be a false negative
155162
def file_or_path_exists(model: Union[str, Path], config_name: str,
156163
revision: Optional[str]) -> bool:
157-
if Path(model).exists():
158-
return (Path(model) / config_name).is_file()
164+
if (local_path := Path(model)).exists():
165+
return (local_path / config_name).is_file()
159166

160167
# Offline mode support: Check if config file is cached already
161168
cached_filepath = try_to_load_from_cache(repo_id=model,

0 commit comments

Comments
 (0)