main
py 101 lines 3.22 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import pytest
5
6 from tests.utils import create_new_process_for_each_test
7 from vllm import LLM, SamplingParams
8 from vllm.assets.image import ImageAsset
9 from vllm.multimodal.image import convert_image_mode
10
11
12 @create_new_process_for_each_test()
13 def test_plugin(
14 monkeypatch: pytest.MonkeyPatch,
15 dummy_opt_path: str,
16 ):
17 with monkeypatch.context() as m:
18 m.setenv("VLLM_PLUGINS", "")
19
20 with pytest.raises(ValueError, match="are not supported for now"):
21 LLM(model=dummy_opt_path, load_format="dummy")
22
23
24 @create_new_process_for_each_test()
25 def test_oot_registration_text_generation(
26 monkeypatch: pytest.MonkeyPatch,
27 dummy_opt_path: str,
28 ):
29 with monkeypatch.context() as m:
30 m.setenv("VLLM_PLUGINS", "register_dummy_model")
31 prompts = ["Hello, my name is", "The text does not matter"]
32 sampling_params = SamplingParams(temperature=0)
33 llm = LLM(model=dummy_opt_path, load_format="dummy")
34 first_token = llm.get_tokenizer().decode(0)
35 outputs = llm.generate(prompts, sampling_params)
36
37 for output in outputs:
38 generated_text = output.outputs[0].text
39 # make sure only the first token is generated
40 rest = generated_text.replace(first_token, "")
41 assert rest == ""
42
43
44 @create_new_process_for_each_test()
45 def test_oot_registration_embedding(
46 monkeypatch: pytest.MonkeyPatch,
47 dummy_gemma2_embedding_path: str,
48 ):
49 with monkeypatch.context() as m:
50 m.setenv("VLLM_PLUGINS", "register_dummy_model")
51 prompts = ["Hello, my name is", "The text does not matter"]
52 llm = LLM(
53 model=dummy_gemma2_embedding_path, load_format="dummy", max_model_len=512
54 )
55 outputs = llm.embed(prompts)
56
57 for output in outputs:
58 assert all(v == 0 for v in output.outputs.embedding)
59
60
61 image = convert_image_mode(ImageAsset("cherry_blossom").pil_image, "RGB")
62
63
64 @create_new_process_for_each_test()
65 def test_oot_registration_multimodal(
66 monkeypatch: pytest.MonkeyPatch,
67 dummy_llava_path: str,
68 ):
69 with monkeypatch.context() as m:
70 m.setenv("VLLM_PLUGINS", "register_dummy_model")
71 prompts = [
72 {
73 "prompt": "What's in the image?<image>",
74 "multi_modal_data": {"image": image},
75 },
76 {
77 "prompt": "Describe the image<image>",
78 "multi_modal_data": {"image": image},
79 },
80 ]
81
82 sampling_params = SamplingParams(temperature=0)
83 llm = LLM(
84 model=dummy_llava_path,
85 load_format="dummy",
86 max_num_seqs=1,
87 trust_remote_code=True,
88 gpu_memory_utilization=0.98,
89 max_model_len=4096,
90 enforce_eager=True,
91 limit_mm_per_prompt={"image": 1},
92 )
93
94 first_token = llm.get_tokenizer().decode(0)
95 outputs = llm.generate(prompts, sampling_params)
96
97 for output in outputs:
98 generated_text = output.outputs[0].text
99 # make sure only the first token is generated
100 rest = generated_text.replace(first_token, "")
101 assert rest == ""