Repository navigation
[https://nvbugs/7033653][perf] Skip unguided eager guided-decoding work when a prefill CUDA graph backend is enabled - #22513
Conversation
…rk when a prefill CUDA graph backend is enabled A prefill CUDA graph covers only the decoder body, so guided decoding never runs inside it. Signed-off-by: Lori Ren <[email protected]>
|
/bot run |
|
No actionable comments were generated in the recent review. WalkthroughGuided-decoder batch setup now sets ChangesGuided decoder graph flag
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk:
|
|
PR_Github #85676 [ run ] triggered by Bot. Commit: |
trtllm-agent-review
left a comment
There was a problem hiding this comment.
Checked this change against every prefill CUDA graph capture path (breakable body capture and break graphs, piecewise compile scopes, model-owned graphs) and against the guided-decoder batch queue. No prefill capture records guided-decoding work. Decode graphs that hold guided host functions replay only when maybe_graph is true. The guided path that is now skipped contains no collectives. So is_cuda_graph=maybe_graph is correct, and its only effect is to remove work from unconstrained eager steps. Posted 2 comments: 0 Blocker, 0 Possible blocker, 2 Nice to have (tests, and a comment). The CI run (L0_MergeRequest_PR #70930) was still in progress at review time.
…refill CUDA graphs Add a JsonModeEval case with MTP and breakable prefill graphs, fold the add_batch check into the steady-gen test, and name the guard in the comment. Signed-off-by: Lori Ren <[email protected]>
|
PR_Github #85676 [ run ] completed with state
|
|
/bot run |
|
PR_Github #85707 [ run ] triggered by Bot. Commit: |
|
/bot kill |
|
PR_Github #85712 [ kill ] triggered by Bot. Commit: |
|
PR_Github #85707 [ run ] completed with state |
|
PR_Github #85712 [ kill ] completed with state |
brnguyen2
left a comment
There was a problem hiding this comment.
Approving — the comments below are optional touch-ups, not blockers.
The fix depends on one claim: prefill CUDA graphs never contain guided-decoding host functions, so a prefill-backend forward with maybe_graph=False can safely skip guided work when no request is guided. _skip_inactive raises at capture if that claim is ever wrong, so a violation fails at startup rather than silently replaying without grammar masks. The new accuracy test exercises this for BREAKABLE + MTP. PIECEWISE is not exercised; see the inline comment.
The description is the auto-generated reviewer summary. Please add:
LarryXFly
left a comment
There was a problem hiding this comment.
Review summary - Approve
Reviewed the full diff; no blocking or major issues found.
Automated review by NVCortex Lite, run by @LarryXFly.
…g-eager-drain Signed-off-by: Lori Ren <[email protected]>
|
/bot run |
|
PR_Github #85910 [ run ] triggered by Bot. Commit: |
|
PR_Github #85910 [ run ] completed with state
|
|
/bot run |
|
PR_Github #85967 [ 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. |
bo-nv
left a comment
There was a problem hiding this comment.
Reviewed the graph boundaries and the disaggregated generation handoff at 67bd4c7. Full decode graphs still enqueue guided work, and a constrained request in a mixed batch keeps the matcher active on the first generation step. An unguided eager step still drains pending callbacks from a previous graph replay. I found no blocking issues.
…y across prefill graph backends The breakable case now reuses the JsonModeEval body of test_guided_decoding, and the unit-test helper forwards config changes. Signed-off-by: Lori Ren <[email protected]>
|
PR_Github #85967 [ run ] completed with state
|
|
/bot run |
|
PR_Github #86020 [ run ] triggered by Bot. Commit: |
bo-nv
left a comment
There was a problem hiding this comment.
Re-reviewed 59358e9, including the disaggregated generation handoff. The test refactor preserves the four existing guided-decoding configurations and their pytest IDs. The dedicated B200 case still exercises xgrammar with MTP and BREAKABLE prefill graphs. Full decode graphs and constrained mixed batches still enqueue guided work. No blocking findings.
|
PR_Github #86020 [ run ] completed with state
|
|
/bot run |
|
PR_Github #86082 [ run ] triggered by Bot. Commit: |
|
PR_Github #86082 [ run ] completed with state |
Dev Engineer Review
tensorrt_llm/_torch/pyexecutor/engine/runners/decoder/inputs.py(DecoderInputPreparer.prepare_inputs): The guided decoderadd_batchcall now passesis_cuda_graph=maybe_graph. Before this change, the value also becameTruewhenprefill_cuda_graph_backendwas notDISABLED. The change affects batches where a prefill CUDA graph backend is enabled andmaybe_graphis false. For those batches,is_cuda_graphis nowFalse.CapturableGuidedDecodernow receivesFalsefor prefill-backend batches that are not CUDA-graph batches. Confirm that theFalsepath is correct for those batches._skip_inactivelogic raisesRuntimeErrorwhen a capture records guided work while guided decoding is inactive. This logic is outside the diff and was not inspected. The PR states thatbreakablecapture does not trigger it.#21460asks to skip guided-decoding work on all unguided eager steps. This diff changes only the prefill-backend flag. It does not change the drain or host-function behavior for other eager steps. Scope against the issue is partial.QA Engineer Review
Test files and test-list files changed:
tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_inputs.py(modified). The helper_input_preparernow accepts arbitrary decoder configuration overrides and forwards them todecoder_config.test_prepare_inputs_returns_steady_gen_fast_inputsnow loops over everyPrefillCudaGraphBackendmember and overmaybe_graphvaluesFalseandTrue. It passesmaybe_graphtoprepare_inputsand asserts thatadd_batchreceives it asis_cuda_graph.tests/integration/defs/accuracy/test_llm_api_pytorch.py(modified). The guided-decoding setup moves into_evaluate_guided_decoding. The existing parameterized test delegates to this helper. A new Hopper-and-newer test,TestDeepSeekV3Lite::test_guided_decoding_breakable_prefill_cuda_graph, covers xgrammar with MTPmax_draft_len=2andPrefillCudaGraphBackend.BREAKABLE.tests/integration/test_lists/test-db/l0_b200.yml(modified). AddsTestDeepSeekV3Lite::test_guided_decoding_breakable_prefill_cuda_graphto the B200 pre-merge list.Test functions and selectors added or modified:
TestDeepSeekV3Lite::test_guided_decoding_breakable_prefill_cuda_graph.DecoderInputPreparerTestCase::test_prepare_inputs_returns_steady_gen_fast_inputs.Coverage:
is_cuda_graphexpression for all backends, includingDISABLED, and for bothmaybe_graphvalues.BREAKABLEbackend. It does not runPIECEWISE.tests/unittest/_torch/speculative/hw_agnostic/test_guided_hostfunc_drain.py. That file is not in this diff. Its presence and results were not verified.CapturableGuidedDecoderis not tested directly in this diff.test_inputs.pyintest-db/orqa/was not verified.Coverage verdict: needs follow-up. The unit test covers the changed condition. The integration test covers only the
BREAKABLEbackend. Drain behavior is not verified in this diff.Per-File QA Perspective
tensorrt_llm/_torch/pyexecutor/engine/runners/decoder/inputs.py: With a prefill CUDA graph backend enabled andmaybe_graphfalse, verify that guided decoding still applies its constraints on eager steps. Verify that outputs match the prior behavior.tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_inputs.py: Extends the steady-generation test to every backend and bothmaybe_graphvalues. Not listed intest-db/orqa/in the diff.tests/integration/defs/accuracy/test_llm_api_pytorch.py: Adds aBREAKABLEprefill-graph guided-decoding accuracy test. Requires Hopper or newer.tests/integration/test_lists/test-db/l0_b200.yml: Adds the new accuracy test to the B200 pre-merge list.Description
Closes #21460.
With one-model speculative decoding and guided decoding,
CapturableGuidedDecoderdrains the GPU after every guided-decoding stage of an eager forward. #20011 made it skip that work when no request in the batch is guided, butDecoderInputPreparerstill marks every forward as a CUDA-graph forward whenever a prefill CUDA graph backend (breakable/piecewise) is enabled, so unguided eager steps keep paying for four drains per step with MTPmax_draft_len: 3.That condition came from the #20011 review: correctness of the skip depends on every forward that captures guided work passing
is_cuda_graph=True, and a prefill graph is captured withmaybe_graph=False, so the prefill backend was treated as one that might capture it. It does not: a prefill CUDA graph covers only the decoder body, and guided decoding runs after it in the spec worker, eagerly. The loud-failure check that review also asked for is in place: capturing a graph while guided decoding is inactive raisesRuntimeError, so a runner that did capture guided work would fail at startup rather than silently drop grammar enforcement. This PR passesis_cuda_graph=maybe_graph; with it, thebreakablebackend starts, captures every prefill bucket and serves without hitting that error.piecewiseprefill capture does not happen in this configuration, becauseCapturableGuidedDecodersets torch.compile toforce_eager.Validation
A hook counts the drain waits per step kind, and every A/B runs inside one server process ("before" forces the old
is_cuda_graph=True). Throughput runs use 160 concurrency, 8K in / 1K out, 480 requests per run, after a discarded warm-up run, in balanced order (after, before, before, after, after, before).Waits per unguided eager step (4×B100, TP4, Nemotron-3 Super NVFP4, MTP 3, xgrammar):
breakablepiecewiseOutput throughput on 1×B300 SXM6, tok/s:
breakableIn both rows every "after" run is faster than every "before" run. The VL model rejects the
breakablebackend (multimodal models are unsupported), so this PR's own case was measured with the text-only model, which has the same language-model architecture. Structured output (32json_schema+ 64 unguided requests) shows no schema violations or errors in either behaviour.Test Coverage
tests/integration/defs/accuracy/test_llm_api_pytorch.py::TestDeepSeekV3Lite::test_guided_decoding_breakable_prefill_cuda_graph(new,l0_b200): xgrammar, MTP 2 andbreakableprefill graphs on JsonModeEvaltests/unittest/_torch/pyexecutor/engine/runners/decoder/test_inputs.py::DecoderInputPreparerTestCase::test_prepare_inputs_returns_steady_gen_fast_inputstests/unittest/_torch/speculative/hw_agnostic/test_guided_hostfunc_drain.pyPR 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.