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

import logging
import os
6
from dataclasses import dataclass, field
7
8
9

import pytest

10
11
12
13
14
from tests.serve.common import (
    WORKSPACE_DIR,
    params_with_model_mark,
    run_serve_deployment,
)
15
from tests.utils.engine_process import EngineConfig
16
from tests.utils.payload_builder import (
17
18
    TEXT_PROMPT,
    chat_payload,
19
    chat_payload_default,
20
    completion_payload,
21
22
    completion_payload_default,
    metric_payload_default,
23
    multimodal_payload_default,
24
)
25
26
27
28
29

logger = logging.getLogger(__name__)


@dataclass
30
class TRTLLMConfig(EngineConfig):
31
32
    """Configuration for trtllm test scenarios"""

33
    stragglers: list[str] = field(default_factory=lambda: ["TRTLLM:EngineCore"])
34

35

36
trtllm_dir = os.environ.get("TRTLLM_DIR") or os.path.join(
37
    WORKSPACE_DIR, "examples/backends/trtllm"
38
)
39

40
41
42
# TensorRT-LLM test configurations
# NOTE: pytest.mark.gpu_1 tests take ~442s (7m 22s) total to run sequentially (with models pre-cached)
# TODO: Parallelize these tests to reduce total execution time
43
44
45
trtllm_configs = {
    "aggregated": TRTLLMConfig(
        name="aggregated",
46
        directory=trtllm_dir,
47
        script_name="agg_metrics.sh",
48
49
50
51
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
            pytest.mark.trtllm,
52
53
54
            pytest.mark.timeout(
                300
            ),  # 3x measured time (44.66s) + download time (150s)
55
        ],
56
        model="Qwen/Qwen3-0.6B",
57
58
59
60
        models_port=8000,
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
61
            metric_payload_default(min_num_requests=6, backend="trtllm"),
62
        ],
63
64
65
    ),
    "disaggregated": TRTLLMConfig(
        name="disaggregated",
66
        directory=trtllm_dir,
67
        script_name="disagg.sh",
68
        marks=[pytest.mark.gpu_2, pytest.mark.trtllm, pytest.mark.post_merge],
69
        model="Qwen/Qwen3-0.6B",
70
71
72
73
74
        models_port=8000,
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
        ],
75
    ),
76
77
78
79
    "disaggregated_same_gpu": TRTLLMConfig(
        name="disaggregated_same_gpu",
        directory=trtllm_dir,
        script_name="disagg_same_gpu.sh",
80
81
82
83
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
            pytest.mark.trtllm,
84
            pytest.mark.skip(reason="unstable"),
85
86
87
            pytest.mark.timeout(
                480
            ),  # 3x measured time (103.66s) + download time (150s)
88
        ],
89
90
91
92
93
94
95
96
97
        model="Qwen/Qwen3-0.6B",
        models_port=8000,
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
            metric_payload_default(port=8081, min_num_requests=6, backend="trtllm"),
            metric_payload_default(port=8082, min_num_requests=6, backend="trtllm"),
        ],
    ),
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    "aggregated_logprobs": TRTLLMConfig(
        name="aggregated_logprobs",
        directory=trtllm_dir,
        script_name="agg.sh",
        marks=[pytest.mark.gpu_1, pytest.mark.pre_merge, pytest.mark.trtllm],
        model="Qwen/Qwen3-0.6B",
        models_port=8000,
        request_payloads=[
            chat_payload(content=TEXT_PROMPT, logprobs=True, top_logprobs=5),
            chat_payload(content=TEXT_PROMPT, logprobs=False, top_logprobs=5),
            chat_payload(content=TEXT_PROMPT, logprobs=True, top_logprobs=None),
            chat_payload(content=TEXT_PROMPT, logprobs=True, top_logprobs=0),
        ],
    ),
    "disaggregated_logprobs": TRTLLMConfig(
        name="disaggregated_logprobs",
        directory=trtllm_dir,
        script_name="disagg.sh",
        marks=[pytest.mark.gpu_2, pytest.mark.post_merge, pytest.mark.trtllm],
        model="Qwen/Qwen3-0.6B",
        models_port=8000,
        request_payloads=[
            chat_payload(content=TEXT_PROMPT, logprobs=True, top_logprobs=5),
            chat_payload(content=TEXT_PROMPT, logprobs=False, top_logprobs=5),
            chat_payload(content=TEXT_PROMPT, logprobs=True, top_logprobs=None),
            chat_payload(content=TEXT_PROMPT, logprobs=True, top_logprobs=0),
        ],
    ),
126
127
    "aggregated_router": TRTLLMConfig(
        name="aggregated_router",
128
        directory=trtllm_dir,
129
        script_name="agg_router.sh",
130
131
132
133
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.pre_merge,
            pytest.mark.trtllm,
134
135
136
            pytest.mark.timeout(
                300
            ),  # 3x measured time (37.91s) + download time (180s)
137
        ],
138
        model="Qwen/Qwen3-0.6B",
139
140
141
142
143
        models_port=8000,
        request_payloads=[
            chat_payload_default(
                expected_log=[
                    r"Event processor for worker_id \d+ processing event: Stored\(",
Yan Ru Pei's avatar
Yan Ru Pei committed
144
                    r"Selected worker: worker_id=\d+ dp_rank=.*?, logit: ",
145
146
147
148
149
150
                ]
            )
        ],
        env={
            "DYN_LOG": "dynamo_llm::kv_router::publisher=trace,dynamo_llm::kv_router::scheduler=info",
        },
151
152
153
    ),
    "disaggregated_router": TRTLLMConfig(
        name="disaggregated_router",
154
        directory=trtllm_dir,
155
        script_name="disagg_router.sh",
156
        marks=[pytest.mark.gpu_2, pytest.mark.trtllm, pytest.mark.nightly],
157
        model="Qwen/Qwen3-0.6B",
158
159
160
161
162
        models_port=8000,
        request_payloads=[
            chat_payload_default(),
            completion_payload_default(),
        ],
163
    ),
164
165
166
167
    "disaggregated_multimodal": TRTLLMConfig(
        name="disaggregated_multimodal",
        directory=trtllm_dir,
        script_name="disagg_multimodal.sh",
168
        marks=[pytest.mark.gpu_2, pytest.mark.trtllm, pytest.mark.multimodal],
169
170
171
172
173
174
        model="Qwen/Qwen2-VL-7B-Instruct",
        models_port=8000,
        timeout=900,
        delayed_start=60,
        request_payloads=[multimodal_payload_default()],
    ),
175
176
177
178
    "completions_only": TRTLLMConfig(
        name="completions_only",
        directory=trtllm_dir,
        script_name="agg.sh",
179
180
181
        marks=[
            pytest.mark.gpu_1,
            pytest.mark.trtllm,
182
183
184
            pytest.mark.timeout(
                480
            ),  # 3x measured time (83.85s) + download time (210s) for 7B model
185
        ],
186
187
188
189
190
191
192
193
        model="deepseek-ai/deepseek-llm-7b-base",
        script_args=["--dyn-endpoint-types", "completions"],
        env={
            "MODEL_PATH": "deepseek-ai/deepseek-llm-7b-base",
            "SERVED_MODEL_NAME": "deepseek-ai/deepseek-llm-7b-base",
        },
        request_payloads=[
            completion_payload_default(),
194
            completion_payload(prompt=TEXT_PROMPT, logprobs=3),
195
196
        ],
    ),
197
198
199
}


Alec's avatar
Alec committed
200
@pytest.fixture(params=params_with_model_mark(trtllm_configs))
201
202
def trtllm_config_test(request):
    """Fixture that provides different trtllm test configurations"""
203
    return trtllm_configs[request.param]
204
205


206
@pytest.mark.trtllm
207
@pytest.mark.e2e
Alec's avatar
Alec committed
208
def test_deployment(trtllm_config_test, request, runtime_services, predownload_models):
209
210
211
212
    """
    Test dynamo deployments with different configurations.
    """
    config = trtllm_config_test
213
214
    extra_env = {"MODEL_PATH": config.model, "SERVED_MODEL_NAME": config.model}
    run_serve_deployment(config, request, extra_env=extra_env)
215
216


217
# TODO make this a normal guy
218
219
@pytest.mark.e2e
@pytest.mark.gpu_1
220
@pytest.mark.trtllm
221
@pytest.mark.timeout(660)  # 3x measured time (159.68s) + download time (180s)
222
def test_chat_only_aggregated_with_test_logits_processor(
Alec's avatar
Alec committed
223
    request, runtime_services, predownload_models, monkeypatch
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
):
    """
    Run a single aggregated chat-completions test using Qwen 0.6B with the
    test logits processor enabled, and expect "Hello world" in the response.
    """

    # Enable HelloWorld logits processor only for this test
    monkeypatch.setenv("DYNAMO_ENABLE_TEST_LOGITS_PROCESSOR", "1")

    base = trtllm_configs["aggregated"]
    config = TRTLLMConfig(
        name="aggregated_qwen_chatonly",
        directory=base.directory,
        script_name=base.script_name,  # agg.sh
        marks=[],  # not used by this direct test
239
        request_payloads=[
240
            chat_payload_default(expected_response=["Hello world!"]),
241
        ],
242
243
244
245
246
        model="Qwen/Qwen3-0.6B",
        delayed_start=base.delayed_start,
        timeout=base.timeout,
    )

247
    run_serve_deployment(config, request)