Repository navigation
Conversation
…after a recompute A recompute moves the generated tokens into the prompt, and the new grammar matcher started from the start of the grammar. Accept those tokens into the new matcher first, and fail the request on a rejected one. Signed-off-by: Andrew Rusli <[email protected]>
|
/bot run |
|
No actionable comments were generated in the recent review. WalkthroughThe guided decoder captures tokens added to a guided request’s prompt during recompute. When it creates a matcher, it replays those tokens in order, stops if the matcher terminates, and reports an error if the matcher rejects a token. ChangesGuided decoding recompute
Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
|
PR_Github #85231 [ run ] triggered by Bot. Commit: |
A guided request can keep generating after its grammar matcher accepted a stop token, for example with ignore_eos, and the matcher then rejects every further token. The replay after a recompute fed those tokens to the new matcher and failed the request. Stop the replay once the matcher is terminated, as the generation-step advance already does. Signed-off-by: Andrew Rusli <[email protected]>
|
PR_Github #85231 [ run ] completed with state |
|
/bot run |
|
PR_Github #85279 [ run ] triggered by Bot. Commit: |
|
PR_Github #85279 [ run ] completed with state |
Dev Engineer Review
GuidedRequest.from_llm_requestsetstokens_to_replayonly when all three conditions hold: the request is on its last context chunk, it has guided decoding params, andprompt_len > orig_prompt_len. The tokens areget_tokens(0)[orig_prompt_len:prompt_len]. Other requests keeptokens_to_replay = None.GuidedDecoder._buildreplays these tokens only inside the branch that creates a new matcher. The loop stops whenmatcher.is_terminated()is true. A rejected token raisesValueErrorwith the request ID, slot, and token._buildhandles the exception. The test asserts the failure, but the handling itself is not in the diff.CapturableGuidedDecodersubclassesGuidedDecoderand does not define its own_build. It therefore uses the same replay path through inheritance.tokens_to_replayis set. Otherwise, replay is skipped silently. This path is not verified in the diff.test_warmup.pyaddsprompt_len=1andorig_prompt_len=1to the fake guided request. Without these fields, the newfrom_llm_requestcomparison fails on the fake request. This change is required and does not expand scope.QA Engineer Review
Test files changed:
tests/unittest/_torch/misc/test_guided_decoder_bitmask.pyadds three GPU-gated tests:test_recompute_replays_generated_tokens_into_matcher[accepted]: expects no failed requests,matcher.accepted == [10, 11], and a next-token mask value of1.test_recompute_replays_generated_tokens_into_matcher[rejected]: expects request7to fail with text containingrejected token 10, and a mask value of0.test_recompute_replay_stops_at_terminated_matcher: uses a matcher that terminates after accepting EOS token10. Expects replay to stop,matcher.accepted == [10], and a mask value of0._build_recomputed_requestcallsreset_for_recomputewith_UNBOUNDED_PAUSE_MAX_INPUT_LEN. The file also imports this constant frompy_executor.tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_warmup.pyaddsprompt_len=1andorig_prompt_len=1to the guided-batch fake request intest_general_warmup_oom_restores_guided_batch_queue.tests/integration/test_lists/test-db/orqa/. Whether these tests run in CI test-db lists is not verified.CapturableGuidedDecoderpath directly.Per-File QA Perspective
tensorrt_llm/_torch/pyexecutor/guided_decoder.py: Recomputed guided requests now replay generated tokens into a newly created matcher. Verify that a rejected replay fails only that request and that the error names the rejected token. Verify that non-guided requests and guided requests without recompute behave as before.tests/unittest/_torch/misc/test_guided_decoder_bitmask.py: Adds accepted, rejected, and terminated-matcher recompute tests. All three require a GPU. Their CI placement is not verified.tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_warmup.py: The fake guided request gains prompt length fields. This change alters no runtime behavior.Description
Bug. When the KV cache runs short, the executor pauses a running request and prefills it again later, with
its generated tokens moved into the prompt (
PyExecutor._pause_recompute_request,LlmRequest.reset_for_recompute). Guided decoding then creates a fresh grammar matcher at the last context chunk.That matcher has not seen the tokens already generated, so the next-token mask is built as if no output existed,
and a structured-output request can produce output that its grammar rejects.
Who hits it. Guided decoding / structured output requests (JSON schema, regex, EBNF grammar, structural tag)
that are paused and recomputed because of KV cache pressure.
Fixes #18891. Same approach as #19307 by @Ritabanm, rebased on current main.
Fix.
GuidedRequest.tokens_to_replayholds the tokens past the C++orig_prompt_len, taken at the last contextchunk of a guided request whose prompt grew, that is, a recomputed request. The C++
orig_prompt_lenkeeps theuser's prompt length across a recompute, while
py_orig_prompt_lenis reset to the longer prompt, so the tokenspast
orig_prompt_lenare exactly the ones to replay.GuidedDecoder._buildaccepts those tokens into the matcher it creates, before it fills the mask. A token thegrammar rejects fails only that request, with the token in the error message.
CapturableGuidedDecoderruns thesame
_build, so it replays them as well.Risk. Low. Without a recompute
tokens_to_replayisNoneand nothing changes; requests without guideddecoding are unaffected.
Test Coverage
tests/unittest/_torch/misc/test_guided_decoder_bitmask.py::test_recompute_replays_generated_tokens_into_matcher[accepted],[rejected](GPU): a realLlmRequestrecomputed withreset_for_recompute; the new matcher accepts thegenerated tokens and the request gets a next-token mask, or a matcher that rejects a replayed token fails only
that request and it gets no mask.
tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_warmup.py: the fake request oftest_general_warmup_oom_restores_guided_batch_queuegainsprompt_lenandorig_prompt_len, which every realLlmRequesthas.With and without the fix: both cases of the new test fail on main and pass with the fix. The changed
test_warmup.pytest passes on main and with the fix.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.