Skip to content

Commit 1df84ff

Browse files
authored
ci: simplify multi-modality tests by using mixins (sgl-project#9006)
1 parent 66d6be0 commit 1df84ff

File tree

6 files changed

+264
-400
lines changed

6 files changed

+264
-400
lines changed

python/sglang/srt/multimodal/processors/base_processor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ def process_mm_data(
217217
if videos:
218218
kwargs["videos"] = videos
219219
if audios:
220-
if self.arch in {
221-
"Gemma3nForConditionalGeneration",
222-
"Qwen2AudioForConditionalGeneration",
220+
if self._processor.__class__.__name__ in {
221+
"Gemma3nProcessor",
222+
"Qwen2AudioProcessor",
223223
}:
224224
# Note(Xinyuan): for gemma3n, ref: https://github.com/huggingface/transformers/blob/ccf2ca162e33f381e454cdb74bf4b41a51ab976d/src/transformers/models/gemma3n/processing_gemma3n.py#L107
225225
kwargs["audio"] = audios

python/sglang/srt/multimodal/processors/llava.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from sglang.srt.models.mistral import Mistral3ForConditionalGeneration
1919
from sglang.srt.multimodal.mm_utils import expand2square, process_anyres_image
2020
from sglang.srt.multimodal.processors.base_processor import BaseMultimodalProcessor
21-
from sglang.srt.utils import load_image, logger
21+
from sglang.srt.utils import ImageData, load_image, logger
2222
from sglang.utils import get_exception_traceback
2323

2424

@@ -35,7 +35,7 @@ def __init__(self, hf_config, server_args, _processor, *args, **kwargs):
3535

3636
@staticmethod
3737
def _process_single_image_task(
38-
image_data: Union[str, bytes],
38+
image_data: Union[str, bytes, ImageData],
3939
image_aspect_ratio: Optional[str] = None,
4040
image_grid_pinpoints: Optional[str] = None,
4141
processor=None,
@@ -44,18 +44,19 @@ def _process_single_image_task(
4444
image_processor = processor.image_processor
4545

4646
try:
47-
image, image_size = load_image(image_data)
47+
url = image_data.url if isinstance(image_data, ImageData) else image_data
48+
image, image_size = load_image(url)
4849
if image_size is not None:
4950
# It is a video with multiple images
50-
image_hash = hash(image_data)
51+
image_hash = hash(url)
5152
pixel_values = image_processor(image)["pixel_values"]
5253
for _ in range(len(pixel_values)):
5354
pixel_values[_] = pixel_values[_].astype(np.float16)
5455
pixel_values = np.stack(pixel_values, axis=0)
5556
return pixel_values, image_hash, image_size
5657
else:
5758
# It is an image
58-
image_hash = hash(image_data)
59+
image_hash = hash(url)
5960
if image_aspect_ratio == "pad":
6061
image = expand2square(
6162
image,
@@ -82,7 +83,10 @@ def _process_single_image_task(
8283
logger.error("Exception in TokenizerManager:\n" + get_exception_traceback())
8384

8485
async def _process_single_image(
85-
self, image_data: Union[bytes, str], aspect_ratio: str, grid_pinpoints: str
86+
self,
87+
image_data: Union[bytes, str, ImageData],
88+
aspect_ratio: str,
89+
grid_pinpoints: str,
8690
):
8791
if self.cpu_executor is not None:
8892
loop = asyncio.get_event_loop()
@@ -104,7 +108,7 @@ async def _process_single_image(
104108

105109
async def process_mm_data_async(
106110
self,
107-
image_data: List[Union[str, bytes]],
111+
image_data: List[Union[str, bytes, ImageData]],
108112
input_text,
109113
request_obj,
110114
*args,

test/srt/run_suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class TestFile:
110110
TestFile("test_utils_update_weights.py", 48),
111111
TestFile("test_vision_chunked_prefill.py", 175),
112112
TestFile("test_vlm_input_format.py", 300),
113-
TestFile("test_vision_openai_server_a.py", 989),
114-
TestFile("test_vision_openai_server_b.py", 620),
113+
TestFile("test_vision_openai_server_a.py", 403),
114+
TestFile("test_vision_openai_server_b.py", 446),
115115
],
116116
"per-commit-2-gpu": [
117117
TestFile("lora/test_lora_tp.py", 116),

test/srt/test_vision_openai_server_a.py

Lines changed: 111 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@
88

99
from test_vision_openai_server_common import *
1010

11-
from sglang.srt.utils import kill_process_tree
1211
from sglang.test.test_utils import (
1312
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
14-
DEFAULT_URL_FOR_TEST,
15-
CustomTestCase,
1613
popen_launch_server,
1714
)
1815

1916

20-
class TestQwen2VLServer(TestOpenAIVisionServer):
17+
class TestLlava(ImageOpenAITestMixin):
18+
@classmethod
19+
def setUpClass(cls):
20+
cls.model = "lmms-lab/llava-onevision-qwen2-0.5b-ov"
21+
cls.base_url = DEFAULT_URL_FOR_TEST
22+
cls.api_key = "sk-123456"
23+
cls.process = popen_launch_server(
24+
cls.model,
25+
cls.base_url,
26+
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
27+
api_key=cls.api_key,
28+
)
29+
cls.base_url += "/v1"
30+
31+
32+
class TestQwen2VLServer(ImageOpenAITestMixin, VideoOpenAITestMixin):
2133
@classmethod
2234
def setUpClass(cls):
2335
cls.model = "Qwen/Qwen2-VL-7B-Instruct"
@@ -37,11 +49,8 @@ def setUpClass(cls):
3749
)
3850
cls.base_url += "/v1"
3951

40-
def test_video_chat_completion(self):
41-
self._test_video_chat_completion()
42-
4352

44-
class TestQwen2_5_VLServer(TestOpenAIVisionServer):
53+
class TestQwen2_5_VLServer(ImageOpenAITestMixin, VideoOpenAITestMixin):
4554
@classmethod
4655
def setUpClass(cls):
4756
cls.model = "Qwen/Qwen2.5-VL-7B-Instruct"
@@ -61,9 +70,6 @@ def setUpClass(cls):
6170
)
6271
cls.base_url += "/v1"
6372

64-
def test_video_chat_completion(self):
65-
self._test_video_chat_completion()
66-
6773

6874
class TestVLMContextLengthIssue(CustomTestCase):
6975
@classmethod
@@ -137,11 +143,8 @@ def test_single_image_chat_completion(self):
137143
# )
138144
# cls.base_url += "/v1"
139145

140-
# def test_video_chat_completion(self):
141-
# pass
142146

143-
144-
class TestMinicpmvServer(TestOpenAIVisionServer):
147+
class TestMinicpmvServer(ImageOpenAITestMixin):
145148
@classmethod
146149
def setUpClass(cls):
147150
cls.model = "openbmb/MiniCPM-V-2_6"
@@ -162,7 +165,7 @@ def setUpClass(cls):
162165
cls.base_url += "/v1"
163166

164167

165-
class TestInternVL2_5Server(TestOpenAIVisionServer):
168+
class TestInternVL2_5Server(ImageOpenAITestMixin):
166169
@classmethod
167170
def setUpClass(cls):
168171
cls.model = "OpenGVLab/InternVL2_5-2B"
@@ -181,7 +184,7 @@ def setUpClass(cls):
181184
cls.base_url += "/v1"
182185

183186

184-
class TestMinicpmoServer(TestOpenAIVisionServer):
187+
class TestMinicpmoServer(ImageOpenAITestMixin, AudioOpenAITestMixin):
185188
@classmethod
186189
def setUpClass(cls):
187190
cls.model = "openbmb/MiniCPM-o-2_6"
@@ -201,12 +204,8 @@ def setUpClass(cls):
201204
)
202205
cls.base_url += "/v1"
203206

204-
def test_audio_chat_completion(self):
205-
self._test_audio_speech_completion()
206-
self._test_audio_ambient_completion()
207-
208207

209-
class TestMimoVLServer(TestOpenAIVisionServer):
208+
class TestMimoVLServer(ImageOpenAITestMixin):
210209
@classmethod
211210
def setUpClass(cls):
212211
cls.model = "XiaomiMiMo/MiMo-VL-7B-RL"
@@ -228,6 +227,95 @@ def setUpClass(cls):
228227
cls.base_url += "/v1"
229228

230229

230+
class TestVILAServer(ImageOpenAITestMixin):
231+
@classmethod
232+
def setUpClass(cls):
233+
cls.model = "Efficient-Large-Model/NVILA-Lite-2B-hf-0626"
234+
cls.base_url = DEFAULT_URL_FOR_TEST
235+
cls.api_key = "sk-123456"
236+
cls.revision = "6bde1de5964b40e61c802b375fff419edc867506"
237+
cls.process = popen_launch_server(
238+
cls.model,
239+
cls.base_url,
240+
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
241+
api_key=cls.api_key,
242+
other_args=[
243+
"--trust-remote-code",
244+
"--context-length=65536",
245+
f"--revision={cls.revision}",
246+
"--cuda-graph-max-bs",
247+
"4",
248+
],
249+
)
250+
cls.base_url += "/v1"
251+
252+
253+
class TestPhi4MMServer(ImageOpenAITestMixin, AudioOpenAITestMixin):
254+
@classmethod
255+
def setUpClass(cls):
256+
# Manually download LoRA adapter_config.json as it's not downloaded by the model loader by default.
257+
from huggingface_hub import constants, snapshot_download
258+
259+
snapshot_download(
260+
"microsoft/Phi-4-multimodal-instruct",
261+
allow_patterns=["**/adapter_config.json"],
262+
)
263+
264+
cls.model = "microsoft/Phi-4-multimodal-instruct"
265+
cls.base_url = DEFAULT_URL_FOR_TEST
266+
cls.api_key = "sk-123456"
267+
268+
revision = "33e62acdd07cd7d6635badd529aa0a3467bb9c6a"
269+
cls.process = popen_launch_server(
270+
cls.model,
271+
cls.base_url,
272+
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
273+
other_args=[
274+
"--trust-remote-code",
275+
"--mem-fraction-static",
276+
"0.70",
277+
"--disable-radix-cache",
278+
"--max-loras-per-batch",
279+
"2",
280+
"--revision",
281+
revision,
282+
"--lora-paths",
283+
f"vision={constants.HF_HUB_CACHE}/models--microsoft--Phi-4-multimodal-instruct/snapshots/{revision}/vision-lora",
284+
f"speech={constants.HF_HUB_CACHE}/models--microsoft--Phi-4-multimodal-instruct/snapshots/{revision}/speech-lora",
285+
"--cuda-graph-max-bs",
286+
"4",
287+
],
288+
)
289+
cls.base_url += "/v1"
290+
291+
def get_vision_request_kwargs(self):
292+
return {
293+
"extra_body": {
294+
"lora_path": "vision",
295+
"top_k": 1,
296+
"top_p": 1.0,
297+
}
298+
}
299+
300+
def get_audio_request_kwargs(self):
301+
return {
302+
"extra_body": {
303+
"lora_path": "speech",
304+
"top_k": 1,
305+
"top_p": 1.0,
306+
}
307+
}
308+
309+
# This _test_audio_ambient_completion test is way too complicated to pass for a small LLM
310+
def test_audio_ambient_completion(self):
311+
pass
312+
313+
231314
if __name__ == "__main__":
232-
del TestOpenAIVisionServer
315+
del (
316+
TestOpenAIOmniServerBase,
317+
ImageOpenAITestMixin,
318+
VideoOpenAITestMixin,
319+
AudioOpenAITestMixin,
320+
)
233321
unittest.main()

0 commit comments

Comments
 (0)