test_vllm.py 20.5 KB
Newer Older
1
2
3
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

4
import base64
5
6
import logging
import os
7
import random
8
from dataclasses import dataclass, field
9
10
11

import pytest

12
13
14
15
16
from tests.serve.common import (
    WORKSPACE_DIR,
    params_with_model_mark,
    run_serve_deployment,
)
17
from tests.serve.conftest import MULTIMODAL_IMG_PATH, MULTIMODAL_IMG_URL
18
19
20
21
from tests.utils.engine_process import EngineConfig
from tests.utils.payload_builder import (
    chat_payload,
    chat_payload_default,
22
    chat_payload_with_logprobs,
23
    completion_payload_default,
24
    completion_payload_with_logprobs,
25
    metric_payload_default,
26
)
27
from tests.utils.payloads import ToolCallingChatPayload
28
29
30
31
32

logger = logging.getLogger(__name__)


@dataclass
33
class VLLMConfig(EngineConfig):
34
35
    """Configuration for vLLM test scenarios"""

36
    stragglers: list[str] = field(default_factory=lambda: ["VLLM:EngineCore"])
37
38


39
vllm_dir = os.environ.get("VLLM_DIR") or os.path.join(
40
    WORKSPACE_DIR, "examples/backends/vllm"
41
)
42

43

44
# vLLM test configurations
45
46
# NOTE: pytest.mark.gpu_1 tests take ~5.5 minutes total to run sequentially (with models pre-cached)
# TODO: Parallelize these tests to reduce total execution time
47
48
49
vllm_configs = {
    "aggregated": VLLMConfig(
        name="aggregated",
50
        directory=vllm_dir,
51
        script_name="agg.sh",
52
53
54
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
55
            pytest.mark.timeout(300),  # 3x measured time (43s) + download time (150s)
56
        ],
57
        model="Qwen/Qwen3-0.6B",
58
59
60
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
61
            metric_payload_default(min_num_requests=6, backend="vllm"),
62
        ],
63
    ),
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    "aggregated_logprobs": VLLMConfig(
        name="aggregated_logprobs",
        directory=vllm_dir,
        script_name="agg.sh",
        marks=[pytest.mark.gpu_1],
        model="Qwen/Qwen3-0.6B",
        request_payloads=[
            chat_payload_with_logprobs(
                repeat_count=2,
                expected_response=["AI", "knock", "joke"],
                max_tokens=30,
                temperature=0.0,
                top_logprobs=3,
            ),
            completion_payload_with_logprobs(
                repeat_count=2,
                expected_response=["AI", "knock", "joke"],
                max_tokens=30,
                temperature=0.0,
                logprobs=5,
            ),
        ],
    ),
87
88
89
90
    "aggregated_lmcache": VLLMConfig(
        name="aggregated_lmcache",
        directory=vllm_dir,
        script_name="agg_lmcache.sh",
91
92
93
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
94
            pytest.mark.timeout(360),  # 3x estimated time (70s) + download time (150s)
95
        ],
96
97
98
99
100
101
102
103
        model="Qwen/Qwen3-0.6B",
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
            metric_payload_default(min_num_requests=6, backend="vllm"),
            metric_payload_default(min_num_requests=6, backend="lmcache"),
        ],
    ),
104
105
106
107
    "aggregated_lmcache_multiproc": VLLMConfig(
        name="aggregated_lmcache_multiproc",
        directory=vllm_dir,
        script_name="agg_lmcache_multiproc.sh",
108
109
        marks=[
            pytest.mark.gpu_1,
110
            pytest.mark.timeout(360),  # 3x estimated time (70s) + download time (150s)
111
        ],
112
113
114
115
116
117
118
119
120
121
122
        model="Qwen/Qwen3-0.6B",
        env={
            "PROMETHEUS_MULTIPROC_DIR": f"/tmp/prometheus_multiproc_test_{os.getpid()}_{random.randint(0, 10000)}"
        },
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
            metric_payload_default(min_num_requests=6, backend="vllm"),
            metric_payload_default(min_num_requests=6, backend="lmcache"),
        ],
    ),
123
124
125
126
    "agg-request-plane-tcp": VLLMConfig(
        name="agg-request-plane-tcp",
        directory=vllm_dir,
        script_name="agg_request_planes.sh",
127
128
129
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
130
            pytest.mark.timeout(300),  # 3x measured time (43s) + download time (150s)
131
        ],
132
133
134
135
136
137
138
139
140
141
142
        model="Qwen/Qwen3-0.6B",
        script_args=["--tcp"],
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
        ],
    ),
    "agg-request-plane-http": VLLMConfig(
        name="agg-request-plane-http",
        directory=vllm_dir,
        script_name="agg_request_planes.sh",
143
144
145
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
146
            pytest.mark.timeout(300),  # 3x measured time (43s) + download time (150s)
147
        ],
148
149
150
151
152
153
154
        model="Qwen/Qwen3-0.6B",
        script_args=["--http"],
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
        ],
    ),
155
156
    "agg-router": VLLMConfig(
        name="agg-router",
157
        directory=vllm_dir,
158
        script_name="agg_router.sh",
159
        marks=[pytest.mark.gpu_2, pytest.mark.post_merge],
160
        model="Qwen/Qwen3-0.6B",
161
162
163
        request_payloads=[
            chat_payload_default(
                expected_log=[
164
                    r"ZMQ listener .* received batch with \d+ events \(seq=\d+(?:, [^)]*)?\)",
165
                    r"Event processor for worker_id \d+ processing event: Stored\(",
Yan Ru Pei's avatar
Yan Ru Pei committed
166
                    r"Selected worker: worker_id=\d+ dp_rank=.*?, logit: ",
167
168
169
170
171
172
                ]
            )
        ],
        env={
            "DYN_LOG": "dynamo_llm::kv_router::publisher=trace,dynamo_llm::kv_router::scheduler=info",
        },
173
    ),
174
175
    "disaggregated": VLLMConfig(
        name="disaggregated",
176
        directory=vllm_dir,
177
        script_name="disagg.sh",
178
        marks=[pytest.mark.gpu_2, pytest.mark.post_merge],
179
        model="Qwen/Qwen3-0.6B",
180
181
182
183
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
        ],
184
    ),
185
186
    "deepep": VLLMConfig(
        name="deepep",
187
        directory=vllm_dir,
188
        script_name="dsr1_dep.sh",
189
190
191
192
        marks=[
            pytest.mark.gpu_2,
            pytest.mark.vllm,
            pytest.mark.h100,
193
            pytest.mark.nightly,
194
        ],
195
        model="deepseek-ai/DeepSeek-V2-Lite",
196
        script_args=[
197
198
199
200
201
202
203
204
205
            "--model",
            "deepseek-ai/DeepSeek-V2-Lite",
            "--num-nodes",
            "1",
            "--node-rank",
            "0",
            "--gpus-per-node",
            "2",
        ],
206
        timeout=700,
207
        request_payloads=[
208
209
            chat_payload_default(),
            completion_payload_default(),
210
        ],
211
    ),
212
213
    "multimodal_agg_llava_epd": VLLMConfig(
        name="multimodal_agg_llava_epd",
214
        directory=vllm_dir,
215
        script_name="agg_multimodal_epd.sh",
216
        marks=[pytest.mark.gpu_2, pytest.mark.nightly],
217
        model="llava-hf/llava-1.5-7b-hf",
218
219
220
221
        script_args=["--model", "llava-hf/llava-1.5-7b-hf"],
        request_payloads=[
            chat_payload(
                [
222
223
224
225
                    {
                        "type": "text",
                        "text": "What colors are in the following image? Respond only with the colors.",
                    },
226
227
                    {
                        "type": "image_url",
228
                        "image_url": {"url": MULTIMODAL_IMG_URL},
229
230
231
                    },
                ],
                repeat_count=1,
232
                expected_response=["purple"],
233
                temperature=0.0,
234
                max_tokens=100,
235
236
            )
        ],
237
    ),
238
239
240
241
    "multimodal_agg_qwen_epd": VLLMConfig(
        name="multimodal_agg_qwen_epd",
        directory=vllm_dir,
        script_name="agg_multimodal_epd.sh",
242
        marks=[pytest.mark.gpu_2, pytest.mark.nightly],
243
244
245
246
247
248
249
        model="Qwen/Qwen2.5-VL-7B-Instruct",
        delayed_start=0,
        script_args=["--model", "Qwen/Qwen2.5-VL-7B-Instruct"],
        timeout=360,
        request_payloads=[
            chat_payload(
                [
250
251
252
253
                    {
                        "type": "text",
                        "text": "What colors are in the following image? Respond only with the colors.",
                    },
254
255
                    {
                        "type": "image_url",
256
                        "image_url": {"url": MULTIMODAL_IMG_URL},
257
258
259
                    },
                ],
                repeat_count=1,
260
261
                expected_response=["purple"],
                max_tokens=100,
262
263
264
            )
        ],
    ),
265
266
    "multimodal_agg_qwen": VLLMConfig(
        name="multimodal_agg_qwen",
267
268
        directory=vllm_dir,
        script_name="agg_multimodal.sh",
269
        marks=[pytest.mark.gpu_2, pytest.mark.nightly],
270
        model="Qwen/Qwen2.5-VL-7B-Instruct",
271
        script_args=["--model", "Qwen/Qwen2.5-VL-7B-Instruct"],
272
        delayed_start=0,
273
        timeout=360,
274
275
276
277
        request_payloads=[
            chat_payload(
                [
                    {
278
279
                        "type": "text",
                        "text": "What colors are in the following image? Respond only with the colors.",
280
                    },
281
282
                    {
                        "type": "image_url",
283
                        "image_url": {"url": MULTIMODAL_IMG_URL},
284
285
286
                    },
                ],
                repeat_count=1,
287
288
                expected_response=["purple"],
                max_tokens=100,
289
            ),
290
        ],
291
    ),
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
    "multimodal_agg_llava": VLLMConfig(
        name="multimodal_agg_llava",
        directory=vllm_dir,
        script_name="agg_multimodal.sh",
        marks=[
            pytest.mark.gpu_2,
            # https://github.com/ai-dynamo/dynamo/issues/4501
            pytest.mark.xfail(strict=False),
        ],
        model="llava-hf/llava-1.5-7b-hf",
        script_args=["--model", "llava-hf/llava-1.5-7b-hf"],
        delayed_start=0,
        timeout=360,
        request_payloads=[
            # HTTP URL test
            chat_payload(
                [
                    {"type": "text", "text": "What is in this image?"},
                    {
                        "type": "image_url",
                        "image_url": {
                            "url": "http://images.cocodataset.org/test2017/000000155781.jpg"
                        },
                    },
                ],
                repeat_count=1,
                expected_response=["bus"],
                temperature=0.0,
            ),
            # String content test - verifies string → array conversion for multimodal templates
            chat_payload_default(
                repeat_count=1,
                expected_response=[],  # Just validate no error
            ),
        ],
    ),
328
    # TODO: Update this test case when we have video multimodal support in vllm official components
329
330
    "multimodal_video_agg": VLLMConfig(
        name="multimodal_video_agg",
331
        directory=os.path.join(WORKSPACE_DIR, "examples/multimodal"),
332
        script_name="video_agg.sh",
333
        marks=[pytest.mark.gpu_2, pytest.mark.nightly],
334
335
        model="llava-hf/LLaVA-NeXT-Video-7B-hf",
        delayed_start=0,
336
        script_args=["--model", "llava-hf/LLaVA-NeXT-Video-7B-hf"],
337
        timeout=360,
338
339
340
341
342
343
344
345
346
347
348
349
350
        request_payloads=[
            chat_payload(
                [
                    {"type": "text", "text": "Describe the video in detail"},
                    {
                        "type": "video_url",
                        "video_url": {
                            "url": "https://storage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
                        },
                    },
                ],
                repeat_count=1,
                expected_response=["rabbit"],
351
                temperature=0.7,
352
353
            )
        ],
354
    ),
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
    "multimodal_audio_agg": VLLMConfig(
        name="multimodal_audio_agg",
        directory="/workspace/examples/multimodal",
        script_name="audio_agg.sh",
        marks=[pytest.mark.gpu_2],
        model="Qwen/Qwen2-Audio-7B-Instruct",
        delayed_start=0,
        script_args=["--model", "Qwen/Qwen2-Audio-7B-Instruct"],
        timeout=500,
        request_payloads=[
            chat_payload(
                [
                    {"type": "text", "text": "What is recited in the audio?"},
                    {
                        "type": "audio_url",
                        "audio_url": {
                            "url": "https://raw.githubusercontent.com/yuekaizhang/Triton-ASR-Client/main/datasets/mini_en/wav/1221-135766-0002.wav"
                        },
                    },
                ],
                repeat_count=1,
                expected_response=[
                    "The original content of this audio is:'yet these thoughts affected Hester Pynne less with hope than apprehension.'"
                ],
                temperature=0.8,
            )
        ],
    ),
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
    "aggregated_toolcalling": VLLMConfig(
        name="aggregated_toolcalling",
        directory=vllm_dir,
        script_name="agg_multimodal.sh",
        marks=[pytest.mark.gpu_2, pytest.mark.multimodal],
        model="Qwen/Qwen3-VL-30B-A3B-Instruct-FP8",
        script_args=[
            "--model",
            "Qwen/Qwen3-VL-30B-A3B-Instruct-FP8",
            "--max-model-len",
            "10000",
            "--dyn-tool-call-parser",
            "hermes",
        ],
        delayed_start=0,
        timeout=600,
        request_payloads=[
            ToolCallingChatPayload(
                body={
                    "messages": [
                        {
                            "role": "user",
                            "content": [
                                {
                                    "type": "text",
                                    "text": "Describe what you see in this image in detail.",
                                },
                                {
                                    "type": "image_url",
                                    "image_url": {"url": MULTIMODAL_IMG_URL},
                                },
                            ],
                        }
                    ],
                    "tools": [
                        {
                            "type": "function",
                            "function": {
                                "name": "describe_image",
                                "description": "Provides detailed description of objects and scenes in an image",
                                "parameters": {
                                    "type": "object",
                                    "properties": {
                                        "objects": {
                                            "type": "array",
                                            "items": {"type": "string"},
                                            "description": "List of objects detected in the image",
                                        },
                                        "scene": {
                                            "type": "string",
                                            "description": "Overall scene description",
                                        },
                                    },
                                    "required": ["objects", "scene"],
                                },
                            },
                        }
                    ],
                    "tool_choice": "auto",
                    "max_tokens": 1024,
                },
                repeat_count=1,
                expected_response=["purple"],  # Validate image understanding
                expected_log=[],
                expected_tool_name="describe_image",  # Validate tool call happened
            )
        ],
    ),
451
452
453
    # TODO: Enable this test case when we have 4 GPUs runners.
    # "multimodal_disagg": VLLMConfig(
    #     name="multimodal_disagg",
454
    #     directory=os.path.join(WORKSPACE_DIR, "examples/multimodal"),
455
456
457
458
    #     script_name="disagg.sh",
    #     marks=[pytest.mark.gpu_4, pytest.mark.vllm],
    #     model="llava-hf/llava-1.5-7b-hf",
    #     delayed_start=45,
459
    #     script_args=["--model", "llava-hf/llava-1.5-7b-hf"],
460
    # ),
461
462
463
464
    "completions_only": VLLMConfig(
        name="completions_only",
        directory=vllm_dir,
        script_name="agg.sh",
465
466
        marks=[
            pytest.mark.gpu_1,
467
468
469
            pytest.mark.timeout(
                420
            ),  # 3x estimated time (60s) + download time (240s) for 7B model
470
        ],
471
472
473
474
475
476
477
478
479
480
481
        model="deepseek-ai/deepseek-llm-7b-base",
        script_args=[
            "--model",
            "deepseek-ai/deepseek-llm-7b-base",
            "--dyn-endpoint-types",
            "completions",
        ],
        request_payloads=[
            completion_payload_default(),
        ],
    ),
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
    "guided_decoding_json": VLLMConfig(
        name="guided_decoding_json",
        directory=vllm_dir,
        script_name="agg.sh",
        marks=[pytest.mark.gpu_1, pytest.mark.pre_merge],
        model="Qwen/Qwen3-0.6B",
        request_payloads=[
            chat_payload(
                "Generate a person with name and age",
                repeat_count=1,
                expected_response=['"name"', '"age"'],
                temperature=0.0,
                max_tokens=100,
                extra_body={
                    "guided_json": {
                        "type": "object",
                        "properties": {
                            "name": {"type": "string"},
                            "age": {"type": "integer"},
                        },
                        "required": ["name", "age"],
                    }
                },
            )
        ],
    ),
    "guided_decoding_regex": VLLMConfig(
        name="guided_decoding_regex",
        directory=vllm_dir,
        script_name="agg.sh",
        marks=[pytest.mark.gpu_1, pytest.mark.pre_merge],
        model="Qwen/Qwen3-0.6B",
        request_payloads=[
            chat_payload(
                "Generate a color name (red, blue, or green)",
                repeat_count=1,
                expected_response=["red", "blue", "green"],
                temperature=0.0,
                max_tokens=20,
                extra_body={"guided_regex": r"(red|blue|green)"},
            )
        ],
    ),
    "guided_decoding_choice": VLLMConfig(
        name="guided_decoding_choice",
        directory=vllm_dir,
        script_name="agg.sh",
        marks=[pytest.mark.gpu_1, pytest.mark.pre_merge],
        model="Qwen/Qwen3-0.6B",
        request_payloads=[
            chat_payload(
                "Generate a color name (red, blue, or green)",
                repeat_count=1,
                expected_response=["red", "blue", "green"],
                temperature=0.0,
                max_tokens=20,
                extra_body={"guided_choice": ["red", "blue", "green"]},
            )
        ],
    ),
542
543
544
}


Alec's avatar
Alec committed
545
@pytest.fixture(params=params_with_model_mark(vllm_configs))
546
547
548
549
550
def vllm_config_test(request):
    """Fixture that provides different vLLM test configurations"""
    return vllm_configs[request.param]


551
@pytest.mark.vllm
552
@pytest.mark.e2e
553
@pytest.mark.nightly
Alec's avatar
Alec committed
554
def test_serve_deployment(
555
    vllm_config_test, request, runtime_services, predownload_models, image_server
Alec's avatar
Alec committed
556
):
557
558
559
560
    """
    Test dynamo serve deployments with different graph configurations.
    """
    config = vllm_config_test
561
    run_serve_deployment(config, request)
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608


@pytest.mark.vllm
@pytest.mark.e2e
@pytest.mark.gpu_2
def test_multimodal_b64(request, runtime_services, predownload_models):
    """
    Test multimodal inference with base64 url passthrough.

    This test is separate because it loads the required image at runtime
    (not collection time), ensuring it only fails when actually executed.
    """
    # Load B64 image at test execution time
    with open(MULTIMODAL_IMG_PATH, "rb") as f:
        b64_img = base64.b64encode(f.read()).decode()

    # Create payload with B64 image
    b64_payload = chat_payload(
        [
            {
                "type": "text",
                "text": "What colors are in the following image? Respond only with the colors.",
            },
            {
                "type": "image_url",
                "image_url": {"url": f"data:image/png;base64,{b64_img}"},
            },
        ],
        repeat_count=1,
        expected_response=["purple"],
        max_tokens=100,
    )

    # Create test config
    config = VLLMConfig(
        name="test_multimodal_b64",
        directory=vllm_dir,
        script_name="agg_multimodal.sh",
        marks=[],  # markers at function-level
        model="Qwen/Qwen2.5-VL-7B-Instruct",
        script_args=["--model", "Qwen/Qwen2.5-VL-7B-Instruct"],
        delayed_start=0,
        timeout=360,
        request_payloads=[b64_payload],
    )

    run_serve_deployment(config, request)