test_srt_backend.py 1.84 KB
Newer Older
1
2
3
"""
Usage:
python3 -m unittest test_srt_backend.TestSRTBackend.test_gen_min_new_tokens
4
python3 -m unittest test_srt_backend.TestSRTBackend.test_hellaswag_select
5
6
"""

Lianmin Zheng's avatar
Lianmin Zheng committed
7
8
import unittest

Liangsheng Yin's avatar
Liangsheng Yin committed
9
import sglang as sgl
Lianmin Zheng's avatar
Lianmin Zheng committed
10
11
from sglang.test.test_programs import (
    test_decode_int,
12
    test_decode_json_regex,
13
    test_dtype_gen,
Lianmin Zheng's avatar
Lianmin Zheng committed
14
15
    test_expert_answer,
    test_few_shot_qa,
16
    test_gen_min_new_tokens,
17
    test_hellaswag_select,
Lianmin Zheng's avatar
Lianmin Zheng committed
18
19
20
21
22
23
24
    test_mt_bench,
    test_parallel_decoding,
    test_regex,
    test_select,
    test_stream,
    test_tool_use,
)
Ying Sheng's avatar
Ying Sheng committed
25
from sglang.test.test_utils import DEFAULT_MODEL_NAME_FOR_TEST
Lianmin Zheng's avatar
Lianmin Zheng committed
26
27
28
29
30


class TestSRTBackend(unittest.TestCase):
    backend = None

31
32
    @classmethod
    def setUpClass(cls):
Ying Sheng's avatar
Ying Sheng committed
33
        cls.backend = sgl.Runtime(model_path=DEFAULT_MODEL_NAME_FOR_TEST)
34
        sgl.set_default_backend(cls.backend)
Lianmin Zheng's avatar
Lianmin Zheng committed
35

36
37
38
    @classmethod
    def tearDownClass(cls):
        cls.backend.shutdown()
Lianmin Zheng's avatar
Lianmin Zheng committed
39
40
41
42
43
44
45
46
47
48
49
50
51

    def test_few_shot_qa(self):
        test_few_shot_qa()

    def test_mt_bench(self):
        test_mt_bench()

    def test_select(self):
        test_select(check_answer=False)

    def test_decode_int(self):
        test_decode_int()

52
53
54
    def test_decode_json_regex(self):
        test_decode_json_regex()

Lianmin Zheng's avatar
Lianmin Zheng committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    def test_expert_answer(self):
        test_expert_answer()

    def test_tool_use(self):
        test_tool_use()

    def test_parallel_decoding(self):
        test_parallel_decoding()

    def test_stream(self):
        test_stream()

    def test_regex(self):
        test_regex()

70
71
72
    def test_dtype_gen(self):
        test_dtype_gen()

73
74
75
76
    def test_hellaswag_select(self):
        # Run twice to capture more bugs
        for _ in range(2):
            accuracy, latency = test_hellaswag_select()
Lianmin Zheng's avatar
Lianmin Zheng committed
77
            self.assertGreater(accuracy, 0.69)
78

79
80
81
    def test_gen_min_new_tokens(self):
        test_gen_min_new_tokens()

Lianmin Zheng's avatar
Lianmin Zheng committed
82
83

if __name__ == "__main__":
Lianmin Zheng's avatar
Lianmin Zheng committed
84
    unittest.main()