Repository navigation
[Bugfix] Clamp client-supplied remote_prefill_cached_tokens to the prompt length - #63659
Open
LeizhenZhang wants to merge 1 commit into
Open
LeizhenZhang wants to merge 1 commit into
LeizhenZhang wants to merge 1 commit into
Conversation
…ompt length kv_transfer_params is a request field on the OpenAI-compatible endpoints, so any client can set do_remote_prefill and remote_prefill_cached_tokens. OutputProcessor copied that value into num_cached_tokens unchecked, which let a request report cached_tokens larger than the prompt or negative in usage.prompt_tokens_details and pushed negative observations into vllm:request_prefill_kv_computed_tokens. Keep the override within [0, prompt_len], the same bounds the local count already has in PrefillStats. Fixes vllm-project#58728 Signed-off-by: LeizhenZhang <zhangleizhen645@gmail.com>
ptimizeroracle
left a comment
There was a problem hiding this comment.
same change as #58730, thanks for picking it up and for the end-to-end table. lgtm
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.
Overview
Clamp the client-supplied
kv_transfer_params.remote_prefill_cached_tokensoverride to[0, prompt_len]before it becomesnum_cached_tokens. Fixes #58728.This is the clamp @ptimizeroracle proposed in #58730, which robertgshaw2-redhat acked on the issue. That PR was closed by its author on 2026-10-23 for lack of review. I reproduced the bug independently on current main and am resubmitting the same approach with an end-to-end reproduction. Credit for the fix goes to @ptimizeroracle.
Claims
usage.prompt_tokens_details.cached_tokensto an arbitrary or negative value throughkv_transfer_params.vllm:request_prefill_kv_computed_tokensno longer goes negative for such requests.Validation
Reproducer on CPU through the real request path: JSON body,
CompletionRequest.to_sampling_params,OutputProcessor,IterationStats. The prompt has 17 tokens and no local cache hits.New test, on the base commit and with the fix:
ruff check,ruff format --check(0.14.0, the pre-commit pin) andtools/pre_commit/mypy.py 3.11 vllm/v1/engine/output_processor.pypass. The test runs in theengine.yamlstep (pytest -v -s v1/engine).I could not run a
RemoteOpenAIServertest here, because this machine's driver cannot run current main's CUDA 13 kernels. The reproducer above covers the same path below the engine core.Details
kv_transfer_paramsis an ordinary request field on the completions, chat, responses and messages endpoints, andto_sampling_paramsforwards it with or without a KV connector.OutputProcessorcopiedremote_prefill_cached_tokensintonum_cached_tokenswith no bounds check. The clamp matches the bounds of the local count inPrefillStats. The Rust frontend change in #58885 reads the same field and may want the same bound.Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.
Need help on this PR? Tag
@codesmith-botwith what you need.Need help on this PR? Tag
@codesmith-botwith what you need.