test_double_sparsity.py 1.86 KB
Newer Older
Shuo Yang's avatar
Shuo Yang committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
import unittest
from types import SimpleNamespace

from sglang.srt.utils import kill_child_process
from sglang.test.run_eval import run_eval
from sglang.test.test_utils import (
    DEFAULT_MODEL_NAME_FOR_TEST,
    DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
    DEFAULT_URL_FOR_TEST,
    popen_launch_server,
)


class TestDoubleSparsity(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.model = DEFAULT_MODEL_NAME_FOR_TEST
        cls.base_url = DEFAULT_URL_FOR_TEST
        dirpath = os.path.dirname(__file__)
21
22
23
        config_file = os.path.join(
            dirpath, "double-sparsity-config-Llama-3.1-8B-Instruct.json"
        )
Shuo Yang's avatar
Shuo Yang committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
        # NOTE: Generate the config file by running https://github.com/andy-yang-1/DoubleSparse/blob/main/evaluation/group_channel_config.py
        cls.process = popen_launch_server(
            cls.model,
            cls.base_url,
            timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
            other_args=[
                "--enable-double-sparsity",
                "--ds-channel-config-path",
                config_file,
                "--ds-heavy-channel-num",
                "32",
                "--ds-heavy-channel-type",
                "k",
                "--ds-heavy-token-num",
                "512",
                "--ds-sparse-decode-threshold",
                "0",
                "--max-total-tokens",
                "200000",
            ],
        )

    @classmethod
    def tearDownClass(cls):
Lianmin Zheng's avatar
Lianmin Zheng committed
48
        kill_child_process(cls.process.pid, include_self=True)
Shuo Yang's avatar
Shuo Yang committed
49
50
51
52
53
54
55
56
57
58
59

    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)
60
        self.assertGreaterEqual(metrics["score"], 0.65)
Shuo Yang's avatar
Shuo Yang committed
61
62
63
64


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