Skip to content

Commit d65fc83

Browse files
youkaichaoafeldman-nm
authored andcommitted
[ci] fix slow tests (vllm-project#10698)
Signed-off-by: youkaichao <youkaichao@gmail.com> Signed-off-by: Andrew Feldman <afeldman@neuralmagic.com>
1 parent 9cc018a commit d65fc83

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

tests/entrypoints/llm/test_lazy_outlines.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
2+
from contextlib import nullcontext
23

3-
from vllm_test_utils import blame
4+
from vllm_test_utils import BlameResult, blame
45

56
from vllm import LLM, SamplingParams
67
from vllm.distributed import cleanup_dist_env_and_memory
@@ -56,9 +57,20 @@ def test_lazy_outlines(sample_regex):
5657
"""
5758
# make sure outlines is not imported
5859
module_name = "outlines"
59-
with blame(lambda: module_name in sys.modules) as result:
60+
# In CI, we only check finally if the module is imported.
61+
# If it is indeed imported, we can rerun the test with `use_blame=True`,
62+
# which will trace every function call to find the first import location,
63+
# and help find the root cause.
64+
# We don't run it in CI by default because it is slow.
65+
use_blame = False
66+
context = blame(
67+
lambda: module_name in sys.modules) if use_blame else nullcontext()
68+
with context as result:
6069
run_normal()
6170
run_lmfe(sample_regex)
62-
assert not result.found, (
63-
f"Module {module_name} is already imported, the"
64-
f" first import location is:\n{result.trace_stack}")
71+
if use_blame:
72+
assert isinstance(result, BlameResult)
73+
print(f"the first import location is:\n{result.trace_stack}")
74+
assert module_name not in sys.modules, (
75+
f"Module {module_name} is imported. To see the first"
76+
f" import location, run the test with `use_blame=True`.")

tests/test_lazy_torch_compile.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@
22
# The utility function cannot be placed in `vllm.utils`
33
# this needs to be a standalone script
44
import sys
5+
from contextlib import nullcontext
56

6-
from vllm_test_utils import blame
7+
from vllm_test_utils import BlameResult, blame
78

89
module_name = "torch._inductor.async_compile"
910

10-
with blame(lambda: module_name in sys.modules) as result:
11+
# In CI, we only check finally if the module is imported.
12+
# If it is indeed imported, we can rerun the test with `use_blame=True`,
13+
# which will trace every function call to find the first import location,
14+
# and help find the root cause.
15+
# We don't run it in CI by default because it is slow.
16+
use_blame = False
17+
context = blame(
18+
lambda: module_name in sys.modules) if use_blame else nullcontext()
19+
with context as result:
1120
import vllm # noqa
1221

13-
assert not result.found, (f"Module {module_name} is already imported, the"
14-
f" first import location is:\n{result.trace_stack}")
22+
if use_blame:
23+
assert isinstance(result, BlameResult)
24+
print(f"the first import location is:\n{result.trace_stack}")
1525

16-
print(f"Module {module_name} is not imported yet")
26+
assert module_name not in sys.modules, (
27+
f"Module {module_name} is imported. To see the first"
28+
f" import location, run the test with `use_blame=True`.")

tests/vllm_test_utils/vllm_test_utils/blame.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def _trace_calls(frame, event, arg=None):
4646
pass
4747
return _trace_calls
4848

49-
sys.settrace(_trace_calls)
50-
51-
yield result
52-
53-
sys.settrace(None)
49+
try:
50+
sys.settrace(_trace_calls)
51+
yield result
52+
finally:
53+
sys.settrace(None)

0 commit comments

Comments
 (0)