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
|
2024-08-11 18:27:33 -07:00
|
|
|
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-08-11 18:27:33 -07:00
|
|
|
popen_launch_server,
|
|
|
|
|
)
|
2024-08-03 23:09:21 -07:00
|
|
|
|
|
|
|
|
|
2024-08-12 02:21:38 -07:00
|
|
|
class TestChunkedPrefill(unittest.TestCase):
|
2024-09-18 03:45:19 -07:00
|
|
|
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
|
2024-08-25 19:02:08 -07:00
|
|
|
base_url = DEFAULT_URL_FOR_TEST
|
2024-08-12 02:21:38 -07:00
|
|
|
process = popen_launch_server(
|
|
|
|
|
model,
|
|
|
|
|
base_url,
|
2024-08-25 19:02:08 -07:00
|
|
|
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",
|
2024-09-15 06:36:06 -07:00
|
|
|
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)
|
2024-09-15 06:36:06 -07:00
|
|
|
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
|
|
|
|
2024-09-18 03:45:19 -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()
|