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
de895f16
Unverified
Commit
de895f16
authored
Oct 09, 2024
by
youkaichao
Committed by
GitHub
Oct 09, 2024
Browse files
[misc] improve model support check in another process (#9208)
parent
cf25b93b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
32 deletions
+36
-32
docs/requirements-docs.txt
docs/requirements-docs.txt
+1
-0
vllm/model_executor/models/registry.py
vllm/model_executor/models/registry.py
+35
-32
No files found.
docs/requirements-docs.txt
View file @
de895f16
...
...
@@ -4,6 +4,7 @@ sphinx-copybutton==0.5.2
myst-parser==2.0.0
sphinx-argparse==0.4.0
msgspec
cloudpickle
# packages to install to build the documentation
pydantic >= 2.8
...
...
vllm/model_executor/models/registry.py
View file @
de895f16
import
importlib
import
string
import
pickle
import
subprocess
import
sys
import
uuid
import
tempfile
from
functools
import
lru_cache
,
partial
from
typing
import
Callable
,
Dict
,
List
,
Optional
,
Tuple
,
Type
,
Union
import
cloudpickle
import
torch.nn
as
nn
from
vllm.logger
import
init_logger
...
...
@@ -282,36 +283,28 @@ class ModelRegistry:
raise
valid_name_characters
=
string
.
ascii_letters
+
string
.
digits
+
"._"
if
any
(
s
not
in
valid_name_characters
for
s
in
mod_name
):
raise
ValueError
(
f
"Unsafe module name detected for
{
model_arch
}
"
)
if
any
(
s
not
in
valid_name_characters
for
s
in
cls_name
):
raise
ValueError
(
f
"Unsafe class name detected for
{
model_arch
}
"
)
if
any
(
s
not
in
valid_name_characters
for
s
in
func
.
__module__
):
raise
ValueError
(
f
"Unsafe module name detected for
{
func
}
"
)
if
any
(
s
not
in
valid_name_characters
for
s
in
func
.
__name__
):
raise
ValueError
(
f
"Unsafe class name detected for
{
func
}
"
)
err_id
=
uuid
.
uuid4
()
stmts
=
";"
.
join
([
f
"from
{
mod_name
}
import
{
cls_name
}
"
,
f
"from
{
func
.
__module__
}
import
{
func
.
__name__
}
"
,
f
"assert
{
func
.
__name__
}
(
{
cls_name
}
), '
{
err_id
}
'"
,
])
result
=
subprocess
.
run
([
sys
.
executable
,
"-c"
,
stmts
],
with
tempfile
.
NamedTemporaryFile
()
as
output_file
:
# `cloudpickle` allows pickling lambda functions directly
input_bytes
=
cloudpickle
.
dumps
(
(
mod_name
,
cls_name
,
func
,
output_file
.
name
))
# cannot use `sys.executable __file__` here because the script
# contains relative imports
returned
=
subprocess
.
run
(
[
sys
.
executable
,
"-m"
,
"vllm.model_executor.models.registry"
],
input
=
input_bytes
,
capture_output
=
True
)
if
result
.
returncode
!=
0
:
err_lines
=
[
line
.
decode
()
for
line
in
result
.
stderr
.
splitlines
()]
if
err_lines
and
err_lines
[
-
1
]
!=
f
"AssertionError:
{
err_id
}
"
:
err_str
=
"
\n
"
.
join
(
err_lines
)
raise
RuntimeError
(
"An unexpected error occurred while importing the model in "
f
"another process. Error log:
\n
{
err_str
}
"
)
return
result
.
returncode
==
0
# check if the subprocess is successful
try
:
returned
.
check_returncode
()
except
Exception
as
e
:
# wrap raised exception to provide more information
raise
RuntimeError
(
f
"Error happened when testing "
f
"model support for
{
mod_name
}
.
{
cls_name
}
:
\n
"
f
"
{
returned
.
stderr
.
decode
()
}
"
)
from
e
with
open
(
output_file
.
name
,
"rb"
)
as
f
:
result
=
pickle
.
load
(
f
)
return
result
@
staticmethod
def
is_text_generation_model
(
architectures
:
Union
[
str
,
List
[
str
]])
->
bool
:
...
...
@@ -364,3 +357,13 @@ class ModelRegistry:
default
=
False
)
return
any
(
is_pp
(
arch
)
for
arch
in
architectures
)
if
__name__
==
"__main__"
:
(
mod_name
,
cls_name
,
func
,
output_file
)
=
pickle
.
loads
(
sys
.
stdin
.
buffer
.
read
())
mod
=
importlib
.
import_module
(
mod_name
)
klass
=
getattr
(
mod
,
cls_name
)
result
=
func
(
klass
)
with
open
(
output_file
,
"wb"
)
as
f
:
f
.
write
(
pickle
.
dumps
(
result
))
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