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

"""
Test suite for profile_sla dry-run functionality.

This test ensures that the profile_sla script can successfully run in dry-run mode
8
for vllm, sglang, and trtllm backends with their respective disagg.yaml configurations.
9
10
11
12
"""

import sys
from pathlib import Path
13
from unittest.mock import patch
14
15
16
17
18
19
20
21

import pytest

# Add the project root to sys.path to enable imports
project_root = Path(__file__).parent.parent.parent
sys.path.insert(0, str(project_root))

from benchmarks.profiler.profile_sla import run_profile  # noqa: E402
22
from benchmarks.profiler.utils.model_info import ModelInfo  # noqa: E402
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from benchmarks.profiler.utils.search_space_autogen import (  # noqa: E402
    auto_generate_search_space,
)


# Override the logger fixture from conftest.py to prevent directory creation
@pytest.fixture(autouse=True)
def logger(request):
    """Override the logger fixture to prevent test directory creation.

    This replaces the logger fixture from tests/conftest.py that creates
    directories named after each test.
    """
    # Simply do nothing - no directories created, no file handlers added
    yield
38
39
40
41
42
43


class TestProfileSLADryRun:
    """Test class for profile_sla dry-run functionality."""

    @pytest.fixture
44
    def vllm_args(self, request):
45
46
47
        """Create arguments for vllm backend dry-run test."""

        class Args:
48
49
            def __init__(self):
                self.backend = "vllm"
50
                self.config = "examples/backends/vllm/deploy/disagg.yaml"
51
52
53
                # Use unique output directory per test for parallel execution
                self.output_dir = f"/tmp/test_profiling_results_{request.node.name}"
                self.namespace = f"test-namespace-{request.node.name}"
54
55
                self.model = ""
                self.dgd_image = ""
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
                self.min_num_gpus_per_engine = 1
                self.max_num_gpus_per_engine = 8
                self.skip_existing_results = False
                self.force_rerun = False
                self.isl = 3000
                self.osl = 500
                self.ttft = 50
                self.itl = 10
                self.max_context_length = 16384
                self.prefill_interpolation_granularity = 16
                self.decode_interpolation_granularity = 6
                self.service_name = ""
                self.dry_run = True
                self.use_ai_configurator = False
                self.aic_system = None
71
                self.aic_hf_id = None
72
73
                self.aic_backend = ""
                self.aic_backend_version = None
74
                self.num_gpus_per_node = 8
75
                self.deploy_after_profile = False
76
77
78
79
80
81
82
                # Provide minimal model_info to avoid HF queries
                self.model_info = ModelInfo(
                    model_size=16384.0,
                    architecture="TestArchitecture",
                    is_moe=False,
                    max_context_length=self.max_context_length,
                )
83
84
85
86

        return Args()

    @pytest.fixture
87
    def sglang_args(self, request):
88
89
90
        """Create arguments for sglang backend dry-run test."""

        class Args:
91
92
            def __init__(self):
                self.backend = "sglang"
93
                self.config = "examples/backends/sglang/deploy/disagg.yaml"
94
95
96
                # Use unique output directory per test for parallel execution
                self.output_dir = f"/tmp/test_profiling_results_{request.node.name}"
                self.namespace = f"test-namespace-{request.node.name}"
97
98
                self.model = ""
                self.dgd_image = ""
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
                self.min_num_gpus_per_engine = 1
                self.max_num_gpus_per_engine = 8
                self.skip_existing_results = False
                self.force_rerun = False
                self.isl = 3000
                self.osl = 500
                self.ttft = 50
                self.itl = 10
                self.max_context_length = 16384
                self.prefill_interpolation_granularity = 16
                self.decode_interpolation_granularity = 6
                self.service_name = ""
                self.dry_run = True
                self.use_ai_configurator = False
                self.aic_system = None
114
                self.aic_hf_id = None
115
116
                self.aic_backend = ""
                self.aic_backend_version = None
117
                self.num_gpus_per_node = 8
118
                self.deploy_after_profile = False
119
120
121
122
123
124
                self.model_info = ModelInfo(
                    model_size=16384.0,
                    architecture="TestArchitecture",
                    is_moe=False,
                    max_context_length=self.max_context_length,
                )
125
126
127
128

        return Args()

    @pytest.mark.pre_merge
129
    @pytest.mark.parallel
130
131
132
133
134
135
136
    @pytest.mark.asyncio
    async def test_vllm_dryrun(self, vllm_args):
        """Test that profile_sla dry-run works for vllm backend with disagg.yaml config."""
        # Run the profile in dry-run mode - should complete without errors
        await run_profile(vllm_args)

    @pytest.mark.pre_merge
137
    @pytest.mark.parallel
138
139
140
141
142
    @pytest.mark.asyncio
    async def test_sglang_dryrun(self, sglang_args):
        """Test that profile_sla dry-run works for sglang backend with disagg.yaml config."""
        # Run the profile in dry-run mode - should complete without errors
        await run_profile(sglang_args)
143
144

    @pytest.fixture
145
    def trtllm_args(self, request):
146
147
148
        """Create arguments for trtllm backend dry-run test."""

        class Args:
149
150
            def __init__(self):
                self.backend = "trtllm"
151
                self.config = "examples/backends/trtllm/deploy/disagg.yaml"
152
153
154
                # Use unique output directory per test for parallel execution
                self.output_dir = f"/tmp/test_profiling_results_{request.node.name}"
                self.namespace = f"test-namespace-{request.node.name}"
155
156
                self.model = ""
                self.dgd_image = ""
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
                self.min_num_gpus_per_engine = 1
                self.max_num_gpus_per_engine = 8
                self.skip_existing_results = False
                self.force_rerun = False
                self.isl = 3000
                self.osl = 500
                self.ttft = 50
                self.itl = 10
                self.max_context_length = 16384
                self.prefill_interpolation_granularity = 16
                self.decode_interpolation_granularity = 6
                self.service_name = ""
                self.dry_run = True
                self.use_ai_configurator = False
                self.aic_system = None
172
                self.aic_hf_id = None
173
174
                self.aic_backend = ""
                self.aic_backend_version = None
175
                self.num_gpus_per_node = 8
176
                self.deploy_after_profile = False
177
178
179
180
181
182
                self.model_info = ModelInfo(
                    model_size=16384.0,
                    architecture="TestArchitecture",
                    is_moe=False,
                    max_context_length=self.max_context_length,
                )
183
184
185
186

        return Args()

    @pytest.mark.pre_merge
187
    @pytest.mark.parallel
188
189
190
191
192
    @pytest.mark.asyncio
    async def test_trtllm_dryrun(self, trtllm_args):
        """Test that profile_sla dry-run works for trtllm backend with disagg.yaml config."""
        # Run the profile in dry-run mode - should complete without errors
        await run_profile(trtllm_args)
193
194

    @pytest.fixture
195
    def sglang_moe_args(self, request):
196
197
198
199
200
        """Create arguments for trtllm backend dry-run test."""

        class Args:
            def __init__(self):
                self.backend = "sglang"
201
                self.config = "recipes/deepseek-r1/sglang/disagg-16gpu/deploy.yaml"
202
203
204
                # Use unique output directory per test for parallel execution
                self.output_dir = f"/tmp/test_profiling_results_{request.node.name}"
                self.namespace = f"test-namespace-{request.node.name}"
205
206
                self.model = ""
                self.dgd_image = ""
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
                self.min_num_gpus_per_engine = 8
                self.max_num_gpus_per_engine = 32
                self.skip_existing_results = False
                self.force_rerun = False
                self.isl = 3000
                self.osl = 500
                self.ttft = 50
                self.itl = 10
                self.max_context_length = 16384
                self.prefill_interpolation_granularity = 16
                self.decode_interpolation_granularity = 6
                self.service_name = ""
                self.dry_run = True
                self.use_ai_configurator = False
                self.aic_system = None
222
                self.aic_hf_id = None
223
224
                self.aic_backend = ""
                self.aic_backend_version = None
225
                self.num_gpus_per_node = 8
226
                self.deploy_after_profile = False
227
228
229
230
231
232
233
                self.model_info = ModelInfo(
                    model_size=65536.0,
                    architecture="TestMoEArchitecture",
                    is_moe=True,
                    max_context_length=self.max_context_length,
                    num_experts=16,
                )
234
235
236
237

        return Args()

    @pytest.mark.pre_merge
238
    @pytest.mark.parallel
239
240
241
242
243
    @pytest.mark.asyncio
    async def test_sglang_moe_dryrun(self, sglang_moe_args):
        """Test that profile_sla dry-run works for sglang backend with MoE config."""
        # Run the profile in dry-run mode - should complete without errors
        await run_profile(sglang_moe_args)
244
245
246
247
248
249
250
251
252
253
254
255
256
257

    # Example tests with mocked GPU inventory
    @pytest.fixture
    def mock_h100_gpu_info(self):
        """Mock GPU info for H100 80GB cluster."""
        return {
            "gpus_per_node": 8,
            "model": "h100_sxm",
            "vram": 81920,  # 80GB in MiB
        }

    @pytest.fixture
    def mock_model_info(self):
        """Mock model info for DeepSeek-R1-Distill-Llama-8B."""
258
259
260
261
262
263
        return ModelInfo(
            model_size=16384.0,  # 16GB model in MiB
            architecture="LlamaForCausalLM",
            is_moe=False,
            max_context_length=16384,
        )
264
265

    @pytest.fixture
266
    def vllm_args_with_model_autogen(self, request):
267
268
269
270
271
272
        """Create arguments for vllm backend with model-based search space autogeneration."""

        class Args:
            def __init__(self):
                self.backend = "vllm"
                self.config = ""
273
274
275
                # Use unique output directory per test for parallel execution
                self.output_dir = f"/tmp/test_profiling_results_{request.node.name}"
                self.namespace = f"test-namespace-{request.node.name}"
276
                self.model = "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"  # Specify model for autogen
277
                self.dgd_image = ""
278
279
280
                # Set to 0 to trigger auto-generation path
                self.min_num_gpus_per_engine = 0
                self.max_num_gpus_per_engine = 0
281
282
283
284
285
286
287
288
289
290
291
292
293
                self.skip_existing_results = False
                self.force_rerun = False
                self.isl = 3000
                self.osl = 500
                self.ttft = 50
                self.itl = 10
                self.max_context_length = 0
                self.prefill_interpolation_granularity = 16
                self.decode_interpolation_granularity = 6
                self.service_name = ""
                self.dry_run = True
                self.use_ai_configurator = False
                self.aic_system = None
294
                self.aic_hf_id = None
295
296
                self.aic_backend = ""
                self.aic_backend_version = None
297
298
                # Set to 0 to trigger auto-generation path
                self.num_gpus_per_node = 0
299
                self.deploy_after_profile = False
300
                self.enable_gpu_discovery = True
301
302
303
304

        return Args()

    @pytest.mark.pre_merge
305
    @pytest.mark.parallel
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    @pytest.mark.asyncio
    @patch("benchmarks.profiler.utils.search_space_autogen.get_gpu_summary")
    @patch("benchmarks.profiler.utils.search_space_autogen.get_model_info")
    async def test_profile_with_autogen_search_space_h100(
        self,
        mock_get_model_info,
        mock_get_gpu_summary,
        vllm_args_with_model_autogen,
        mock_h100_gpu_info,
        mock_model_info,
    ):
        """Test profile_sla with auto-generated search space on mocked H100 cluster.

        This test demonstrates how search space is auto-generated based on model
        size and available GPU memory.
        """
        # Configure the mocks to return the appropriate info
        mock_get_model_info.return_value = mock_model_info
        mock_get_gpu_summary.return_value = mock_h100_gpu_info

        # Run the profile - the search space will be auto-generated
        # based on the model and mocked GPU info
        auto_generate_search_space(vllm_args_with_model_autogen)
        await run_profile(vllm_args_with_model_autogen)

    @pytest.fixture
332
    def sglang_args_with_model_autogen(self, request):
333
334
335
336
337
338
        """Create arguments for sglang backend with model-based search space autogeneration."""

        class Args:
            def __init__(self):
                self.backend = "sglang"
                self.config = ""
339
340
341
                # Use unique output directory per test for parallel execution
                self.output_dir = f"/tmp/test_profiling_results_{request.node.name}"
                self.namespace = f"test-namespace-{request.node.name}"
342
                self.model = "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"  # Specify model for autogen
343
                self.dgd_image = ""
344
345
                self.min_num_gpus_per_engine = 0
                self.max_num_gpus_per_engine = 0
346
347
348
349
350
351
352
353
354
355
356
357
358
                self.skip_existing_results = False
                self.force_rerun = False
                self.isl = 3000
                self.osl = 500
                self.ttft = 50
                self.itl = 10
                self.max_context_length = 0
                self.prefill_interpolation_granularity = 16
                self.decode_interpolation_granularity = 6
                self.service_name = ""
                self.dry_run = True
                self.use_ai_configurator = False
                self.aic_system = None
359
                self.aic_hf_id = None
360
361
                self.aic_backend = ""
                self.aic_backend_version = None
362
                self.num_gpus_per_node = 0
363
                self.deploy_after_profile = False
364
                self.enable_gpu_discovery = True
365
366
367
368

        return Args()

    @pytest.mark.pre_merge
369
    @pytest.mark.parallel
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
    @pytest.mark.asyncio
    @patch("benchmarks.profiler.utils.search_space_autogen.get_gpu_summary")
    @patch("benchmarks.profiler.utils.search_space_autogen.get_model_info")
    async def test_sglang_profile_with_autogen_search_space_h100(
        self,
        mock_get_model_info,
        mock_get_gpu_summary,
        sglang_args_with_model_autogen,
        mock_h100_gpu_info,
        mock_model_info,
    ):
        """Test profile_sla with auto-generated search space for sglang on mocked H100 cluster.

        This test demonstrates how search space is auto-generated based on model
        size and available GPU memory for sglang backend.
        """
        # Configure the mocks to return the appropriate info
        mock_get_model_info.return_value = mock_model_info
        mock_get_gpu_summary.return_value = mock_h100_gpu_info

        # Run the profile - the search space will be auto-generated
        # based on the model and mocked GPU info
        auto_generate_search_space(sglang_args_with_model_autogen)
        await run_profile(sglang_args_with_model_autogen)

    @pytest.fixture
396
    def trtllm_args_with_model_autogen(self, request):
397
398
399
400
401
402
        """Create arguments for trtllm backend with model-based search space autogeneration."""

        class Args:
            def __init__(self):
                self.backend = "trtllm"
                self.config = ""
403
404
405
                # Use unique output directory per test for parallel execution
                self.output_dir = f"/tmp/test_profiling_results_{request.node.name}"
                self.namespace = f"test-namespace-{request.node.name}"
406
                self.model = "deepseek-ai/DeepSeek-R1-Distill-Llama-8B"  # Specify model for autogen
407
                self.dgd_image = ""
408
409
                self.min_num_gpus_per_engine = 0
                self.max_num_gpus_per_engine = 0
410
411
412
413
414
415
416
417
418
419
420
421
422
                self.skip_existing_results = False
                self.force_rerun = False
                self.isl = 3000
                self.osl = 500
                self.ttft = 50
                self.itl = 10
                self.max_context_length = 0
                self.prefill_interpolation_granularity = 16
                self.decode_interpolation_granularity = 6
                self.service_name = ""
                self.dry_run = True
                self.use_ai_configurator = False
                self.aic_system = None
423
                self.aic_hf_id = None
424
425
                self.aic_backend = ""
                self.aic_backend_version = None
426
                self.num_gpus_per_node = 0
427
                self.deploy_after_profile = False
428
                self.enable_gpu_discovery = True
429
430
431
432

        return Args()

    @pytest.mark.pre_merge
433
    @pytest.mark.parallel
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    @pytest.mark.asyncio
    @patch("benchmarks.profiler.utils.search_space_autogen.get_gpu_summary")
    @patch("benchmarks.profiler.utils.search_space_autogen.get_model_info")
    async def test_trtllm_profile_with_autogen_search_space_h100(
        self,
        mock_get_model_info,
        mock_get_gpu_summary,
        trtllm_args_with_model_autogen,
        mock_h100_gpu_info,
        mock_model_info,
    ):
        """Test profile_sla with auto-generated search space for trtllm on mocked H100 cluster.

        This test demonstrates how search space is auto-generated based on model
        size and available GPU memory for trtllm backend.
        """
        # Configure the mocks to return the appropriate info
        mock_get_model_info.return_value = mock_model_info
        mock_get_gpu_summary.return_value = mock_h100_gpu_info

        # Run the profile - the search space will be auto-generated
        # based on the model and mocked GPU info
        auto_generate_search_space(trtllm_args_with_model_autogen)
        await run_profile(trtllm_args_with_model_autogen)