[ci] add vllm_test_utils (#10659)
Signed-off-by: youkaichao <youkaichao@gmail.com>
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import sys
|
||||
|
||||
from vllm_test_utils import blame
|
||||
|
||||
from vllm import LLM, SamplingParams
|
||||
from vllm.distributed import cleanup_dist_env_and_memory
|
||||
|
||||
|
||||
def test_lazy_outlines(sample_regex):
|
||||
"""If users don't use guided decoding, outlines should not be imported.
|
||||
"""
|
||||
def run_normal():
|
||||
prompts = [
|
||||
"Hello, my name is",
|
||||
"The president of the United States is",
|
||||
@@ -25,13 +25,12 @@ def test_lazy_outlines(sample_regex):
|
||||
generated_text = output.outputs[0].text
|
||||
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
|
||||
|
||||
# make sure outlines is not imported
|
||||
assert 'outlines' not in sys.modules
|
||||
|
||||
# Destroy the LLM object and free up the GPU memory.
|
||||
del llm
|
||||
cleanup_dist_env_and_memory()
|
||||
|
||||
|
||||
def run_lmfe(sample_regex):
|
||||
# Create an LLM with guided decoding enabled.
|
||||
llm = LLM(model="facebook/opt-125m",
|
||||
enforce_eager=True,
|
||||
@@ -51,5 +50,15 @@ def test_lazy_outlines(sample_regex):
|
||||
generated_text = output.outputs[0].text
|
||||
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
|
||||
|
||||
|
||||
def test_lazy_outlines(sample_regex):
|
||||
"""If users don't use guided decoding, outlines should not be imported.
|
||||
"""
|
||||
# make sure outlines is not imported
|
||||
assert 'outlines' not in sys.modules
|
||||
module_name = "outlines"
|
||||
with blame(lambda: module_name in sys.modules) as result:
|
||||
run_normal()
|
||||
run_lmfe(sample_regex)
|
||||
assert not result.found, (
|
||||
f"Module {module_name} is already imported, the"
|
||||
f" first import location is:\n{result.trace_stack}")
|
||||
|
||||
Reference in New Issue
Block a user