test_radix_attention.py 2.39 KB
Newer Older
1
2
import unittest

3
4
from sglang.srt.environ import envs
from sglang.test.kits.radix_cache_server_kit import run_radix_attention_test
5
from sglang.test.test_utils import (
Lianmin Zheng's avatar
Lianmin Zheng committed
6
    DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
7
8
    DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
    DEFAULT_URL_FOR_TEST,
9
    CustomTestCase,
10
    is_in_ci,
11
    kill_process_tree,
12
13
14
15
    popen_launch_server,
)


16
class TestRadixCacheFCFS(CustomTestCase):
17
18
    @classmethod
    def setUpClass(cls):
Lianmin Zheng's avatar
Lianmin Zheng committed
19
        cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
        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=[
                "--chunked-prefill-size",
                "128",
                "--max-total-tokens",
                "20000",
                "--schedule-policy",
                "fcfs",
            ],
        )

    @classmethod
    def tearDownClass(cls):
37
        kill_process_tree(cls.process.pid)
38
39

    def test_radix_attention(self):
40
        run_radix_attention_test(self.base_url)
41
42


43
@unittest.skipIf(is_in_ci(), "To reduce the CI execution time.")
44
45
46
class TestRadixCacheLPM(TestRadixCacheFCFS):
    @classmethod
    def setUpClass(cls):
Lianmin Zheng's avatar
Lianmin Zheng committed
47
        cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        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=[
                "--chunked-prefill-size",
                "128",
                "--max-total-tokens",
                "20000",
                "--schedule-policy",
                "lpm",
            ],
        )


64
class TestRadixCacheNonOverlapLPM(TestRadixCacheFCFS):
65
66
    @classmethod
    def setUpClass(cls):
Lianmin Zheng's avatar
Lianmin Zheng committed
67
        cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
68
69
70
71
72
73
        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=[
74
                "--disable-overlap-schedule",
75
76
77
78
79
80
81
82
83
84
                "--chunked-prefill-size",
                "128",
                "--max-total-tokens",
                "20000",
                "--schedule-policy",
                "lpm",
            ],
        )


85
if __name__ == "__main__":
86
    envs.SGLANG_TEST_RETRACT.set(True)
87
    unittest.main()