A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 11, 10:00 UTC
improve lazy import test (#30733)
Signed-off-by: Boyuan Feng <boyuan@meta.com>
Boyuan Feng committed
Dec 15, 2025 at 19:12 UTC
c881db364e2bbcc90350db857fe294ae01ff71b7
1 file changed
+6
-25
tests/standalone_tests/lazy_imports.py
+6
-25
@@ -5,9 +5,6 @@
5
# The utility function cannot be placed in `vllm.utils`
6
# this needs to be a standalone script
7
import sys
8
-from contextlib import nullcontext
9
-
10
-from vllm_test_utils import BlameResult, blame
8
9
# List of modules that should not be imported too early.
10
# Lazy import `torch._inductor.async_compile` to avoid creating
@@ -16,26 +13,10 @@ from vllm_test_utils import BlameResult, blame
13
# `cv2` can easily mess up the environment.
14
module_names = ["torch._inductor.async_compile", "cv2"]
15
16
+# set all modules in `module_names` to be None.
17
+# if we import any modules during `import vllm`, there would be a
18
+# hard error and nice stacktrace on the first import.
19
+for module_name in module_names:
20
+ sys.modules[module_name] = None # type: ignore[assignment]
21
20
-def any_module_imported():
21
- return any(module_name in sys.modules for module_name in module_names)
22
-
23
-
24
-# In CI, we only check finally if the module is imported.
25
-# If it is indeed imported, we can rerun the test with `use_blame=True`,
26
-# which will trace every function call to find the first import location,
27
-# and help find the root cause.
28
-# We don't run it in CI by default because it is slow.
29
-use_blame = False
30
-context = blame(any_module_imported) if use_blame else nullcontext()
31
-with context as result:
32
- import vllm # noqa
33
-
34
-if use_blame:
35
- assert isinstance(result, BlameResult)
36
- print(f"the first import location is:\n{result.trace_stack}")
37
-
38
-assert not any_module_imported(), (
39
- f"Some the modules in {module_names} are imported. To see the first"
40
- f" import location, run the test with `use_blame=True`."
41
-)
22
+import vllm # noqa