Add warmup to SRT server (#146)
This commit is contained in:
@@ -389,7 +389,7 @@ def launch_server(server_args, pipe_finish_writer):
|
|||||||
|
|
||||||
assert proc_router.is_alive() and proc_detoken.is_alive()
|
assert proc_router.is_alive() and proc_detoken.is_alive()
|
||||||
|
|
||||||
def launch_server():
|
def _launch_server():
|
||||||
# Launch api server
|
# Launch api server
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
app,
|
app,
|
||||||
@@ -400,26 +400,48 @@ def launch_server(server_args, pipe_finish_writer):
|
|||||||
loop="uvloop",
|
loop="uvloop",
|
||||||
)
|
)
|
||||||
|
|
||||||
t = threading.Thread(target=launch_server)
|
t = threading.Thread(target=_launch_server)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
if pipe_finish_writer:
|
|
||||||
url = server_args.url()
|
url = server_args.url()
|
||||||
|
for _ in range(60):
|
||||||
success = False
|
|
||||||
for i in range(60):
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
try:
|
try:
|
||||||
res = requests.get(url + "/get_model_info", timeout=5)
|
requests.get(url + "/get_model_info", timeout=5)
|
||||||
success = True
|
|
||||||
break
|
break
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if success:
|
|
||||||
pipe_finish_writer.send("init ok")
|
|
||||||
else:
|
else:
|
||||||
|
if pipe_finish_writer is not None:
|
||||||
pipe_finish_writer.send(str(e))
|
pipe_finish_writer.send(str(e))
|
||||||
|
else:
|
||||||
|
print(e, flush=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Warmup
|
||||||
|
try:
|
||||||
|
print("Warmup...", flush=True)
|
||||||
|
res = requests.post(
|
||||||
|
url + "/generate",
|
||||||
|
json={
|
||||||
|
"text": "Say this is a warmup request.",
|
||||||
|
"sampling_params": {
|
||||||
|
"temperature": 0,
|
||||||
|
"max_new_tokens": 16,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
timeout=60,
|
||||||
|
)
|
||||||
|
print(f"Warmup done. model response: {res.json()['text']}")
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
if pipe_finish_writer is not None:
|
||||||
|
pipe_finish_writer.send(str(e))
|
||||||
|
else:
|
||||||
|
print(e, flush=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
if pipe_finish_writer is not None:
|
||||||
|
pipe_finish_writer.send("init ok")
|
||||||
|
|
||||||
|
|
||||||
class Runtime:
|
class Runtime:
|
||||||
|
|||||||
Reference in New Issue
Block a user