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
c881db36
Unverified
Commit
c881db36
authored
Dec 15, 2025
by
Boyuan Feng
Committed by
GitHub
Dec 16, 2025
Browse files
improve lazy import test (#30733)
Signed-off-by:
Boyuan Feng
<
boyuan@meta.com
>
parent
3bd9c491
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
25 deletions
+6
-25
tests/standalone_tests/lazy_imports.py
tests/standalone_tests/lazy_imports.py
+6
-25
No files found.
tests/standalone_tests/lazy_imports.py
View file @
c881db36
...
...
@@ -5,9 +5,6 @@
# The utility function cannot be placed in `vllm.utils`
# this needs to be a standalone script
import
sys
from
contextlib
import
nullcontext
from
vllm_test_utils
import
BlameResult
,
blame
# List of modules that should not be imported too early.
# Lazy import `torch._inductor.async_compile` to avoid creating
...
...
@@ -16,26 +13,10 @@ from vllm_test_utils import BlameResult, blame
# `cv2` can easily mess up the environment.
module_names
=
[
"torch._inductor.async_compile"
,
"cv2"
]
# set all modules in `module_names` to be None.
# if we import any modules during `import vllm`, there would be a
# hard error and nice stacktrace on the first import.
for
module_name
in
module_names
:
sys
.
modules
[
module_name
]
=
None
# type: ignore[assignment]
def
any_module_imported
():
return
any
(
module_name
in
sys
.
modules
for
module_name
in
module_names
)
# In CI, we only check finally if the module is imported.
# If it is indeed imported, we can rerun the test with `use_blame=True`,
# which will trace every function call to find the first import location,
# and help find the root cause.
# We don't run it in CI by default because it is slow.
use_blame
=
False
context
=
blame
(
any_module_imported
)
if
use_blame
else
nullcontext
()
with
context
as
result
:
import
vllm
# noqa
if
use_blame
:
assert
isinstance
(
result
,
BlameResult
)
print
(
f
"the first import location is:
\n
{
result
.
trace_stack
}
"
)
assert
not
any_module_imported
(),
(
f
"Some the modules in
{
module_names
}
are imported. To see the first"
f
" import location, run the test with `use_blame=True`."
)
import
vllm
# noqa
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