test_sglang.py 2.94 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

Alec's avatar
Alec committed
10
11
12
13
14
from tests.serve.common import (
    SERVE_TEST_DIR,
    params_with_model_mark,
    run_serve_deployment,
)
15
16
from tests.utils.engine_process import EngineConfig
from tests.utils.payload_builder import chat_payload_default, completion_payload_default
17
18
19
20
21

logger = logging.getLogger(__name__)


@dataclass
22
class SGLangConfig(EngineConfig):
23
24
    """Configuration for SGLang test scenarios"""

25
    stragglers: list[str] = field(default_factory=lambda: ["SGLANG:EngineCore"])
26
27


28
sglang_dir = os.environ.get("SGLANG_DIR", "/workspace/components/backends/sglang")
29
30
31

sglang_configs = {
    "aggregated": SGLangConfig(
32
        name="aggregated",
Alec's avatar
Alec committed
33
        directory=SERVE_TEST_DIR,
34
        script_name="sglang_agg.sh",
35
        marks=[pytest.mark.gpu_1],
36
        model="deepseek-ai/DeepSeek-R1-Distill-Llama-8B",
37
38
39
        env={},
        models_port=8000,
        request_payloads=[chat_payload_default(), completion_payload_default()],
40
41
    ),
    "disaggregated": SGLangConfig(
42
43
44
45
46
47
48
49
        name="disaggregated",
        directory=sglang_dir,
        script_name="disagg.sh",
        marks=[pytest.mark.gpu_2],
        model="Qwen/Qwen3-0.6B",
        env={},
        models_port=8000,
        request_payloads=[chat_payload_default(), completion_payload_default()],
50
    ),
51
    "kv_events": SGLangConfig(
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
        name="kv_events",
        directory=sglang_dir,
        script_name="agg_router.sh",
        marks=[pytest.mark.gpu_2],
        model="Qwen/Qwen3-0.6B",
        env={
            "DYN_LOG": "dynamo_llm::kv_router::publisher=trace,dynamo_llm::kv_router::scheduler=info",
        },
        models_port=8000,
        request_payloads=[
            chat_payload_default(
                expected_log=[
                    r"ZMQ listener .* received batch with \d+ events \(seq=\d+\)",
                    r"Event processor for worker_id \d+ processing event: Stored\(",
                    r"Selected worker: \d+, logit: ",
                ]
            )
        ],
70
    ),
71
72
73
}


Alec's avatar
Alec committed
74
@pytest.fixture(params=params_with_model_mark(sglang_configs))
75
76
77
78
79
80
81
def sglang_config_test(request):
    """Fixture that provides different SGLang test configurations"""
    return sglang_configs[request.param]


@pytest.mark.e2e
@pytest.mark.sglang
Alec's avatar
Alec committed
82
83
84
def test_sglang_deployment(
    sglang_config_test, request, runtime_services, predownload_models
):
85
    """Test SGLang deployment scenarios using common helpers"""
86
    config = sglang_config_test
87
    run_serve_deployment(config, request)
88
89


90
91
92
@pytest.mark.skip(
    reason="Requires 4 GPUs - enable when hardware is consistently available"
)
Alec's avatar
Alec committed
93
def test_sglang_disagg_dp_attention(request, runtime_services, predownload_models):
94
95
    """Test sglang disaggregated with DP attention (requires 4 GPUs)"""

96
    # Kept for reference; this test uses a different launch path and is skipped