Repository navigation
[Rust Frontend] Support --return-tokens-as-token-ids - #39
Closed
richard-for-bugen[bot] wants to merge 2 commits into
Closed
richard-for-bugen[bot] wants to merge 2 commits into
richard-for-bugen[bot] wants to merge 2 commits into
Conversation
Python's `--return-tokens-as-token-ids` sets the server-wide default for
rendering logprob tokens as `token_id:{id}`; a request's own
`return_tokens_as_token_ids` overrides it, and an omitted or null field
falls back to the flag. Rust rejected the flag at startup.
Declare the flag as a real frontend arg, carry it in `ApiServerOptions`,
and keep the request field as `Option<bool>` in the chat and completions
response options so the response stage resolves it against the flag, as
Python's serving classes do.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: richard-for-bugen[bot] <342439978+richard-for-bugen[bot]@users.noreply.github.com>
BugenZhao
approved these changes
Oct 23, 2026
| pub enable_prompt_tokens_details: bool, | ||
| /// Format logprob tokens as `token_id:{id}` unless the request sets | ||
| /// `return_tokens_as_token_ids` itself. | ||
| pub return_tokens_as_token_ids: bool, |
Owner
There was a problem hiding this comment.
Suggested change
| pub return_tokens_as_token_ids: bool, | |
| pub default_return_tokens_as_token_ids: bool, |
Author
There was a problem hiding this comment.
Applied in 90e74ff: ApiServerOptions.default_return_tokens_as_token_ids. The CLI field keeps the flag name --return-tokens-as-token-ids. Full Rust CI command set green (2296 passed).
…_ids The flag is only the default a request's own return_tokens_as_token_ids overrides; name the ApiServerOptions field after that role. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: richard-for-bugen[bot] <342439978+richard-for-bugen[bot]@users.noreply.github.com>
Author
|
Promoted as vllm-project#63318. |
Author
|
Merged upstream as vllm-project#63318. |
richard-for-bugen
Bot
deleted the
richard/parity-impl-return-tokens-as-token-ids
branch
October 25, 2026 19:18
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.
Motivation
Python's
--return-tokens-as-token-ids(FrontendArgs.return_tokens_as_token_ids) sets the server-wide default for rendering logprob tokens astoken_id:{id}placeholders. The chat and completions serving classes resolve it per request in_create_chat_logprobs/_create_completion_logprobs:So an omitted or
nullrequest field takes the server flag, and an explicittrue/falseoverrides it (a request can opt out withfalseon a server started with the flag). The rule covers output logprobs and completions echo/prompt logprobs.Rust already honors the per-request
return_tokens_as_token_idsfield, but declared the flagUnsupported, so a server started with it failed at startup (both undervllm servewithVLLM_USE_RUST_FRONTEND=1, through--args-json, and undervllm-rs serve).Change
vllm-cmd:--return-tokens-as-token-idsmoves from theUnsupportedmarkers to a realboolonSharedRuntimeArgs(help text kept from Python), carried intoApiServerOptions. Like the other frontend booleans it has no--no-*spelling yet (the inverse-spelling item is parked separately); the inverse sets Python's default anyway.vllm-server:ApiServerOptionsgainsdefault_return_tokens_as_token_ids(renamed in review, 90e74ff). The chat and completionsResponseOptionskeep the request field asOption<bool>instead of collapsing it tofalseduring lowering, and the response stage (the collect and chunk-stream functions of each route, which already receive bothApiServerOptionsandResponseOptions) resolves it once withunwrap_or(<server flag>), as Python's serving classes do.Layering. The consumer is the OpenAI logprob formatting in the route response stage (
routes/openai/utils/logprobs.rscallers); the server-wide default is fixed at construction inApiServerOptions, and DTO lowering stays request-only, soprepare_*_request(also used by the render routes) takes no server config./inference/v1/generateis unaffected: Rust serves onlyoutput_mode="tokens", whose logprobs carry integer token IDs, and Python's flag only changes itstext/derenderlevels. Open vllm-project#63173 (Python only) adds aparse_contextoverride for derender; not applicable here.Validation
server_return_tokens_as_token_ids_is_the_request_default: chat and completions, streaming and non-streaming, against the mock engine, for (server flag, request field) = (on, omitted), (on,null), (on,false), (off, omitted), (off,true); expectstoken_id:104exactly when Python would. Red-green: ignoring the server flag fails it (/v1/chat/completions stream=false server_flag=true request={}); ignoring it only in the completions stream fails/v1/completions stream=true.serve_passes_return_tokens_as_token_ids_into_config;SharedRuntimeArgs/FrontendConfigsnapshots refreshed.cargo sort,cargo deny bans, clippy-D warnings,cargo nextest run --workspace --all-features): all green, 2296 passed, 13 skipped.tests/entrypoints/openai/test_return_tokens_as_ids.pyunderVLLM_USE_RUST_FRONTEND=1withvllm-rsbuilt from this branch:--lora-modules, which fails at startup on currentmain(add_lora ... Expected bool, got null); that is the LoRA wire-layout fix in [Rust Frontend] Drop tensorizer_config_dict from the LoRA request wire layout #29, not this change. With that commit applied on top for the run only:test_chat_return_tokens_as_token_ids_completion[True](server flag, request field omitted) and[False](request field) pass.test_completion_return_tokens_as_token_ids_completion[True]and[False]both fail identically ontoken_strs[1:] == top_logprob_keys: Rust builds each completionstop_logprobsentry as aHashMap, so the sampled token is not reliably the first key. That is the separatecompletions.top_logprobs_key_ordergap, present with or without the flag; the token strings themselves aretoken_id:Nin both variants.tests/entrypoints/openai/test_return_tokens_as_ids.pyjoins Rust CI through the parity e2e run PR once this, #29, and the completionstop_logprobskey-order fix have merged (the chat tests need only this and #29).Dedup
No open upstream PR implements the flag in Rust (searched
return_tokens_as_token_ids,return-tokens-as-token-ids). Active vllm-project#62684 editsroutes/openai/completions.rsforechowithreturn_token_ids, a different field; the hunks here touch only the option destructuring in that file.Codex review
Verdict: approve with nits; no blocking findings (problem real, precedence matches Python's
_create_*_logprobs, resolution placed at each response path that formats logprobs; Codex re-ran both new tests red on the base implementation).top_logprobs: 2, completionslogprobs: 1) and expects bothh/Hor both placeholders. Echoed prompt tokens were not added: the flag is resolved once per response function before any formatter runs, and the echo/prompt-only formatters already take that same resolved value.🤖 Generated with Claude Code
https://claude.ai/code/session_012jJ3QaARmRe3jZJYTfHsCB