1
1
import sys
2
2
3
+ from vllm_test_utils import blame
4
+
3
5
from vllm import LLM , SamplingParams
4
6
from vllm .distributed import cleanup_dist_env_and_memory
5
7
6
8
7
- def test_lazy_outlines (sample_regex ):
8
- """If users don't use guided decoding, outlines should not be imported.
9
- """
9
+ def run_normal ():
10
10
prompts = [
11
11
"Hello, my name is" ,
12
12
"The president of the United States is" ,
@@ -25,13 +25,12 @@ def test_lazy_outlines(sample_regex):
25
25
generated_text = output .outputs [0 ].text
26
26
print (f"Prompt: { prompt !r} , Generated text: { generated_text !r} " )
27
27
28
- # make sure outlines is not imported
29
- assert 'outlines' not in sys .modules
30
-
31
28
# Destroy the LLM object and free up the GPU memory.
32
29
del llm
33
30
cleanup_dist_env_and_memory ()
34
31
32
+
33
+ def run_lmfe (sample_regex ):
35
34
# Create an LLM with guided decoding enabled.
36
35
llm = LLM (model = "facebook/opt-125m" ,
37
36
enforce_eager = True ,
@@ -51,5 +50,15 @@ def test_lazy_outlines(sample_regex):
51
50
generated_text = output .outputs [0 ].text
52
51
print (f"Prompt: { prompt !r} , Generated text: { generated_text !r} " )
53
52
53
+
54
+ def test_lazy_outlines (sample_regex ):
55
+ """If users don't use guided decoding, outlines should not be imported.
56
+ """
54
57
# make sure outlines is not imported
55
- assert 'outlines' not in sys .modules
58
+ module_name = "outlines"
59
+ with blame (lambda : module_name in sys .modules ) as result :
60
+ run_normal ()
61
+ 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 } " )
0 commit comments