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

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

import pytest

14
15
16
17
18
from tests.serve.common import (
    WORKSPACE_DIR,
    params_with_model_mark,
    run_serve_deployment,
)
19
from tests.serve.conftest import MULTIMODAL_IMG_URL, get_multimodal_test_image_bytes
20
from tests.serve.lora_utils import MinioLoraConfig
21
from tests.utils.constants import DefaultPort
22
23
from tests.utils.engine_process import EngineConfig
from tests.utils.payload_builder import (
24
    cached_tokens_chat_payload,
25
26
    chat_payload,
    chat_payload_default,
27
    chat_payload_with_logprobs,
28
    completion_payload_default,
29
    completion_payload_with_logprobs,
30
    metric_payload_default,
31
)
32
from tests.utils.payloads import LoraTestChatPayload, ToolCallingChatPayload
33
34
35
36

logger = logging.getLogger(__name__)


37
38
39
40
41
42
def _is_cuda13() -> bool:
    v = os.environ.get("CUDA_VERSION", "")
    # handles "13", "13.0", "13.0.1", etc.
    return v.startswith("13")


43
@dataclass
44
class VLLMConfig(EngineConfig):
45
46
    """Configuration for vLLM test scenarios"""

47
    stragglers: list[str] = field(default_factory=lambda: ["VLLM:EngineCore"])
48
49


50
vllm_dir = os.environ.get("VLLM_DIR") or os.path.join(
51
    WORKSPACE_DIR, "examples/backends/vllm"
52
)
53

54

55
# vLLM test configurations
56
# NOTE: pytest.mark.gpu_1 tests take ~5.5 minutes total to run sequentially (with models pre-cached)
57
58
59
60
# TODO: Now that these tests use dynamic ports, optimize the runtime by bin-packing and running
# multiple engine deployments in parallel (while keeping GPU contention under control). This may
# require annotating each config with approximate GPU RAM usage so a future collector/launcher can
# bin-pack safely.
61
62
63
vllm_configs = {
    "aggregated": VLLMConfig(
        name="aggregated",
64
        directory=vllm_dir,
65
        script_name="agg.sh",
66
67
68
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
69
            pytest.mark.timeout(300),  # 3x measured time (43s) + download time (150s)
70
        ],
71
        model="Qwen/Qwen3-0.6B",
72
73
74
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
75
76
77
78
79
80
81
82
83
84
85
            chat_payload(
                "Can you write me a song?",
                repeat_count=1,
                expected_response=["song"],
                temperature=0.0,
                max_tokens=32,
                extra_body={
                    "stop": ["song"],
                    "include_stop_str_in_output": True,
                },
            ),
86
            metric_payload_default(min_num_requests=6, backend="vllm"),
87
        ],
88
    ),
89
90
91
92
    "aggregated_logprobs": VLLMConfig(
        name="aggregated_logprobs",
        directory=vllm_dir,
        script_name="agg.sh",
93
        marks=[pytest.mark.gpu_1, pytest.mark.post_merge],
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
        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,
            ),
        ],
    ),
112
113
114
115
    "aggregated_lmcache": VLLMConfig(
        name="aggregated_lmcache",
        directory=vllm_dir,
        script_name="agg_lmcache.sh",
116
117
118
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
119
            pytest.mark.timeout(360),  # 3x estimated time (70s) + download time (150s)
120
            pytest.mark.skipif(
121
122
123
124
                _is_cuda13(),
                reason="lmcache does not support CUDA 13 as of v0.3.11",
                strict=False,
            ),
125
        ],
126
127
128
129
130
131
132
133
        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"),
        ],
    ),
134
135
136
137
    "aggregated_lmcache_multiproc": VLLMConfig(
        name="aggregated_lmcache_multiproc",
        directory=vllm_dir,
        script_name="agg_lmcache_multiproc.sh",
138
139
        marks=[
            pytest.mark.gpu_1,
140
            pytest.mark.pre_merge,
141
            pytest.mark.timeout(360),  # 3x estimated time (70s) + download time (150s)
142
            pytest.mark.skipif(
143
144
145
146
                _is_cuda13(),
                reason="lmcache does not support CUDA 13 as of v0.3.11",
                strict=False,
            ),
147
        ],
148
149
150
151
152
153
154
155
156
157
158
        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"),
        ],
    ),
159
160
161
162
    "agg-request-plane-tcp": VLLMConfig(
        name="agg-request-plane-tcp",
        directory=vllm_dir,
        script_name="agg_request_planes.sh",
163
164
165
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
166
            pytest.mark.timeout(300),  # 3x measured time (43s) + download time (150s)
167
        ],
168
169
170
171
172
173
174
175
176
177
178
        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",
179
180
181
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
182
            pytest.mark.timeout(300),  # 3x measured time (43s) + download time (150s)
183
        ],
184
185
186
187
188
189
190
        model="Qwen/Qwen3-0.6B",
        script_args=["--http"],
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
        ],
    ),
191
192
    "agg-router": VLLMConfig(
        name="agg-router",
193
        directory=vllm_dir,
194
        script_name="agg_router.sh",
Dmitry Tokarev's avatar
Dmitry Tokarev committed
195
196
197
198
199
        marks=[
            pytest.mark.gpu_2,
            pytest.mark.post_merge,
            pytest.mark.skip(reason="DYN-2263"),
        ],
200
        model="Qwen/Qwen3-0.6B",
201
202
203
        request_payloads=[
            chat_payload_default(
                expected_log=[
204
                    r"ZMQ listener .* received batch with \d+ events \(seq=\d+(?:, [^)]*)?\)",
205
                    r"Event processor for worker_id \d+ processing event: Stored\(",
Yan Ru Pei's avatar
Yan Ru Pei committed
206
                    r"Selected worker: worker_id=\d+ dp_rank=.*?, logit: ",
207
208
209
210
                ]
            )
        ],
        env={
211
            "DYN_LOG": "dynamo_llm::kv_router::publisher=trace,dynamo_kv_router::scheduling::selector=info",
212
        },
213
    ),
214
215
216
217
    "agg-router-approx": VLLMConfig(
        name="agg-router-approx",
        directory=vllm_dir,
        script_name="agg_router_approx.sh",
Dmitry Tokarev's avatar
Dmitry Tokarev committed
218
219
220
221
222
        marks=[
            pytest.mark.gpu_2,
            pytest.mark.post_merge,
            pytest.mark.skip(reason="DYN-2264"),
        ],
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
        model="Qwen/Qwen3-0.6B",
        request_payloads=[
            # Test approximate KV routing (--no-kv-events mode)
            # Repeated requests should show cache-aware routing in logs
            chat_payload_default(
                repeat_count=3,
                expected_log=[
                    # Verify scheduler is selecting workers with cache awareness
                    r"Selected worker: worker_id=\d+ dp_rank=.*?, logit: ",
                    # After first request, should see cached blocks being tracked
                    r"with \d+ cached blocks",
                ],
            ),
            # Also test with cached tokens payload to verify usage field
            cached_tokens_chat_payload(
                repeat_count=3,
                expected_log=[
                    # Verify routing decision shows cache hits
                    r"with \d+ cached blocks",
                ],
            ),
        ],
        env={
246
            "DYN_LOG": "dynamo_kv_router::scheduling::selector=info",
247
248
        },
    ),
249
250
    "disaggregated": VLLMConfig(
        name="disaggregated",
251
        directory=vllm_dir,
252
        script_name="disagg.sh",
253
        marks=[pytest.mark.gpu_2, pytest.mark.post_merge],
254
        model="Qwen/Qwen3-0.6B",
255
256
257
258
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
        ],
259
    ),
260
261
    "deepep": VLLMConfig(
        name="deepep",
262
        directory=vllm_dir,
263
        script_name="dsr1_dep.sh",
264
265
266
267
        marks=[
            pytest.mark.gpu_2,
            pytest.mark.vllm,
            pytest.mark.h100,
268
            pytest.mark.nightly,
269
        ],
270
        model="deepseek-ai/DeepSeek-V2-Lite",
271
        script_args=[
272
273
274
275
276
277
278
279
280
            "--model",
            "deepseek-ai/DeepSeek-V2-Lite",
            "--num-nodes",
            "1",
            "--node-rank",
            "0",
            "--gpus-per-node",
            "2",
        ],
281
        timeout=700,
282
        request_payloads=[
283
284
            chat_payload_default(),
            completion_payload_default(),
285
        ],
286
    ),
287
    # NOTE: Pack all workers on 1 GPU for lower CI resource requirements
288
289
    "multimodal_disagg_qwen3vl_2b_e_pd": VLLMConfig(
        name="multimodal_disagg_qwen3vl_2b_e_pd",
290
291
292
        directory=vllm_dir,
        script_name="disagg_multimodal_e_pd.sh",
        marks=[pytest.mark.gpu_1, pytest.mark.pre_merge],
293
294
        model="Qwen/Qwen3-VL-2B-Instruct",
        script_args=["--model", "Qwen/Qwen3-VL-2B-Instruct", "--single-gpu"],
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
        request_payloads=[
            chat_payload(
                [
                    {
                        "type": "text",
                        "text": "What colors are in the following image? Respond only with the colors.",
                    },
                    {
                        "type": "image_url",
                        "image_url": {"url": MULTIMODAL_IMG_URL},
                    },
                ],
                repeat_count=1,
                # With proper prompt templating, the model actually only returns "green",
                # verified behavior with native vLLM.
                expected_response=["green"],
                temperature=0.0,
                max_tokens=100,
            )
        ],
    ),
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
    "multimodal_agg_frontend_decoding": VLLMConfig(
        name="multimodal_agg_frontend_decoding",
        directory=vllm_dir,
        script_name="agg_multimodal.sh",
        marks=[pytest.mark.gpu_1, pytest.mark.pre_merge],
        model="Qwen/Qwen2-VL-2B-Instruct",
        # Pass --frontend-decoding to enable Rust frontend image decoding + NIXL RDMA transfer
        script_args=[
            "--model",
            "Qwen/Qwen2-VL-2B-Instruct",
            "--frontend-decoding",
        ],
        request_payloads=[
            chat_payload(
                [
                    {
                        "type": "text",
                        "text": "What colors are in the following image? Respond only with the colors.",
                    },
                    {
                        "type": "image_url",
                        "image_url": {"url": MULTIMODAL_IMG_URL},
                    },
                ],
                repeat_count=1,
                expected_response=["green"],
                temperature=0.0,
                max_tokens=100,
            )
        ],
    ),
347
    # NOTE: Pack all workers on 1 GPU for lower CI resource requirements
348
349
    "multimodal_disagg_qwen3vl_2b_epd": VLLMConfig(
        name="multimodal_disagg_qwen3vl_2b_epd",
350
        directory=vllm_dir,
351
        script_name="disagg_multimodal_epd.sh",
Dmitry Tokarev's avatar
Dmitry Tokarev committed
352
353
354
355
356
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
            pytest.mark.skip(reason="DYN-2265"),
        ],
357
        model="Qwen/Qwen3-VL-2B-Instruct",
358
359
        script_args=["--model", "Qwen/Qwen3-VL-2B-Instruct", "--single-gpu"],
        timeout=360,
360
361
362
        env={
            "DYN_ENCODE_WORKER_GPU": "0",
            "DYN_PREFILL_WORKER_GPU": "0",
363
364
            "DYN_DECODE_WORKER_GPU": "0",
            "DYN_ENCODE_GPU_MEM": "0.1",
365
            "DYN_PREFILL_GPU_MEM": "0.4",
366
            "DYN_DECODE_GPU_MEM": "0.4",
367
        },
368
369
370
        request_payloads=[
            chat_payload(
                [
371
372
373
374
                    {
                        "type": "text",
                        "text": "What colors are in the following image? Respond only with the colors.",
                    },
375
376
                    {
                        "type": "image_url",
377
                        "image_url": {"url": MULTIMODAL_IMG_URL},
378
379
380
                    },
                ],
                repeat_count=1,
381
                expected_response=["green"],
382
                temperature=0.0,
383
                max_tokens=100,
384
385
            )
        ],
386
    ),
387
388
    "multimodal_agg_qwen": VLLMConfig(
        name="multimodal_agg_qwen",
389
390
        directory=vllm_dir,
        script_name="agg_multimodal.sh",
391
        marks=[pytest.mark.gpu_1, pytest.mark.pre_merge],
392
        model="Qwen/Qwen2.5-VL-7B-Instruct",
393
        script_args=["--model", "Qwen/Qwen2.5-VL-7B-Instruct"],
394
        delayed_start=0,
395
        timeout=360,
396
397
398
399
        request_payloads=[
            chat_payload(
                [
                    {
400
401
                        "type": "text",
                        "text": "What colors are in the following image? Respond only with the colors.",
402
                    },
403
404
                    {
                        "type": "image_url",
405
                        "image_url": {"url": MULTIMODAL_IMG_URL},
406
407
408
                    },
                ],
                repeat_count=1,
409
410
                expected_response=["purple"],
                max_tokens=100,
411
            ),
412
        ],
413
    ),
414
415
416
417
418
    "multimodal_agg_llava": VLLMConfig(
        name="multimodal_agg_llava",
        directory=vllm_dir,
        script_name="agg_multimodal.sh",
        marks=[
419
            pytest.mark.gpu_1,
420
            pytest.mark.nightly,
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
            # 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
            ),
        ],
    ),
451
452
453
    # Video multimodal tests for nightly CI pipeline
    # These tests validate video inference capabilities with LLaVA-NeXT-Video model
    # Reference: Linear OPS-3015
454
455
    "multimodal_video_agg": VLLMConfig(
        name="multimodal_video_agg",
456
        directory=os.path.join(WORKSPACE_DIR, "examples/multimodal"),
457
        script_name="video_agg.sh",
458
        marks=[pytest.mark.gpu_2, pytest.mark.nightly],
459
        model="llava-hf/LLaVA-NeXT-Video-7B-hf",
460
        delayed_start=60,  # Video models require longer loading time
461
        script_args=["--model", "llava-hf/LLaVA-NeXT-Video-7B-hf"],
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
        timeout=600,  # 10 minutes for video processing overhead
        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"],
                temperature=0.0,
                max_tokens=100,
            )
        ],
    ),
    "multimodal_video_disagg": VLLMConfig(
        name="multimodal_video_disagg",
        directory=os.path.join(WORKSPACE_DIR, "examples/multimodal"),
        script_name="video_disagg.sh",
        marks=[pytest.mark.gpu_2, pytest.mark.nightly],
        model="llava-hf/LLaVA-NeXT-Video-7B-hf",
        delayed_start=60,  # Video models require longer loading time
        script_args=["--model", "llava-hf/LLaVA-NeXT-Video-7B-hf"],
        timeout=600,  # 10 minutes for video processing overhead
490
491
492
493
494
495
496
497
498
499
500
501
502
        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"],
503
504
                temperature=0.0,
                max_tokens=100,
505
506
            )
        ],
507
    ),
508
509
    # Audio multimodal tests for nightly CI pipeline
    # These tests validate audio inference capabilities with Qwen2-Audio model
510
511
    "multimodal_audio_agg": VLLMConfig(
        name="multimodal_audio_agg",
512
        directory=os.path.join(WORKSPACE_DIR, "examples/multimodal"),
513
        script_name="audio_agg.sh",
514
        marks=[pytest.mark.gpu_2, pytest.mark.nightly],
515
        model="Qwen/Qwen2-Audio-7B-Instruct",
516
        delayed_start=60,  # Audio models require longer loading time
517
        script_args=["--model", "Qwen/Qwen2-Audio-7B-Instruct"],
518
        timeout=600,  # 10 minutes for audio processing overhead
519
520
521
522
523
524
525
526
527
528
529
530
        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,
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
                expected_response=["Hester", "Pynne"],
                temperature=0.0,
                max_tokens=100,
            )
        ],
    ),
    "multimodal_audio_disagg": VLLMConfig(
        name="multimodal_audio_disagg",
        directory=os.path.join(WORKSPACE_DIR, "examples/multimodal"),
        script_name="audio_disagg.sh",
        marks=[pytest.mark.gpu_2, pytest.mark.nightly],
        model="Qwen/Qwen2-Audio-7B-Instruct",
        delayed_start=60,  # Audio models require longer loading time
        script_args=["--model", "Qwen/Qwen2-Audio-7B-Instruct"],
        timeout=600,  # 10 minutes for audio processing overhead
        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"
                        },
                    },
556
                ],
557
558
559
560
                repeat_count=1,
                expected_response=["Hester", "Pynne"],
                temperature=0.0,
                max_tokens=100,
561
562
563
            )
        ],
    ),
564
565
566
567
    "aggregated_toolcalling": VLLMConfig(
        name="aggregated_toolcalling",
        directory=vllm_dir,
        script_name="agg_multimodal.sh",
568
        marks=[pytest.mark.gpu_2, pytest.mark.multimodal, pytest.mark.nightly],
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
        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
            )
        ],
    ),
632
633
634
    # TODO: Enable this test case when we have 4 GPUs runners.
    # "multimodal_disagg": VLLMConfig(
    #     name="multimodal_disagg",
635
    #     directory=os.path.join(WORKSPACE_DIR, "examples/multimodal"),
636
637
638
639
    #     script_name="disagg.sh",
    #     marks=[pytest.mark.gpu_4, pytest.mark.vllm],
    #     model="llava-hf/llava-1.5-7b-hf",
    #     delayed_start=45,
640
    #     script_args=["--model", "llava-hf/llava-1.5-7b-hf"],
641
    # ),
642
643
644
645
    "completions_only": VLLMConfig(
        name="completions_only",
        directory=vllm_dir,
        script_name="agg.sh",
646
647
        marks=[
            pytest.mark.gpu_1,
648
            pytest.mark.post_merge,
649
650
651
            pytest.mark.timeout(
                420
            ),  # 3x estimated time (60s) + download time (240s) for 7B model
652
        ],
653
654
655
656
657
658
659
660
661
662
663
        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(),
        ],
    ),
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
    "multi_node_tp_headless": VLLMConfig(
        name="multi_node_tp_headless",
        directory=os.path.join(WORKSPACE_DIR, "tests/serve"),
        script_name="multi_node_tp_headless.sh",
        marks=[
            pytest.mark.gpu_2,
            pytest.mark.post_merge,
            pytest.mark.timeout(300),
        ],
        model="Qwen/Qwen3-0.6B",
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
        ],
    ),
679
680
    "guided_decoding": VLLMConfig(
        name="guided_decoding",
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
        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"],
                    }
                },
702
            ),
703
704
705
706
707
708
709
            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)"},
710
            ),
711
712
713
714
715
716
717
            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"]},
718
            ),
719
720
        ],
    ),
721
722
723
}


Alec's avatar
Alec committed
724
@pytest.fixture(params=params_with_model_mark(vllm_configs))
725
726
727
728
729
def vllm_config_test(request):
    """Fixture that provides different vLLM test configurations"""
    return vllm_configs[request.param]


730
@pytest.mark.vllm
731
@pytest.mark.e2e
Alec's avatar
Alec committed
732
def test_serve_deployment(
733
734
735
736
737
738
    vllm_config_test,
    request,
    runtime_services_dynamic_ports,
    dynamo_dynamic_ports,
    predownload_models,
    image_server,
Alec's avatar
Alec committed
739
):
740
741
742
    """
    Test dynamo serve deployments with different graph configurations.
    """
743
744
745
746
    config = dataclasses.replace(
        vllm_config_test, frontend_port=dynamo_dynamic_ports.frontend_port
    )
    run_serve_deployment(config, request, ports=dynamo_dynamic_ports)
747
748
749
750
751


@pytest.mark.vllm
@pytest.mark.e2e
@pytest.mark.gpu_2
752
@pytest.mark.nightly
753
754
@pytest.mark.timeout(360)  # Match VLLMConfig.timeout for this multimodal deployment
def test_multimodal_b64(
755
756
757
758
    request,
    runtime_services_dynamic_ports,
    dynamo_dynamic_ports,
    predownload_models,
759
):
760
761
762
763
764
765
    """
    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.
    """
766
767
    # Load B64 image at test execution time (uses real PNG even if MULTIMODAL_IMG is LFS pointer)
    b64_img = base64.b64encode(get_multimodal_test_image_bytes()).decode()
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798

    # 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],
    )

799
800
801
802
    config = dataclasses.replace(
        config, frontend_port=dynamo_dynamic_ports.frontend_port
    )
    run_serve_deployment(config, request, ports=dynamo_dynamic_ports)
803
804
805
806
807
808
809
810
811


# LoRA Test Directory
lora_dir = os.path.join(vllm_dir, "launch/lora")


def lora_chat_payload(
    lora_name: str,
    s3_uri: str,
812
    system_port: int = DefaultPort.SYSTEM1.value,
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
    repeat_count: int = 2,
    expected_response: Optional[list] = None,
    expected_log: Optional[list] = None,
    max_tokens: int = 100,
    temperature: float = 0.0,
) -> LoraTestChatPayload:
    """Create a LoRA-enabled chat payload for testing"""
    return LoraTestChatPayload(
        body={
            "model": lora_name,
            "messages": [
                {
                    "role": "user",
                    "content": "What is deep learning? Answer in one sentence.",
                }
            ],
            "max_tokens": max_tokens,
            "temperature": temperature,
            "stream": False,
        },
        lora_name=lora_name,
        s3_uri=s3_uri,
        system_port=system_port,
        repeat_count=repeat_count,
        expected_response=expected_response
        or ["learning", "neural", "network", "AI", "model"],
        expected_log=expected_log or [],
    )


@pytest.mark.vllm
@pytest.mark.e2e
@pytest.mark.gpu_1
@pytest.mark.model("Qwen/Qwen3-0.6B")
@pytest.mark.timeout(600)
848
@pytest.mark.post_merge
Dmitry Tokarev's avatar
Dmitry Tokarev committed
849
@pytest.mark.skip(reason="DYN-2260")
850
def test_lora_aggregated(
851
852
853
854
855
    request,
    runtime_services_dynamic_ports,
    predownload_models,
    minio_lora_service,
    dynamo_dynamic_ports,
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
):
    """
    Test LoRA inference with aggregated vLLM deployment.

    This test:
    1. Uses MinIO fixture to provide S3-compatible storage with uploaded LoRA
    2. Starts vLLM with LoRA support enabled
    3. Loads the LoRA adapter via system API
    4. Runs inference with the LoRA model
    """
    minio_config: MinioLoraConfig = minio_lora_service

    # Create payload that loads LoRA and tests inference
    lora_payload = lora_chat_payload(
        lora_name=minio_config.lora_name,
        s3_uri=minio_config.get_s3_uri(),
872
        system_port=DefaultPort.SYSTEM1.value,
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
        repeat_count=2,
    )

    # Create test config with MinIO environment variables
    config = VLLMConfig(
        name="test_lora_aggregated",
        directory=vllm_dir,
        script_name="lora/agg_lora.sh",
        marks=[],  # markers at function-level
        model="Qwen/Qwen3-0.6B",
        timeout=600,
        env=minio_config.get_env_vars(),
        request_payloads=[lora_payload],
    )

888
889
890
891
892
893
894
895
896
    config = dataclasses.replace(
        config, frontend_port=dynamo_dynamic_ports.frontend_port
    )
    run_serve_deployment(
        config,
        request,
        ports=dynamo_dynamic_ports,
        extra_env=minio_config.get_env_vars(),
    )
897
898
899
900
901
902
903


@pytest.mark.vllm
@pytest.mark.e2e
@pytest.mark.gpu_2
@pytest.mark.model("Qwen/Qwen3-0.6B")
@pytest.mark.timeout(600)
904
@pytest.mark.post_merge
905
@pytest.mark.parametrize("num_system_ports", [2], indirect=True)
Dmitry Tokarev's avatar
Dmitry Tokarev committed
906
@pytest.mark.skip(reason="DYN-2265")
907
def test_lora_aggregated_router(
908
909
910
911
912
    request,
    runtime_services_dynamic_ports,
    predownload_models,
    minio_lora_service,
    dynamo_dynamic_ports,
913
    num_system_ports,
914
915
916
917
918
919
920
921
922
923
):
    """
    Test LoRA inference with aggregated vLLM deployment using KV router.

    This test:
    1. Uses MinIO fixture to provide S3-compatible storage with uploaded LoRA
    2. Starts multiple vLLM workers with LoRA support and KV router
    3. Loads the LoRA adapter on both workers via system API
    4. Runs inference with the LoRA model, verifying KV cache routing
    """
924
925
926
    assert (
        num_system_ports >= 2
    ), "serve tests require at least SYSTEM_PORT1 + SYSTEM_PORT2"
927
928
929
    minio_config: MinioLoraConfig = minio_lora_service

    # Create payloads that load LoRA on both workers and test inference
930
    # Worker 1 (DefaultPort.SYSTEM1)
931
932
933
    lora_payload_worker1 = lora_chat_payload(
        lora_name=minio_config.lora_name,
        s3_uri=minio_config.get_s3_uri(),
934
        system_port=DefaultPort.SYSTEM1.value,
935
936
937
        repeat_count=1,
    )

938
    # Worker 2 (DefaultPort.SYSTEM2)
939
940
941
    lora_payload_worker2 = lora_chat_payload(
        lora_name=minio_config.lora_name,
        s3_uri=minio_config.get_s3_uri(),
942
        system_port=DefaultPort.SYSTEM2.value,
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
        repeat_count=1,
    )

    # Additional inference payload to test routing (LoRA already loaded)
    inference_payload = chat_payload(
        content="Explain machine learning in simple terms.",
        repeat_count=2,
        expected_response=["learn", "data", "algorithm", "model", "pattern"],
        max_tokens=150,
        temperature=0.0,
    ).with_model(minio_config.lora_name)

    # Add env vars including PYTHONHASHSEED for deterministic KV event IDs
    env_vars = minio_config.get_env_vars()
    env_vars["PYTHONHASHSEED"] = "0"

    # Create test config with MinIO environment variables
    config = VLLMConfig(
        name="test_lora_aggregated_router",
        directory=vllm_dir,
        script_name="lora/agg_lora_router.sh",
        marks=[],  # markers at function-level
        model="Qwen/Qwen3-0.6B",
        timeout=600,
        env=env_vars,
        request_payloads=[
            lora_payload_worker1,
            lora_payload_worker2,
            inference_payload,
        ],
    )

975
976
977
978
979
980
    config = dataclasses.replace(
        config, frontend_port=dynamo_dynamic_ports.frontend_port
    )
    run_serve_deployment(
        config, request, ports=dynamo_dynamic_ports, extra_env=env_vars
    )