Repository navigation
Conversation
RouteCapture derives each decode row's position from the request's prompt length plus a per-request decode counter. Two things broke that position once an opted-in request is paused after it has decoded and later re-prefilled (KV cache manager V2 recompute under KV pressure, connector-deferred preemption, recompute_active_requests after a weight update): - The counter survived the re-prefill. The re-prefilled prompt already holds the generated tokens, so every later decode row landed past the end of the sequence; assemble() then found a gap and raised ValueError when the request finished, which fails the request batch or stops the executor loop. - The position read py_prompt_len, which a plain pause (KV cache manager V1) does not refresh while the C++ prompt length grows. The later decode rows were shifted onto earlier positions and the routes silently came back short. A context phase now resets the request's decode counter, and decode positions use the live prompt_len. Under helix context parallelism both lengths hold the same rank-local value, so that path is unchanged. Beam width > 1 is out of scope: a pause there trims the tokens back to the original prompt. Router Replay itself landed in NVIDIA#18397. Tests: a recompute after decoding, with a refreshed and with a stale py_prompt_len; both fail without this change, and the stale case also fails with the counter reset alone. Signed-off-by: Andrew Rusli <[email protected]>
|
/bot run |
|
No actionable comments were generated in the recent review. WalkthroughRoute capture now resets per-request generation counts during context phases and calculates decode positions from the live prompt length. New tests cover route positions after pause and re-prefill, including cases where ChangesRoute capture position tracking
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Possibly related issues
Suggested reviewers: Merge Risk:
|
|
PR_Github #85241 [ run ] triggered by Bot. Commit: |
|
PR_Github #85241 [ run ] completed with state |
Dev Engineer Review
tensorrt_llm/_torch/route_capture.py(+12/-8, per the diff stat): The context phase now sets the per-request decode counter to 0 withself._gen_count[rid] = 0. Previously it usedsetdefault(rid, 0), so the counter survived a re-prefill. This change is the fix for decode positions after a recompute pause.int(req.prompt_len) + self._gen_count.get(rid, 0). The old code usedgetattr(req, "py_prompt_len", 0). The change depends on the liveprompt_lenbeing correct after a pause. The diff does not show howprompt_lenis maintained, so that dependency is unverified here.getattrdefault of 0 is removed.req.prompt_lenis now read directly. A request object without this attribute would now raiseAttributeErrorinstead of falling back to 0. Confirm that every request type reaching this path definesprompt_len.QA Engineer Review
Test files changed:
tests/unittest/_torch/test_route_capture.py: +70 lines, no removals. Two new recompute tests, per the PR objectives and the raw summary. Test function names were not visible in the diff stat, so they are not listed here.tests/unittest/llmapi/test_return_routed_experts.pywas run by the author but skipped because its model was unavailable. It is not covered.tests/integration/test_lists/test-db/orqa/: not established from the diff.Coverage verdict:
needs follow-up. The new tests cover the two reported causes. The llmapi test was skipped, and CI results for the current head were not available.Per-File QA Perspective
tensorrt_llm/_torch/route_capture.py: Verify that routed-expert positions restart after a pause-and-recompute on a request that has already generated tokens. Verify that routes stay complete andassemble()no longer raisesValueErrorin that case.tests/unittest/_torch/test_route_capture.py: Covers recompute after decoding, with both a refreshed and a stalepy_prompt_len. Confirm these tests are listed in the appropriate test-db CI list. Not verified here.Description
Bug. Router Replay (
RouteCapture,enable_return_routed_experts) gives each decode row of a request theposition
py_prompt_len + gen_count, wheregen_countcounts the request's processed decode tokens. When an opted-inrequest has decoded and is then paused and prefilled again, that position is wrong:
decode row lands past the end of the sequence.
assemble()then finds a gap and raisesValueErrorwhen therequest finishes, which fails the request batch (non-overlap loop) or stops the executor loop (overlap loop).
py_prompt_lencan be stale. A plain pause with KV cache manager V1 grows the C++ prompt length but does notrefresh
py_prompt_len, so the later decode rows shift onto earlier positions and the returned routes are silentlyshort. No error is raised.
Who hits it. Any opted-in request that is recomputed after at least one decode step:
recompute_active_requestsafter a weight update.Fix. In
RouteCapture._prepare:phase prefills.
req.prompt_leninstead ofpy_prompt_len.Out of scope. Beam width > 1: a pause there trims the tokens back to the original prompt. Router Replay landed
in #18397.
Risk. Low. Requests that are never recomputed get the same positions as before. Only recomputed requests change,
and they now return complete routes instead of failing or returning short ones.
Test Coverage
tests/unittest/_torch/test_route_capture.py(CPU), two new tests. Their fake router rows carry each token's trueposition, so a shifted or skipped position is visible in the assembled routes:
test_recompute_restarts_decode_positions_after_the_grown_prompt: prefill, decodes, a recompute re-prefill of thegrown prompt, more decodes. The assembled routes cover prompt + generated - 1 positions in order.
test_recompute_reads_the_live_prompt_length_when_py_prompt_len_is_stale: the same with a stalepy_prompt_len(the KV cache manager V1 pause).
With and without the fix, on main's code:
tests/unittest/llmapi/test_return_routed_experts.pywas also run; it was skipped because its model is notavailable in our environment.
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.