2024-11-20 18:36:33 -08:00
|
|
|
# Description: Test the lazy import module
|
|
|
|
# The utility function cannot be placed in `vllm.utils`
|
|
|
|
# this needs to be a standalone script
|
|
|
|
import sys
|
2024-11-27 09:26:14 -08:00
|
|
|
from contextlib import nullcontext
|
2024-11-20 18:36:33 -08:00
|
|
|
|
2024-11-27 09:26:14 -08:00
|
|
|
from vllm_test_utils import BlameResult, blame
|
2024-11-20 18:36:33 -08:00
|
|
|
|
|
|
|
module_name = "torch._inductor.async_compile"
|
|
|
|
|
2024-11-27 09:26:14 -08:00
|
|
|
# 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(
|
|
|
|
lambda: module_name in sys.modules) if use_blame else nullcontext()
|
|
|
|
with context as result:
|
2024-11-20 18:36:33 -08:00
|
|
|
import vllm # noqa
|
|
|
|
|
2024-11-27 09:26:14 -08:00
|
|
|
if use_blame:
|
|
|
|
assert isinstance(result, BlameResult)
|
|
|
|
print(f"the first import location is:\n{result.trace_stack}")
|
2024-11-20 18:36:33 -08:00
|
|
|
|
2024-11-27 09:26:14 -08:00
|
|
|
assert module_name not in sys.modules, (
|
|
|
|
f"Module {module_name} is imported. To see the first"
|
|
|
|
f" import location, run the test with `use_blame=True`.")
|