Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
c2a96715
Unverified
Commit
c2a96715
authored
Apr 06, 2025
by
Isotr0py
Committed by
GitHub
Apr 06, 2025
Browse files
[Misc] Improve model redirect to accept json dictionary (#16119)
Signed-off-by:
Isotr0py
<
2037008807@qq.com
>
parent
d5ae4f7f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
vllm/envs.py
vllm/envs.py
+5
-0
vllm/transformers_utils/utils.py
vllm/transformers_utils/utils.py
+26
-11
No files found.
vllm/envs.py
View file @
c2a96715
...
@@ -665,6 +665,11 @@ environment_variables: dict[str, Callable[[], Any]] = {
...
@@ -665,6 +665,11 @@ environment_variables: dict[str, Callable[[], Any]] = {
lambda
:
os
.
environ
.
get
(
"VLLM_CI_USE_S3"
,
"0"
)
==
"1"
,
lambda
:
os
.
environ
.
get
(
"VLLM_CI_USE_S3"
,
"0"
)
==
"1"
,
# Use model_redirect to redirect the model name to a local folder.
# Use model_redirect to redirect the model name to a local folder.
# `model_redirect` can be a json file mapping the model between
# repo_id and local folder:
# {"meta-llama/Llama-3.2-1B": "/tmp/Llama-3.2-1B"}
# or a space separated values table file:
# meta-llama/Llama-3.2-1B /tmp/Llama-3.2-1B
"VLLM_MODEL_REDIRECT_PATH"
:
"VLLM_MODEL_REDIRECT_PATH"
:
lambda
:
os
.
environ
.
get
(
"VLLM_MODEL_REDIRECT_PATH"
,
None
),
lambda
:
os
.
environ
.
get
(
"VLLM_MODEL_REDIRECT_PATH"
,
None
),
...
...
vllm/transformers_utils/utils.py
View file @
c2a96715
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: Apache-2.0
import
json
from
functools
import
cache
from
functools
import
cache
from
os
import
PathLike
from
os
import
PathLike
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -51,6 +52,26 @@ def modelscope_list_repo_files(
...
@@ -51,6 +52,26 @@ def modelscope_list_repo_files(
return
files
return
files
def
_maybe_json_dict
(
path
:
Union
[
str
,
PathLike
])
->
dict
[
str
,
str
]:
with
open
(
path
)
as
f
:
try
:
return
json
.
loads
(
f
.
read
())
except
Exception
:
return
dict
[
str
,
str
]()
def
_maybe_space_split_dict
(
path
:
Union
[
str
,
PathLike
])
->
dict
[
str
,
str
]:
parsed_dict
=
dict
[
str
,
str
]()
with
open
(
path
)
as
f
:
for
line
in
f
.
readlines
():
try
:
model_name
,
redirect_name
=
line
.
strip
().
split
()
parsed_dict
[
model_name
]
=
redirect_name
except
Exception
:
pass
return
parsed_dict
@
cache
@
cache
def
maybe_model_redirect
(
model
:
str
)
->
str
:
def
maybe_model_redirect
(
model
:
str
)
->
str
:
"""
"""
...
@@ -68,16 +89,10 @@ def maybe_model_redirect(model: str) -> str:
...
@@ -68,16 +89,10 @@ def maybe_model_redirect(model: str) -> str:
if
not
Path
(
model_redirect_path
).
exists
():
if
not
Path
(
model_redirect_path
).
exists
():
return
model
return
model
with
open
(
model_redirect_path
)
as
f
:
redirect_dict
=
(
_maybe_json_dict
(
model_redirect_path
)
for
line
in
f
.
readlines
():
or
_maybe_space_split_dict
(
model_redirect_path
))
try
:
if
(
redirect_model
:
=
redirect_dict
.
get
(
model
)):
model_name
,
redirect_name
=
line
.
split
(
"
\t
"
)
logger
.
info
(
"model redirect: [ %s ] -> [ %s ]"
,
model
,
redirect_model
)
if
model
==
model_name
:
return
redirect_model
redirect_name
=
redirect_name
.
strip
()
logger
.
info
(
"model redirect: [ %s ] -> [ %s ]"
,
model
,
redirect_name
)
return
redirect_name
except
Exception
:
pass
return
model
return
model
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment