Skip to content

Commit 3f532cb

Browse files
authored
[Misc] Use model_redirect to redirect the model name to a local folder. (#14116)
1 parent e6c9053 commit 3f532cb

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

vllm/config.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
get_sentence_transformer_tokenizer_config, is_encoder_decoder,
3939
try_get_generation_config, uses_mrope)
4040
from vllm.transformers_utils.s3_utils import S3Model
41-
from vllm.transformers_utils.utils import is_s3
41+
from vllm.transformers_utils.utils import is_s3, maybe_model_redirect
4242
from vllm.utils import (GiB_bytes, LayerBlockType, cuda_device_count_stateless,
4343
get_cpu_memory, random_uuid, resolve_obj_by_qualname)
4444

@@ -266,9 +266,13 @@ def __init__(
266266
override_generation_config: Optional[dict[str, Any]] = None,
267267
model_impl: Union[str, ModelImpl] = ModelImpl.AUTO,
268268
) -> None:
269-
self.model = model
269+
self.model = maybe_model_redirect(model)
270+
self.tokenizer = maybe_model_redirect(tokenizer)
271+
270272
self.hf_config_path = hf_config_path
271-
self.tokenizer = tokenizer
273+
if isinstance(hf_config_path, str):
274+
self.hf_config_path = maybe_model_redirect(hf_config_path)
275+
272276
self.tokenizer_mode = tokenizer_mode
273277
self.trust_remote_code = trust_remote_code
274278
self.allowed_local_media_path = allowed_local_media_path

vllm/envs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
S3_ACCESS_KEY_ID: Optional[str] = None
2323
S3_SECRET_ACCESS_KEY: Optional[str] = None
2424
S3_ENDPOINT_URL: Optional[str] = None
25+
VLLM_MODEL_REDIRECT_PATH: Optional[str] = None
2526
VLLM_CACHE_ROOT: str = os.path.expanduser("~/.cache/vllm")
2627
VLLM_CONFIG_ROOT: str = os.path.expanduser("~/.config/vllm")
2728
VLLM_USAGE_STATS_SERVER: str = "https://stats.vllm.ai"
@@ -635,6 +636,10 @@ def maybe_convert_int(value: Optional[str]) -> Optional[int]:
635636
"VLLM_CI_USE_S3":
636637
lambda: os.environ.get("VLLM_CI_USE_S3", "0") == "1",
637638

639+
# Use model_redirect to redirect the model name to a local folder.
640+
"VLLM_MODEL_REDIRECT_PATH":
641+
lambda: os.environ.get("VLLM_MODEL_REDIRECT_PATH", None),
642+
638643
# Whether to use atomicAdd reduce in gptq/awq marlin kernel.
639644
"VLLM_MARLIN_USE_ATOMIC_ADD":
640645
lambda: os.environ.get("VLLM_MARLIN_USE_ATOMIC_ADD", "0") == "1",

vllm/transformers_utils/utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
from functools import cache
34
from os import PathLike
45
from pathlib import Path
56
from typing import List, Optional, Union
67

8+
from vllm.envs import VLLM_MODEL_REDIRECT_PATH
9+
from vllm.logger import init_logger
10+
11+
logger = init_logger(__name__)
12+
713

814
def is_s3(model_or_path: str) -> bool:
915
return model_or_path.lower().startswith('s3://')
@@ -38,3 +44,35 @@ def modelscope_list_repo_files(
3844
if file['Type'] == 'blob'
3945
]
4046
return files
47+
48+
49+
@cache
50+
def maybe_model_redirect(model: str) -> str:
51+
"""
52+
Use model_redirect to redirect the model name to a local folder.
53+
54+
:param model: hf model name
55+
:return: maybe redirect to a local folder
56+
"""
57+
58+
model_redirect_path = VLLM_MODEL_REDIRECT_PATH
59+
60+
if not model_redirect_path:
61+
return model
62+
63+
if not Path(model_redirect_path).exists():
64+
return model
65+
66+
with open(model_redirect_path) as f:
67+
for line in f.readlines():
68+
try:
69+
model_name, redirect_name = line.split("\t")
70+
if model == model_name:
71+
redirect_name = redirect_name.strip()
72+
logger.info("model redirect: [ %s ] -> [ %s ]", model,
73+
redirect_name)
74+
return redirect_name
75+
except Exception:
76+
pass
77+
78+
return model

0 commit comments

Comments
 (0)