Repository navigation
Conversation
Fan `n > 1` chat and text completion requests out into one child engine
request per choice, mirroring Python's `ParentRequest`: child request IDs
use the `{index}_{parent}` scheme and seeds are offset by the choice index.
Streaming responses interleave indexed choice chunks and emit a single
merged usage chunk; non-streaming responses collect every choice. Usage
counts the shared prompt once and sums completion and reasoning tokens.
Adapted from vllm-project#43780.
Co-authored-by: xunzhuo <xunzhuo@vllm-semantic-router.ai>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: errmakov <ide404@gmail.com>
Contributor
|
This pull request has merge conflicts that must be resolved before it can be |
6 tasks done
6 tasks done
6 tasks done
6 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
Adds OpenAI
n > 1support to the Rust frontend's/v1/chat/completionsand/v1/completions, which today reject it withOnly n=1 is supported.This picks up #43780 by @Xunzhuo. A maintainer reviewed that PR ("The overall implementation LGTM"), but it then went stale with merge conflicts. Since then the routes have been reworked on
main(response envelopes,ResponseOptions, continuous usage stats, cached/reasoning token details, SSE keep-alive), so this is a re-implementation of the same design on currentmain, not a rebase. @Xunzhuo is credited as co-author.Like Python's
ParentRequest(vllm/v1/engine/parallel_sampling.py):{index}_{parent}scheme whenn > 1. The parent ID is kept unchanged forn = 1, so single-choice requests behave exactly as before.cached_tokens, and sums completion and reasoning tokens across choices.Response shape:
indexset and are interleaved (select_all). Each choice's final usage-only chunk is held back and merged, so clients get one usage chunk after all choices finish, followed by one[DONE].continuous_usage_statsstays per choice, as in Python.kv_transfer_paramscome from the first choice.Validation:
/v1/completionsnow boundsnto1..=10, the same range/v1/chat/completionsalready enforces, so one HTTP request cannot fan out without limit.Not duplicating existing work: searched open and closed PRs for "rust n choices", "Rust Frontend n", "rust parallel sampling" and "Only n=1". The only PR for this change is #43780 itself. #52844 / #52399 are about
/inference/v1/generate, which keeps rejectingn > 1.AI assistance (Claude) was used to write this change. I reviewed every changed line and ran the tests below.
Test Plan
New route tests in
rust/src/server/src/routes/tests.rs, using a mock engine that expects one request per choice:non_stream_{chat_completions,completions}_support_n_greater_than_one: checks the child request IDs (0_…,1_…), the seed offsets (41 → 41/42), the indexed choices, and the merged usage.stream_{chat_completions,completions}_support_n_greater_than_one: checks per-index content, a single merged usage chunk as the last payload, and a single[DONE]. The chat variant also enablescontinuous_usage_statsand checks that per-choice usage survives the merge.completions_reject_n_outside_supported_range:n=0andn=11return 400.Plus unit tests for the helpers in
routes/openai/utils/parallel_sampling.rs.Test Result
cargo test -p vllm-server: 435 passed, 0 failed.main's route code and pass with this change.cargo clippy -p vllm-server --all-targets -- -D warnings: clean.cargo fmt --check: clean.No model eval was run. The change only affects the Rust frontend's request fan-out and response assembly, and for
n = 1the request it sends and the response it returns are unchanged.Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.