2024-11-17 19:49:20 -08:00
|
|
|
"""
|
|
|
|
|
Usage:
|
|
|
|
|
python3 -m unittest test_triton_attention_backend.TestTritonAttnBackend.test_mmlu
|
|
|
|
|
"""
|
|
|
|
|
|
2024-08-12 03:39:01 -07:00
|
|
|
import unittest
|
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
|
2024-11-28 00:22:39 -08:00
|
|
|
from sglang.srt.utils import kill_process_tree
|
2024-08-12 03:39:01 -07:00
|
|
|
from sglang.test.run_eval import run_eval
|
|
|
|
|
from sglang.test.test_utils import (
|
|
|
|
|
DEFAULT_MODEL_NAME_FOR_TEST,
|
2024-08-25 19:02:08 -07:00
|
|
|
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
|
|
|
|
DEFAULT_URL_FOR_TEST,
|
2024-09-14 15:38:37 -07:00
|
|
|
is_in_ci,
|
2024-08-12 03:39:01 -07:00
|
|
|
popen_launch_server,
|
2024-11-21 20:07:48 -08:00
|
|
|
run_bench_one_batch,
|
2024-08-12 03:39:01 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestTritonAttnBackend(unittest.TestCase):
|
2024-09-14 15:38:37 -07:00
|
|
|
def test_latency(self):
|
2024-11-21 20:07:48 -08:00
|
|
|
output_throughput = run_bench_one_batch(
|
2024-09-14 15:38:37 -07:00
|
|
|
DEFAULT_MODEL_NAME_FOR_TEST,
|
|
|
|
|
[
|
|
|
|
|
"--attention-backend",
|
|
|
|
|
"triton",
|
|
|
|
|
"--enable-torch-compile",
|
|
|
|
|
],
|
2024-08-12 03:39:01 -07:00
|
|
|
)
|
|
|
|
|
|
2024-09-14 15:38:37 -07:00
|
|
|
if is_in_ci():
|
2024-10-06 00:10:48 -07:00
|
|
|
assert output_throughput > 153, f"{output_throughput=}"
|
2024-08-12 03:39:01 -07:00
|
|
|
|
|
|
|
|
def test_mmlu(self):
|
2024-09-14 15:38:37 -07:00
|
|
|
model = DEFAULT_MODEL_NAME_FOR_TEST
|
|
|
|
|
base_url = DEFAULT_URL_FOR_TEST
|
|
|
|
|
process = popen_launch_server(
|
|
|
|
|
model,
|
|
|
|
|
base_url,
|
|
|
|
|
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
|
|
|
|
other_args=["--attention-backend", "triton"],
|
2024-08-12 03:39:01 -07:00
|
|
|
)
|
|
|
|
|
|
2024-09-14 15:38:37 -07:00
|
|
|
try:
|
|
|
|
|
args = SimpleNamespace(
|
|
|
|
|
base_url=base_url,
|
|
|
|
|
model=model,
|
|
|
|
|
eval_name="mmlu",
|
|
|
|
|
num_examples=64,
|
|
|
|
|
num_threads=32,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
metrics = run_eval(args)
|
2024-11-14 01:30:24 -08:00
|
|
|
self.assertGreaterEqual(metrics["score"], 0.65)
|
2024-09-14 15:38:37 -07:00
|
|
|
finally:
|
2024-11-28 00:22:39 -08:00
|
|
|
kill_process_tree(process.pid)
|
2024-08-12 03:39:01 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|