Provide an offline engine API (#1567)

This commit is contained in:
Byron Hsu
2024-10-06 20:27:03 -07:00
committed by GitHub
parent 91877a9f9c
commit 551a3a9d38
6 changed files with 148 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ suites = {
"test_pytorch_sampling_backend.py",
"test_server_args.py",
"test_skip_tokenizer_init.py",
"test_srt_engine.py",
"test_srt_endpoint.py",
"test_torch_compile.py",
"test_torchao.py",

View File

@@ -0,0 +1,33 @@
import json
import unittest
import sglang as sgl
from sglang.test.test_utils import DEFAULT_MODEL_NAME_FOR_TEST
class TestSRTBackend(unittest.TestCase):
def test_engine_runtime_consistency(self):
prompt = "Today is a sunny day and I like"
model_path = DEFAULT_MODEL_NAME_FOR_TEST
sampling_params = {"temperature": 0, "max_new_tokens": 8}
engine = sgl.Engine(model_path=model_path, random_seed=42)
out1 = engine.generate(prompt, sampling_params)["text"]
engine.shutdown()
runtime = sgl.Runtime(model_path=model_path, random_seed=42)
out2 = json.loads(runtime.generate(prompt, sampling_params))["text"]
runtime.shutdown()
print("==== Answer 1 ====")
print(out1)
print("==== Answer 2 ====")
print(out2)
assert out1 == out2, f"{out1} != {out2}"
if __name__ == "__main__":
unittest.main()