Files
sglang/test/srt/test_torch_compile.py

75 lines
1.9 KiB
Python
Raw Normal View History

2024-11-19 22:07:58 -08:00
import time
2024-08-03 23:09:21 -07:00
import unittest
from types import SimpleNamespace
import requests
from sglang.srt.utils import kill_process_tree
2024-08-03 23:09:21 -07:00
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,
)
2024-08-03 23:09:21 -07:00
2024-08-12 02:21:38 -07:00
class TestTorchCompile(unittest.TestCase):
2024-08-03 23:09:21 -07:00
@classmethod
def setUpClass(cls):
2024-08-04 20:51:55 -07:00
cls.model = DEFAULT_MODEL_NAME_FOR_TEST
cls.base_url = DEFAULT_URL_FOR_TEST
2024-08-03 23:09:21 -07:00
cls.process = popen_launch_server(
cls.model,
cls.base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
other_args=["--enable-torch-compile"],
2024-08-03 23:09:21 -07:00
)
@classmethod
def tearDownClass(cls):
kill_process_tree(cls.process.pid)
2024-08-03 23:09:21 -07:00
def test_mmlu(self):
args = SimpleNamespace(
base_url=self.base_url,
model=self.model,
eval_name="mmlu",
num_examples=64,
2024-08-12 02:21:38 -07:00
num_threads=32,
2024-08-03 23:09:21 -07:00
)
metrics = run_eval(args)
2024-11-14 01:30:24 -08:00
self.assertGreaterEqual(metrics["score"], 0.65)
2024-08-03 23:09:21 -07:00
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,
2024-11-14 01:30:24 -08:00
"ignore_eos": True,
},
},
)
return response.json()
def test_throughput(self):
2024-11-19 22:07:58 -08:00
# Warmup
res = self.run_decode(16)
max_tokens = 256
tic = time.time()
res = self.run_decode(max_tokens)
tok = time.time()
2024-11-19 22:07:58 -08:00
print(f"{res=}")
throughput = max_tokens / (tok - tic)
print(f"Throughput: {throughput} tokens/s")
self.assertGreaterEqual(throughput, 152)
2024-08-03 23:09:21 -07:00
if __name__ == "__main__":
2024-08-10 15:09:03 -07:00
unittest.main()