[Engine] Fix generate hanging issue after the first call (#1606)
This commit is contained in:
@@ -691,8 +691,9 @@ class Engine:
|
||||
lora_path=lora_path,
|
||||
)
|
||||
|
||||
# make it synchronous
|
||||
return asyncio.run(generate_request(obj, None))
|
||||
# get the current event loop
|
||||
loop = asyncio.get_event_loop()
|
||||
return loop.run_until_complete(generate_request(obj, None))
|
||||
|
||||
def shutdown(self):
|
||||
kill_child_process(os.getpid(), including_parent=False)
|
||||
|
||||
@@ -28,6 +28,18 @@ class TestSRTBackend(unittest.TestCase):
|
||||
print(out2)
|
||||
assert out1 == out2, f"{out1} != {out2}"
|
||||
|
||||
def test_engine_multiple_generate(self):
|
||||
# just to ensure there is no issue running multiple generate calls
|
||||
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)
|
||||
engine.generate(prompt, sampling_params)
|
||||
engine.generate(prompt, sampling_params)
|
||||
engine.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user