[Misc] Use model_redirect to redirect the model name to a local folder. (#14116)

This commit is contained in:
wang.yuqi
2025-03-27 02:21:23 -07:00
committed by GitHub
parent e6c9053f9e
commit 3f532cb6a6
3 changed files with 50 additions and 3 deletions
+38
View File
@@ -1,9 +1,15 @@
# SPDX-License-Identifier: Apache-2.0
from functools import cache
from os import PathLike
from pathlib import Path
from typing import List, Optional, Union
from vllm.envs import VLLM_MODEL_REDIRECT_PATH
from vllm.logger import init_logger
logger = init_logger(__name__)
def is_s3(model_or_path: str) -> bool:
return model_or_path.lower().startswith('s3://')
@@ -38,3 +44,35 @@ def modelscope_list_repo_files(
if file['Type'] == 'blob'
]
return files
@cache
def maybe_model_redirect(model: str) -> str:
"""
Use model_redirect to redirect the model name to a local folder.
:param model: hf model name
:return: maybe redirect to a local folder
"""
model_redirect_path = VLLM_MODEL_REDIRECT_PATH
if not model_redirect_path:
return model
if not Path(model_redirect_path).exists():
return model
with open(model_redirect_path) as f:
for line in f.readlines():
try:
model_name, redirect_name = line.split("\t")
if model == model_name:
redirect_name = redirect_name.strip()
logger.info("model redirect: [ %s ] -> [ %s ]", model,
redirect_name)
return redirect_name
except Exception:
pass
return model