test_dp_attention.py 1.63 KB
Newer Older
Ke Bao's avatar
Ke Bao committed
1
2
3
import unittest
from types import SimpleNamespace

4
from sglang.srt.utils import kill_process_tree
Ke Bao's avatar
Ke Bao committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from sglang.test.run_eval import run_eval
from sglang.test.test_utils import (
    DEFAULT_MLA_MODEL_NAME_FOR_TEST,
    DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
    DEFAULT_URL_FOR_TEST,
    popen_launch_server,
)


class TestDPAttention(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.model = DEFAULT_MLA_MODEL_NAME_FOR_TEST
        cls.base_url = DEFAULT_URL_FOR_TEST
        cls.process = popen_launch_server(
            cls.model,
            cls.base_url,
            timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
            other_args=[
                "--trust-remote-code",
                "--tp",
                "2",
                "--enable-dp-attention",
Lianmin Zheng's avatar
Lianmin Zheng committed
28
29
                "--dp",
                "2",
Ke Bao's avatar
Ke Bao committed
30
31
32
33
34
            ],
        )

    @classmethod
    def tearDownClass(cls):
35
        kill_process_tree(cls.process.pid)
Ke Bao's avatar
Ke Bao committed
36
37
38
39
40
41
42
43
44
45
46

    def test_mmlu(self):
        args = SimpleNamespace(
            base_url=self.base_url,
            model=self.model,
            eval_name="mmlu",
            num_examples=64,
            num_threads=32,
        )

        metrics = run_eval(args)
Lianmin Zheng's avatar
Lianmin Zheng committed
47
48
        print(f"{metrics=}")
        self.assertGreater(metrics["score"], 0.5)
Ke Bao's avatar
Ke Bao committed
49
50
51
52
53
54
55
56
57
58
59

    def test_mgsm_en(self):
        args = SimpleNamespace(
            base_url=self.base_url,
            model=self.model,
            eval_name="mgsm_en",
            num_examples=None,
            num_threads=1024,
        )

        metrics = run_eval(args)
Lianmin Zheng's avatar
Lianmin Zheng committed
60
61
        print(f"{metrics=}")
        self.assertGreater(metrics["score"], 0.8)
Ke Bao's avatar
Ke Bao committed
62
63
64
65


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