Files
sglang/test/srt/test_chunked_prefill.py

68 lines
2.0 KiB
Python
Raw Normal View History

2024-08-03 23:09:21 -07:00
import unittest
from types import SimpleNamespace
from sglang.srt.utils import kill_child_process
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 TestChunkedPrefill(unittest.TestCase):
def run_mmlu(
self, disable_radix_cache, enable_mixed_chunk, chunked_prefill_size=32
):
other_args = ["--chunked-prefill-size", str(chunked_prefill_size)]
2024-08-12 02:21:38 -07:00
if disable_radix_cache:
other_args += ["--disable-radix-cache"]
2024-08-16 02:13:00 -07:00
if enable_mixed_chunk:
other_args += ["--enable-mixed-chunk"]
2024-08-12 02:21:38 -07:00
model = DEFAULT_MODEL_NAME_FOR_TEST
base_url = DEFAULT_URL_FOR_TEST
2024-08-12 02:21:38 -07:00
process = popen_launch_server(
model,
base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
2024-08-12 02:21:38 -07:00
other_args=other_args,
2024-08-03 23:09:21 -07:00
)
args = SimpleNamespace(
2024-08-12 02:21:38 -07:00
base_url=base_url,
model=model,
2024-08-03 23:09:21 -07:00
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
)
2024-08-12 02:21:38 -07:00
try:
metrics = run_eval(args)
assert metrics["score"] >= 0.65
2024-08-12 02:21:38 -07:00
finally:
kill_child_process(process.pid)
def test_chunked_prefill(self):
2024-08-16 02:13:00 -07:00
self.run_mmlu(disable_radix_cache=False, enable_mixed_chunk=False)
def test_mixed_chunked_prefill(self):
self.run_mmlu(disable_radix_cache=False, enable_mixed_chunk=True)
2024-08-12 02:21:38 -07:00
def test_chunked_prefill_without_radix_cache(self):
2024-08-16 02:13:00 -07:00
self.run_mmlu(disable_radix_cache=True, enable_mixed_chunk=False)
def test_mixed_chunked_prefill_without_radix_cache(self):
self.run_mmlu(disable_radix_cache=True, enable_mixed_chunk=True)
2024-08-03 23:09:21 -07:00
def test_no_chunked_prefill(self):
self.run_mmlu(
disable_radix_cache=False, enable_mixed_chunk=False, chunked_prefill_size=-1
)
2024-08-03 23:09:21 -07:00
if __name__ == "__main__":
2024-08-10 15:09:03 -07:00
unittest.main()