feat: allow streaming for multi-prompt and/or parallel sampling #1134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Official OpenAI API and vLLM supports
stream: true
with parallel sampling (n > 1
), and multi-prompt completions (len(prompt) > 1
). However current version of SGLang does not support this.The goal here is to support requests with
stream: true
AND (n > 1
ORlen(prompt) > 1
).Modification
This PR:
tokenizer_manager._handle_batch_request
function to support streaming response when enabled. This has been implemented by re-usingtokenizer_manager._wait_for_response
, which is currently being used fortokenizer_manager._handle_single_request
.i * batch_index + parallel_sample_index
, which is the same behavior of official OpenAI API and vLLM.tokenizer_manager._wait_for_response
to be able to handle batch request as well.openai.v1_(chat_|)completions
functions to be able to correctly handle batched streaming responses.stream = False
assertion fromtokenizer_manager
, which was asserting all the batch requests, toopenai.process_batch
, which will assert only the/v1/batches
requests.Notes to reviewers
I have tested this on my local environment, and will be rolling out to few of our production GPU nodes soon for further testing.
Checklist
pre-commit run --all-files
or other linting tools are used to fix potential lint issues.