test_triton_attention_backend.py 1.62 KB
Newer Older
1
2
3
4
5
"""
Usage:
python3 -m unittest test_triton_attention_backend.TestTritonAttnBackend.test_mmlu
"""

Lianmin Zheng's avatar
Lianmin Zheng committed
6
7
8
import unittest
from types import SimpleNamespace

9
from sglang.srt.utils import kill_process_tree
Lianmin Zheng's avatar
Lianmin Zheng committed
10
11
12
from sglang.test.run_eval import run_eval
from sglang.test.test_utils import (
    DEFAULT_MODEL_NAME_FOR_TEST,
13
14
    DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
    DEFAULT_URL_FOR_TEST,
15
    CustomTestCase,
16
    is_in_ci,
Lianmin Zheng's avatar
Lianmin Zheng committed
17
    popen_launch_server,
18
    run_bench_one_batch,
Lianmin Zheng's avatar
Lianmin Zheng committed
19
20
21
)


22
class TestTritonAttnBackend(CustomTestCase):
23
    def test_latency(self):
24
        output_throughput = run_bench_one_batch(
25
26
27
28
29
            DEFAULT_MODEL_NAME_FOR_TEST,
            [
                "--attention-backend",
                "triton",
                "--enable-torch-compile",
30
                "--cuda-graph-max-bs",
31
                4,
32
            ],
Lianmin Zheng's avatar
Lianmin Zheng committed
33
34
        )

35
        if is_in_ci():
36
            self.assertGreater(output_throughput, 153)
Lianmin Zheng's avatar
Lianmin Zheng committed
37
38

    def test_mmlu(self):
39
40
41
42
43
44
45
        model = DEFAULT_MODEL_NAME_FOR_TEST
        base_url = DEFAULT_URL_FOR_TEST
        process = popen_launch_server(
            model,
            base_url,
            timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
            other_args=["--attention-backend", "triton"],
Lianmin Zheng's avatar
Lianmin Zheng committed
46
47
        )

48
49
50
51
52
53
54
55
56
57
        try:
            args = SimpleNamespace(
                base_url=base_url,
                model=model,
                eval_name="mmlu",
                num_examples=64,
                num_threads=32,
            )

            metrics = run_eval(args)
58
            self.assertGreaterEqual(metrics["score"], 0.65)
59
        finally:
60
            kill_process_tree(process.pid)
Lianmin Zheng's avatar
Lianmin Zheng committed
61
62
63
64


if __name__ == "__main__":
    unittest.main()