Skip to content

[https://nvbugs/7033653][perf] Skip unguided eager guided-decoding work when a prefill CUDA graph backend is enabled - #22513

Merged
lori-ren merged 4 commits into
NVIDIA:mainfrom
lori-ren:perf/guided-decoding-eager-drain
Nov 19, 2026

Conversation

@lori-ren

@lori-ren lori-ren commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Dev Engineer Review

  • tensorrt_llm/_torch/pyexecutor/engine/runners/decoder/inputs.py (DecoderInputPreparer.prepare_inputs): The guided decoder add_batch call now passes is_cuda_graph=maybe_graph. Before this change, the value also became True when prefill_cuda_graph_backend was not DISABLED. The change affects batches where a prefill CUDA graph backend is enabled and maybe_graph is false. For those batches, is_cuda_graph is now False.
  • Risk: CapturableGuidedDecoder now receives False for prefill-backend batches that are not CUDA-graph batches. Confirm that the False path is correct for those batches.
  • The _skip_inactive logic raises RuntimeError when a capture records guided work while guided decoding is inactive. This logic is outside the diff and was not inspected. The PR states that breakable capture does not trigger it.
  • Linked issue #21460 asks 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.
  • The PR reports drain waits per unguided eager step falling from four to zero, and throughput gains on B300 and B200. These numbers come from the author's setup. This review did not verify them.
  • The diff changes four files: 54 lines added and 36 removed.

QA Engineer Review

Test files and test-list files changed:

  • tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_inputs.py (modified). The helper _input_preparer now accepts arbitrary decoder configuration overrides and forwards them to decoder_config. test_prepare_inputs_returns_steady_gen_fast_inputs now loops over every PrefillCudaGraphBackend member and over maybe_graph values False and True. It passes maybe_graph to prepare_inputs and asserts that add_batch receives it as is_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 MTP max_draft_len=2 and PrefillCudaGraphBackend.BREAKABLE.
  • tests/integration/test_lists/test-db/l0_b200.yml (modified). Adds TestDeepSeekV3Lite::test_guided_decoding_breakable_prefill_cuda_graph to the B200 pre-merge list.

Test functions and selectors added or modified:

  • Added: TestDeepSeekV3Lite::test_guided_decoding_breakable_prefill_cuda_graph.
  • Modified: DecoderInputPreparerTestCase::test_prepare_inputs_returns_steady_gen_fast_inputs.

Coverage:

  • The unit test covers the changed is_cuda_graph expression for all backends, including DISABLED, and for both maybe_graph values.
  • The integration test runs only the BREAKABLE backend. It does not run PIECEWISE.
  • The PR objectives name 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.
  • Drain-count behavior of CapturableGuidedDecoder is not tested directly in this diff.
  • Membership of test_inputs.py in test-db/ or qa/ was not verified.

Coverage verdict: needs follow-up. The unit test covers the changed condition. The integration test covers only the BREAKABLE backend. 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 and maybe_graph false, 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 both maybe_graph values. Not listed in test-db/ or qa/ in the diff.
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py: Adds a BREAKABLE prefill-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, CapturableGuidedDecoder drains 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, but DecoderInputPreparer still 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 MTP max_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 with maybe_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 raises RuntimeError, so a runner that did capture guided work would fail at startup rather than silently drop grammar enforcement. This PR passes is_cuda_graph=maybe_graph; with it, the breakable backend starts, captures every prefill bucket and serves without hitting that error. piecewise prefill capture does not happen in this configuration, because CapturableGuidedDecoder sets torch.compile to force_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):

Prefill graph backend Before After
breakable 4 (748 waits / 187 steps) 0 (207 steps, all inactive)
piecewise 4 (484 / 121) 0 (117 steps, all inactive)

Output throughput on 1×B300 SXM6, tok/s:

Case Model Before After After / before
This PR, breakable Nemotron-3 Super NVFP4 2420.3 / 2413.0 / 2409.8 2484.0 / 2479.5 / 2477.3 1.027
#20011's skip, prefill graphs off (the issue's setup) Nemotron 3.5 Super VL NVFP4 2850.3 / 2817.8 / 2841.7 3001.8 / 3032.8 / 2962.5 1.057

In both rows every "after" run is faster than every "before" run. The VL model rejects the breakable backend (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 (32 json_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 and breakable prefill graphs on JsonModeEval
  • tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_inputs.py::DecoderInputPreparerTestCase::test_prepare_inputs_returns_steady_gen_fast_inputs
  • tests/unittest/_torch/speculative/hw_agnostic/test_guided_hostfunc_drain.py

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-compatible or api-breaking. For api-breaking, include BREAKING in 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.

…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]>
@lori-ren
lori-ren marked this pull request as ready for review November 18, 2026 04:33
@lori-ren
lori-ren requested review from a team as code owners November 18, 2026 04:33
@lori-ren

Copy link
Copy Markdown
Contributor Author

/bot run

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Guided-decoder batch setup now sets is_cuda_graph from maybe_graph alone. Unit tests cover both maybe_graph values and prefill CUDA-graph backends. Integration coverage includes guided decoding with breakable prefill CUDA graphs.

Changes

Guided decoder graph flag

Layer / File(s) Summary
Set and verify guided-decoder graph state
tensorrt_llm/_torch/pyexecutor/engine/runners/decoder/inputs.py, tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_inputs.py
guided_decoder.add_batch now receives maybe_graph as is_cuda_graph. The unit test checks this for both maybe_graph values and each prefill CUDA-graph backend.
Cover breakable prefill graph decoding
tests/integration/defs/accuracy/test_llm_api_pytorch.py, tests/integration/test_lists/test-db/l0_b200.yml
A guided-decoding accuracy test uses xgrammar, MTP draft length 2, and the BREAKABLE prefill CUDA-graph backend. The B200 pre-merge test list includes the test.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 59358

Guided decoding now skips graph-mode work on eager steps even when a prefill CUDA graph backend is enabled. This removes unnecessary waits. Unit and integration tests cover the change, and no merge-blocking issue was identified.

Security architecture risk: Minimal · up to 59358

The optimization skips unnecessary work for unconstrained eager batches. Constrained batches remain active, and the inspected change establishes no introduced or worsened security or failure-containment risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: prefill CUDA graph backends no longer cause unguided eager steps to run guided-decoding drain work. It follows the NVBugs ID and type format from the template. The tit…
Description check Passed The description covers the problem, the cause, the fix, validation measurements, and test coverage. It lists the new breakable prefill CUDA graph test, the unit test, and the hw-agnostic drain test. T…
Linked Issues check Passed [#21460] The issue asks that unguided eager steps skip guided-decoding host functions, bitmask copies, and drains. Guided batches and pending CUDA-graph host work must keep the normal path. At the rev…
Out of Scope Changes check Passed The changed files named in the summaries are inputs.py (is_cuda_graph=maybe_graph), test_inputs.py (steady-generation fast-input test over PrefillCudaGraphBackend and maybe_graph, plus test-helper key…
Full details: Title check

Explanation

The title names the main change: prefill CUDA graph backends no longer cause unguided eager steps to run guided-decoding drain work. It follows the NVBugs ID and type format from the template. The title is specific to the changeset, so it passes.

Full details: Description check

Explanation

The description covers the problem, the cause, the fix, validation measurements, and test coverage. It lists the new breakable prefill CUDA graph test, the unit test, and the hw-agnostic drain test. The Description section is detailed and explains the change. The Test Coverage section lists specific tests. The PR checklist is present and checked. The title is the template format with NVBugs ID and type. Some template parts are not repeated verbatim, but the content is mostly complete, so the check passes.

Full details: Linked Issues check

Explanation

[#21460] The issue asks that unguided eager steps skip guided-decoding host functions, bitmask copies, and drains. Guided batches and pending CUDA-graph host work must keep the normal path. At the reviewed head, CapturableGuidedDecoder.add_batch activates only for is_cuda_graph or a constrained batch. test_guided_hostfunc_drain.py pins that an inactive forward enqueues nothing, that the drain runs only through drain_captured_hostfuncs when a replay is pending, and that capturing an inactive forward raises RuntimeError. This PR changes DecoderInputPreparer.prepare_inputs in inputs.py to pass is_cuda_graph=maybe_graph. Previously any enabled prefill CUDA-graph backend set is_cuda_graph. The change removes the unguided eager case that still paid the drains under a prefill graph backend. The steady-generation test in test_inputs.py checks that maybe_graph reaches add_batch as is_cuda_graph. Limitation: the inputs.py diff could not be read because changed blobs are missing from the checkout. The is_cuda_graph change therefore rests on the PR summary, the AI-generated change summary, and the PR description, not on the diff. The new integration test was not run.

Full details: Out of Scope Changes check

Explanation

The changed files named in the summaries are inputs.py (is_cuda_graph=maybe_graph), test_inputs.py (steady-generation fast-input test over PrefillCudaGraphBackend and maybe_graph, plus test-helper keyword forwarding), test_llm_api_pytorch.py (refactor into _evaluate_guided_decoding and a new breakable prefill graph guided-decoding accuracy test), and l0_b200.yml (registers that test). Each file connects to the objective of skipping unguided eager guided-decoding work under a prefill graph backend. The benchmark tables in the PR description are supporting evidence, not code changes. No unrelated code change appears in the available evidence. The inputs.py diff could not be read, so this verdict relies on the change summaries.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 67bd4c7 and 59358e9.

Files selected for processing: 2

  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_inputs.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85676 [ run ] triggered by Bot. Commit: 1b89718 Link to invocation

@trtllm-agent-review trtllm-agent-review left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85676 [ run ] completed with state SUCCESS. Commit: 1b89718
/LLM/main/L0_MergeRequest_PR pipeline #70930 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lori-ren

Copy link
Copy Markdown
Contributor Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85707 [ run ] triggered by Bot. Commit: 76719a2 Link to invocation

@lori-ren

Copy link
Copy Markdown
Contributor Author

/bot kill

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85712 [ kill ] triggered by Bot. Commit: 76719a2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85707 [ run ] completed with state ABORTED. Commit: 76719a2

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85712 [ kill ] completed with state SUCCESS. Commit: 76719a2
Successfully killed previous jobs for commit 76719a2

Link to invocation

@brnguyen2 brnguyen2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • the motivation (unguided eager steps with a prefill graph backend still paid for the guided host-function drains),
  • links to the GitHub issue (#21460) and #20011, which this PR extends to the prefill-graph case,
  • the measured before/after numbers, so the [perf] tag has data behind it.

@LarryXFly LarryXFly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary - Approve

Reviewed the full diff; no blocking or major issues found.

Automated review by NVCortex Lite, run by @LarryXFly.

@lori-ren

Copy link
Copy Markdown
Contributor Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85910 [ run ] triggered by Bot. Commit: 67bd4c7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85910 [ run ] completed with state SUCCESS. Commit: 67bd4c7
/LLM/main/L0_MergeRequest_PR pipeline #71146 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lori-ren

Copy link
Copy Markdown
Contributor Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85967 [ run ] triggered by Bot. Commit: 67bd4c7 Link to invocation

@github-actions

Copy link
Copy Markdown

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 bo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85967 [ run ] completed with state SUCCESS. Commit: 67bd4c7
/LLM/main/L0_MergeRequest_PR pipeline #71193 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lori-ren

Copy link
Copy Markdown
Contributor Author

/bot run

@lori-ren
lori-ren enabled auto-merge (squash) November 19, 2026 08:15
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86020 [ run ] triggered by Bot. Commit: 59358e9 Link to invocation

@bo-nv bo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86020 [ run ] completed with state SUCCESS. Commit: 59358e9
/LLM/main/L0_MergeRequest_PR pipeline #71245 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@lori-ren

Copy link
Copy Markdown
Contributor Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86082 [ run ] triggered by Bot. Commit: 59358e9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86082 [ run ] completed with state SUCCESS. Commit: 59358e9
/LLM/main/L0_MergeRequest_PR pipeline #71296 completed with status: 'SUCCESS'

CI Report

Link to invocation

@lori-ren
lori-ren merged commit 7d6def1 into NVIDIA:main Nov 19, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] Guided decoding with one-model speculative decoding drains the GPU 4 times per eager step, even when no request is guided