test_double_sparsity.py 1.86 KB
Newer Older
Shuo Yang's avatar
Shuo Yang committed
1
2
3
4
import os
import unittest
from types import SimpleNamespace

5
from sglang.srt.utils import kill_process_tree
Shuo Yang's avatar
Shuo Yang committed
6
7
8
9
10
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,
11
    CustomTestCase,
Shuo Yang's avatar
Shuo Yang committed
12
13
14
15
    popen_launch_server,
)


16
class TestDoubleSparsity(CustomTestCase):
Shuo Yang's avatar
Shuo Yang committed
17
18
19
20
21
    @classmethod
    def setUpClass(cls):
        cls.model = DEFAULT_MODEL_NAME_FOR_TEST
        cls.base_url = DEFAULT_URL_FOR_TEST
        dirpath = os.path.dirname(__file__)
22
23
24
        config_file = os.path.join(
            dirpath, "double-sparsity-config-Llama-3.1-8B-Instruct.json"
        )
Shuo Yang's avatar
Shuo Yang committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
        # 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):
49
        kill_process_tree(cls.process.pid)
Shuo Yang's avatar
Shuo Yang committed
50
51
52
53
54
55
56
57
58
59
60

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


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