Skip to content

fix(scale-out): return all n choices from /inference/v1/generate - #52507

Closed
hclsys wants to merge 1 commit into
vllm-project:mainfrom
hclsys:fix/scaleout-generate-n-drops-choices
Closed

hclsys wants to merge 1 commit into
vllm-project:mainfrom
hclsys:fix/scaleout-generate-n-drops-choices

Conversation

@hclsys

@hclsys hclsys commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Non-streaming /inference/v1/generate with n > 1 returns fewer than n choices, no error. serve_tokens only sets output_kind for the streaming case, so non-streaming keeps the SamplingParams default (CUMULATIVE); serve_tokens_full_generator then keeps only the last streamed RequestOutput, and under CUMULATIVE each sequence is pruned from the stream once it finishes, so sequences that finished before the final step never make it into choices. The OpenAI completion path already uses FINAL_ONLY when not streaming — this does the same.

Root cause + repro are @qgallouedec's in #52398; I offered there to put up the fix. Happy to hand it back if you'd rather carry it yourself.

Added an n=2/4 regression test to test_serving_tokens.py (the existing scale-out tests are all n=1).

Fixes #52398

serve_tokens set output_kind only for streaming, so non-streaming requests
kept the SamplingParams default (CUMULATIVE). serve_tokens_full_generator
keeps only the last streamed RequestOutput, and under CUMULATIVE each
sequence is pruned from the stream once it finishes, so with n > 1 the
sequences that finished before the final step never reach `choices` and the
response silently returns fewer than n completions. The OpenAI completion
path already uses FINAL_ONLY when not streaming; do the same here.

Root cause and repro from @qgallouedec in vllm-project#52398.

Fixes vllm-project#52398

Signed-off-by: Chenglun Hu <chenglunhu@gmail.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 954d971f8c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

payload = {
"model": MODEL_NAME,
"token_ids": [9707, 1879, 11],
"sampling_params": {"max_tokens": 5, "temperature": 1.0, "n": n},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Force choices to finish on different decoding steps

With max_tokens=5, all choices normally hit the length limit in the same engine iteration; the RequestOutputCollector then merges those same-step cumulative outputs, so the pre-fix implementation can still return all n choices and pass this test. An unseeded, temperature-1 sample only exposes the regression if a choice happens to emit EOS early, making coverage probabilistic and potentially flaky. Use a deterministic setup or mocked generator that finishes choices on different steps so reverting the production fix reliably fails.

AGENTS.md reference: AGENTS.md:L82-L93

Useful? React with 👍 / 👎.

@DarkLight1337

Copy link
Copy Markdown
Member

There is already an open PR to fix the issue: #52399

@hclsys

hclsys commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

closing — #52399 already covers this (didn't surface in my search, my bad for the dup). thanks @DarkLight1337.

@hclsys hclsys closed this Aug 16, 2026
@hclsys
hclsys deleted the fix/scaleout-generate-n-drops-choices branch August 16, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /inference/v1/generate silently drops choices when n > 1

2 participants