Repository navigation
[None][fix] Latch cached_tokens from the prefix reuse decision, not the decode position - #19743
Conversation
…he decode position LlmRequest.cached_tokens is set once per request and reports the prompt prefix served from the KV cache. The generation branch of _prepare_tp_inputs also wrote it, from the decode position (max_beam_num_tokens - 1). That write is a no-op for a request whose context phase ran on this worker, because the context branch already latched the real prefix. For a disaggregated generation-only request the context phase ran elsewhere, so the decode write was the first one and latched the whole prompt as a cache hit. Every consumer of the field then saw it: the five response sites, the ADP router's active-token load, the Prometheus prompt_cache_cached_tokens metric, the gRPC servicers and RequestOutput.cached_tokens. Only a promoted one-token context chunk may latch on the decode path; that is its context-phase forward. Generation-only requests latch in _prepare_disagg_gen_resources from prepopulated_prompt_len, the prefix this worker matched in its own cache and will not receive, at the point the allocation decided it. Signed-off-by: Iman Tabrizian <[email protected]>
|
/bot run --disable-fail-fast |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: NVIDIA/TensorRT-LLM/.coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review. WalkthroughThe executor copies prepopulated prompt lengths to ChangesCached-token accounting
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The reviewed paths preserve cached-token accounting for generation-only and promoted requests, so no actionable merge risk remains; proceed with normal validation. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
PR_Github #75885 [ run ] triggered by Bot. Commit: |
…n-only request factory Move the promoted-context latch to the categorization loop where is_promoted_context is decided, so neither decode branch carries a cached_tokens write. Lift the real-LlmRequest factory from the KV-connector gen-only test into llm_request_factory.py and use it from both tests; drop the test that exercised no changed code and trim the comments that restated each other. Signed-off-by: Iman Tabrizian <[email protected]>
|
/bot run --disable-fail-fast |
|
PR_Github #75909 [ run ] triggered by Bot. Commit: |
|
PR_Github #75885 [ run ] completed with state |
|
PR_Github #75909 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #75942 [ run ] triggered by Bot. Commit: |
|
PR_Github #75942 [ run ] completed with state
|
…t_len _prepare_disagg_gen_resources now latches cached_tokens from prepopulated_prompt_len. test_disagg_receive_ordering.py drives the real method with SimpleNamespace requests, which lacked the attribute every real request carries, so ten parametrizations failed with AttributeError on the H100, B300 and SBSA CPU stages. Signed-off-by: Iman Tabrizian <[email protected]>
|
/bot run --disable-fail-fast |
|
PR_Github #75974 [ run ] triggered by Bot. Commit: |
|
Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Semantic conflict reviewThe verdict of record is the Latest recorded state: No semantic conflict found (best effort) for head Best-effort AI judgment for the recorded revisions. PASS, FAIL and INCONCLUSIVE may be incomplete or incorrect. PR authors and reviewers should independently verify the evidence and relevant behavior. This semantic review and its status/workflow are advisory, not required merge checks under current repository rules; other merge requirements still apply. Advisory status does not make a confirmed defect safe to ignore.
Processed request and reply comments are minimized to reduce timeline noise; they remain expandable for audit. |
chienchunhung
left a comment
There was a problem hiding this comment.
Thanks for the PR. Added one non-blocking comment/question.
|
PR_Github #75974 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
1 similar comment
|
/bot run --disable-fail-fast |
|
PR_Github #76024 [ run ] triggered by Bot. Commit: |
|
PR_Github #76025 [ run ] triggered by Bot. Commit: |
|
PR_Github #76024 [ run ] completed with state |
|
PR_Github #76025 [ run ] completed with state |
Keep prefill capture on local call state after NVIDIA#18060 and take NVIDIA#19743's cached_tokens change. Signed-off-by: Lori Ren <[email protected]>
…factor/decoder-runner-migration Port the main-side engine changes (NVIDIA#18813, NVIDIA#18060, NVIDIA#19743) into DecoderRunner and share the startup metrics dict with the engine. Signed-off-by: Lori Ren <[email protected]>
Dev Engineer Review
The change latches
cached_tokensfrom prefix reuse for generation-only requests._prepare_tp_inputsno longer sets the field from decode positions, except for promoted final-context rows._prepare_disagg_gen_resourcesinitializes it fromprepopulated_prompt_len. This corrects the reported cold-request overcount while preserving the set-once behavior. No current review findings were supplied; finding counts are unavailable. Test results are also unavailable.QA Engineer Review
The change adds
tests/unittest/_torch/executor/test_gen_only_cached_tokens.py, which checks zero and nonzero prefix reuse and verifies thatcached_tokensremains latched. It also modifies the request factory, the KV-connector generation-only test, and the disaggregated receive-ordering helper. The reported receive-ordering failure caused by missingprepopulated_prompt_lenwas addressed by adding that attribute to the test fake. No test-list files changed. The reported integration checks are not confirmed as passing. Coverage verdict: needs follow-up.Per-File QA Perspective
tensorrt_llm/_torch/pyexecutor/model_engine.py: Verify that decode paths do not overwritecached_tokensand that promoted final-context rows still report reused-prefix tokens.tensorrt_llm/_torch/pyexecutor/py_executor.py: Verify that generation-only requests setcached_tokensfromprepopulated_prompt_lenbefore connector reporting.tests/unittest/_torch/executor/test_gen_only_cached_tokens.py: Covers zero and nonzero reuse and the set-once behavior. This unit test is not listed in CI or manual-QA integration lists.tests/unittest/_torch/executor/llm_request_factory.py: Adds a shared helper to buildLlmRequestobjects, including generation-only context parameters. Check that tests using the helper preserve their intended request setup.tests/unittest/_torch/executor/test_kv_connector_generation_only.py: Reuses the shared request helper while retaining context-request and generation-only guard checks. This unit test is not listed in CI or manual-QA integration lists.tests/unittest/_torch/executor/test_disagg_receive_ordering.py: Addsprepopulated_prompt_lento mocked requests to match the resource-preparation input. This unit test is not listed in CI or manual-QA integration lists.Description
Result.cached_tokensfor a disaggregated generation-only request equals the prompt length, even on a cold cache. The KV arrived by transfer; nothing was served from a prefix cache.LlmRequest.cached_tokensis a set-once field that reports the prompt prefix served from the KV cache. The generation (decode) branch of_prepare_tp_inputsalso wrote it, from the decode positionmax_beam_num_tokens - 1. For every request whose context phase ran on this worker that write is a silent no-op, because the context branch already latched the real prefix. A generation-only request never runs the context branch on the generation worker, so the decode write was its first write and the sequence length was latched as a cache hit. Every consumer of the field then saw it: the five response-copy sites,LlmRequest.create_response, the ADP router's active-token load, the Prometheusprompt_cache_cached_tokensmetric, the gRPC servicers andRequestOutput.cached_tokens.This fixes the writer instead of the readers (alternative to #19708, which patches three of the response sites):
_prepare_tp_inputs: the decode branches no longer writecached_tokens. The one exception is a promoted one-token final context chunk, for which the decode branch is the request's context-phase forward; it latchescontext_current_positionexactly as the context branch does.num_cached_tokens_per_seq(attention metadata) is untouched._prepare_disagg_gen_resources: generation-only requests latchcached_tokensfromprepopulated_prompt_lenright after the allocation decides how much of the prompt this worker's cache lookup matched. This is the generation-worker analogue of the context branch's first-chunk latch and uses the same definition (tokens matched, partial-block match included). Transfer granularity is a separate concern: the transceiver skips only whole matched blocks and re-receives a trailing partially matched block, so on a warm local hit the reported count can exceed the skipped tokens by up totokens_per_block - 1.Not changed: the set-once property (chunked prefill relies on it), the response sites and router (they now read a correct value), and the
ctx_usagepath (the context worker's count still reaches the generation worker over the KV aux buffer and the serve postprocessor still adopts it, sotrtllm-serveoutput via the disaggregated server is unchanged).Behaviour that changes on a generation worker:
RequestOutput.cached_tokens, gRPC usage and the Prometheus metric report the locally reused prefix (0 on a cold cache) instead of the prompt length.prompt_len - local_reuseactive tokens for its whole life, on the same scale as aggregated requests, instead of dropping to 0 after its first step. Flagging for the router owners since attention-DP generation workers will balance differently.Test Coverage
tests/unittest/_torch/executor/test_gen_only_cached_tokens.py(cpu_only): builds a real generation-onlyLlmRequestthrough the new sharedllm_request_factory.make_llm_request(also adopted bytest_kv_connector_generation_only.py), drives_prepare_disagg_gen_resourceswith a fake KV manager that settlesprepopulated_prompt_lento 0 or 8, asserts the latch equals the reuse, and asserts a subsequent decode-position write bounces off it.tests/unittest/_torch/executor/test_pytorch_model_engine.py::test_promoted_context_uses_prompt_token_during_overlapstill asserts a promoted chunk latchescontext_current_position.1.3.0rc29, Qwen3-0.6B, context-only and generation-onlytrtllm-serveworkers on one node, two-call flow driven directly so noctx_usageis attached). Before, with the container as shipped: the generation side reportedcached_tokens=186of 186 prompt tokens on a cold request and again on the warm repeat, and its Prometheusprompt_cached_tokens_totaladvanced by 186 each time. After, with this fix cherry-picked ontov1.3.0rc29(clean merge) and the two files swapped into the container: cold0, warm repeat185(the prefix the generation worker already held and did not receive). The context side (0,185) and an aggregated control request on the generation worker (185) were identical in both runs, as was the generated text.tests/integration/defs/disaggregated/test_disaggregated.pyusage check andtest_disaggregated_single_gpu.pycached-token checks cover the disaggregated path end to end.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.