Repository navigation
[Rust Frontend] Truncate prompts against max_model_len like Python - #11
Closed
richard-for-bugen[bot] wants to merge 1 commit into
Closed
richard-for-bugen[bot] wants to merge 1 commit into
richard-for-bugen[bot] wants to merge 1 commit into
Conversation
`truncate_prompt_tokens=-1` now keeps `max_model_len - 1` prompt tokens and an explicit value is checked against `max_model_len`, matching Python's `TokenizeParams` (vllm-project#57035, vllm-project#62010). `max_tokens` is an upper bound clamped after tokenization, not a reservation. Previously `-1` without `max_tokens` truncated to the full context and then failed the request as too long. 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 20, 2026
Author
|
Promoted upstream as vllm-project#62642 (replayed onto current main, no conflicts; same change). Leaving this open until it merges. |
Owner
|
Merged upstream as vllm-project#62642 (97a82d3). |
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
truncate_prompt_tokensbudgets against the context length only.-1truncates the prompt tomax_model_len - 1(TokenizeParams.max_truncation_tokens,vllm/renderers/params.py), holding one token back for generation, and an explicit value is rejected only abovemax_model_len.max_tokensis an upper bound thatget_max_tokens()clamps after tokenization, not a reservation ([Bugfix] Treat max_tokens as output upper bound, not input-space reservation vllm-project/vllm#57035). [Bugfix][Frontend] Fix auto truncation without an output token limit vllm-project/vllm#62010 fixed the last gap, a request without an output limit: it used to truncate to the full context and then fail with no room to generate.TextRequestProcessorbudgetsmax_model_len - max_tokens(max_model_lenwhenmax_tokensis absent):truncate_prompt_tokens=-1withoutmax_tokenstruncates to the full context, thenresolve_max_tokensrejects the request as too long. Auto-truncation never helps such a request.max_tokens, it dropsmax_tokensprompt tokens that Python keeps, so the same request sees a different prompt.max_model_len - max_tokensis rejected, while Python accepts it.-1keepsmax_model_len - 1tokens, and an explicit value is checked againstmax_model_len, with Python's message. Generation then gets the remaining context through the existingresolve_max_tokensclamp.Example with
max_model_len=10, a 15-token prompt, andtruncate_prompt_tokens=-1:max_tokensmax_tokens=1max_tokens=5max_tokens=1Ownership and layering
Truncation is owned by
vllm-text(PromptTruncation::apply, called fromTextRequestProcessor::prepare_prompt_tokens). Chat, completions, and gRPC all reach it, so the fix there covers every entry point that acceptstruncate_prompt_tokens. Only generation paths set a truncation policy (/tokenizeand/inference/v1/generatenever do), so the one held-back token always applies. That matches Python, where only no-output requests such as pooling keep the full context.prepare_prompt_tokensno longer needsmax_tokens, and the error variant is renamed toTruncatePromptTokensExceedsMaxModelLento match what it now checks.Validation
Commands from
.buildkite/scripts/run-rust-frontend-cargo-ci.sh(style-clippyandtest), run from the worktree root:Tests:
auto_truncation_leaves_one_output_token(vllm-text): the table above throughTextRequestProcessor::prepare. Fails before the fix: setting-1back to the full context makes themax_tokens-absent case panic on the prompt-too-long error.input_budget_holds_back_one_token_for_outputandfixed_limit_cannot_exceed_max_model_lenreplace the unit tests that pinned the old budget.Python parity item
chat+completions.truncate_prompt_tokens_budget(category 4), queued at the 2026-10-14 baseline and refreshed by vllm-project#62010.🤖 Generated with Claude Code