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,
|
2025-03-26 07:53:12 +08:00
|
|
|
CustomTestCase,
|
2024-09-14 15:38:37 -07:00
|
|
|
is_in_ci,
|
2024-08-12 03:39:01 -07:00
|
|
|
popen_launch_server,
|
2025-04-28 10:57:17 -07:00
|
|
|
run_bench_offline_throughput,
|
2024-08-12 03:39:01 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2025-03-26 07:53:12 +08:00
|
|
|
class TestTritonAttnBackend(CustomTestCase):
|
2024-09-14 15:38:37 -07:00
|
|
|
def test_latency(self):
|
2025-04-28 10:57:17 -07:00
|
|
|
output_throughput = run_bench_offline_throughput(
|
2024-09-14 15:38:37 -07:00
|
|
|
DEFAULT_MODEL_NAME_FOR_TEST,
|
|
|
|
|
[
|
|
|
|
|
"--attention-backend",
|
|
|
|
|
"triton",
|
|
|
|
|
"--enable-torch-compile",
|
2025-03-04 13:40:40 -08:00
|
|
|
"--cuda-graph-max-bs",
|
2025-03-28 10:34:10 -07:00
|
|
|
4,
|
2024-09-14 15:38:37 -07:00
|
|
|
],
|
2024-08-12 03:39:01 -07:00
|
|
|
)
|
|
|
|
|
|
2025-04-28 10:57:17 -07:00
|
|
|
print(f"{output_throughput=}")
|
|
|
|
|
|
2024-09-14 15:38:37 -07:00
|
|
|
if is_in_ci():
|
2024-12-26 07:56:26 -08:00
|
|
|
self.assertGreater(output_throughput, 153)
|
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()
|