".github/vscode:/vscode.git/clone" did not exist on "4748281bcc40843dca083fdd00621ec00662afd7"
test_torch_compile.py 2.1 KB
Newer Older
1
import time
2
3
4
import unittest
from types import SimpleNamespace

5
6
import requests

7
from sglang.srt.utils import kill_process_tree
8
from sglang.test.run_eval import run_eval
9
10
from sglang.test.test_utils import (
    DEFAULT_MODEL_NAME_FOR_TEST,
11
12
    DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
    DEFAULT_URL_FOR_TEST,
13
    CustomTestCase,
14
    is_in_amd_ci,
15
16
    popen_launch_server,
)
17
18


19
class TestTorchCompile(CustomTestCase):
20
21
    @classmethod
    def setUpClass(cls):
Ying Sheng's avatar
Ying Sheng committed
22
        cls.model = DEFAULT_MODEL_NAME_FOR_TEST
23
        cls.base_url = DEFAULT_URL_FOR_TEST
24
        cls.process = popen_launch_server(
25
26
27
            cls.model,
            cls.base_url,
            timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
28
            other_args=["--enable-torch-compile", "--cuda-graph-max-bs", "4"],
29
30
31
32
        )

    @classmethod
    def tearDownClass(cls):
33
        kill_process_tree(cls.process.pid)
34
35
36
37
38
39

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

        metrics = run_eval(args)
45
        self.assertGreaterEqual(metrics["score"], 0.65)
46

47
48
49
50
51
52
53
54
    def run_decode(self, max_new_tokens):
        response = requests.post(
            self.base_url + "/generate",
            json={
                "text": "The capital of France is",
                "sampling_params": {
                    "temperature": 0,
                    "max_new_tokens": max_new_tokens,
55
                    "ignore_eos": True,
56
57
58
59
60
61
                },
            },
        )
        return response.json()

    def test_throughput(self):
62
63
        # Warmup
        res = self.run_decode(16)
64
65

        max_tokens = 256
66
        tic = time.perf_counter()
67
        res = self.run_decode(max_tokens)
68
        tok = time.perf_counter()
69
        print(f"{res=}")
70
71
        throughput = max_tokens / (tok - tic)
        print(f"Throughput: {throughput} tokens/s")
72
73
74
75
76

        if is_in_amd_ci():
            self.assertGreaterEqual(throughput, 145)
        else:
            self.assertGreaterEqual(throughput, 152)
77

78
79

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