Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug-fix: when using stream is False, continuous batching doesn't work #346

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lmdeploy/serve/openai/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async def generate(request: GenerateRequest, raw_request: Request = None):
generation = VariableInterface.async_engine.generate(
request.prompt,
request.instance_id,
stream_response=request.stream,
stream_response=True, # always use stream to enable batching
sequence_start=request.sequence_start,
sequence_end=request.sequence_end,
request_output_len=request.request_output_len,
Expand All @@ -303,12 +303,14 @@ async def stream_results() -> AsyncGenerator[bytes, None]:
return StreamingResponse(stream_results())
else:
ret = {}
text = ''
tokens = 0
finish_reason = None
async for out in generation:
ret = {
'text': out.response,
'tokens': out.generate_token_len,
'finish_reason': out.finish_reason
}
text += out.response
tokens += out.generate_token_len
finish_reason = out.finish_reason
ret = {'text': text, 'tokens': tokens, 'finish_reason': finish_reason}
return JSONResponse(ret)


Expand Down