Skip to content

[https://nvbugs/6475346][fix] Avoid stale CUD… - #16952

Open
liji-nv wants to merge 4 commits into
NVIDIA:mainfrom
liji-nv:agent/fix-pcg-cuda-graph-pool-reuse
Open

[https://nvbugs/6475346][fix] Avoid stale CUD…#16952
liji-nv wants to merge 4 commits into
NVIDIA:mainfrom
liji-nv:agent/fix-pcg-cuda-graph-pool-reuse

Conversation

@liji-nv

@liji-nv liji-nv commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

…A graph pool reuse

A torch.compile Backend cached a CUDA graph pool handle at class scope and passed that handle to the outer generation CUDA graph runner. When the QA session-reuse path created a second LLM in the same MPI worker, the first LLM had already reset its graphs and released the allocator private pool, but the Backend class still retained the old handle tuple. The next generation-only capture attempted to reuse that stale pool ID and failed in CUDACachingAllocator with use_count > 0.

Piecewise CUDA graphs did not actually use this pre-created handle: piecewise_optimizer immediately replaced the argument with a new graph_pool_handle and shared that independently owned pool among its runners. Remove the unused Backend parameter and class-level registration. Let PCG continue to own its private pool, and initialize the outer generation runner without a pool so its first successful capture creates the pool that subsequent graphs reuse through graph.pool().

Unwaive the affected Gemma3 FP8 torch.compile cases on B300 and GB300, and the affected DeepSeekV3Lite NVFP4 torch.compile cases on RTX PRO 6000 Blackwell.

Validation: reproduced the failure with the DeepSeekV3Lite-to-Gemma3 session-reuse sequence on CMH GB300 (job 2707269), then verified the same sequence completes successfully with this fix (job 2707407).

Fixes https://nvbugs/6475346

Fixes https://nvbugs/6473373

Dev Engineer Review

  • Fixed stale CUDA graph pool reuse by removing Backend-level cached pool plumbing in tensorrt_llm/_torch/compilation/backend.py:
    • Deleted Backend._graph_pool_handle and the associated lazy initialization/registration logic.
    • In the piecewise CUDA graph path, piecewise_optimizer is no longer passed a shared graph pool handle; piecewise orchestration (runner updates, event generation, and returning the compiled GraphModule) remains intact.
  • Updated tensorrt_llm/_torch/compilation/piecewise_optimizer.py API to remove the externally provided graph_pool_handle parameter:
    • piecewise_optimizer now creates/initializes its own internal pool via torch.cuda.graph_pool_handle().
  • Updated tensorrt_llm/_torch/pyexecutor/model_engine.py to reinforce pool ownership boundaries:
    • _cuda_graph_mem_pool is no longer derived from the torch-compile backend pool handle and is initialized to None (first capture creates a private pool; piecewise graphs keep private pool ownership; outer generation uses graph.pool() to create/reuse its own pool).
    • Tightened generation-batch MRoPE handling in _prepare_tp_inputs:
      • Added has_gen_mrope_delta to detect whether any generation request supplies non-zero mrope_position_deltas.
      • When generation multimodal lacks usable mrope_config/deltas, it records a reserved “zero delta” slot (mrope_dummy_seq_slot) and clears mrope_delta_read_seq_slots when no real deltas exist to preserve the steady-state fast path.
      • Context token MRoPE position-id span recording now tolerates missing mrope_position_ids by only appending when present.

QA Engineer Review

  • Test-list change: tests/integration/test_lists/waives.txt

    • Removed SKIP entries:
      • full:L40S/...::TestQwen3_30B_A3B::test_fp8[latency-torch_compile=True]
      • perf/test_perf_sanity.py::test_e2e[disagg_upload-gen_only-b200_deepseek-r1-fp4_...]
      • full:B300/...::TestGemma3_1BInstruct::test_fp8_prequantized[torch_compile=True]
      • full:GB300/...::TestGemma3_1BInstruct::test_fp8_prequantized[torch_compile=True]
    • Adjusted SKIP entries (narrowed combinations) for:
      • full:RTX_PRO_6000_Blackwell_Server_Edition/...::TestDeepSeekV3Lite::test_nvfp4
      • Replaced CUTLASS SKIP waivers for mtp_nextn=0 and mtp_nextn=2 with a narrower set that keeps only cuda_graph=False and overlap_scheduler=False combinations (dropping broader variants including cuda_graph=True / other parameter combos).
  • Verdict: needs follow-up (CBTS coverage data not provided).

Description

Test Coverage

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.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

…A graph pool reuse

A torch.compile Backend cached a CUDA graph pool handle at class scope and passed that handle to the outer generation CUDA graph runner. When the QA session-reuse path created a second LLM in the same MPI worker, the first LLM had already reset its graphs and released the allocator private pool, but the Backend class still retained the old handle tuple. The next generation-only capture attempted to reuse that stale pool ID and failed in CUDACachingAllocator with use_count > 0.

Piecewise CUDA graphs did not actually use this pre-created handle: piecewise_optimizer immediately replaced the argument with a new graph_pool_handle and shared that independently owned pool among its runners. Remove the unused Backend parameter and class-level registration. Let PCG continue to own its private pool, and initialize the outer generation runner without a pool so its first successful capture creates the pool that subsequent graphs reuse through graph.pool().

Unwaive the affected Gemma3 FP8 torch.compile cases on B300 and GB300, and the affected DeepSeekV3Lite NVFP4 torch.compile cases on RTX PRO 6000 Blackwell.

Validation: reproduced the failure with the DeepSeekV3Lite-to-Gemma3 session-reuse sequence on CMH GB300 (job 2707269), then verified the same sequence completes successfully with this fix (job 2707407).

Fixes https://nvbugs/6475346

Fixes https://nvbugs/6473373

Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
@liji-nv
liji-nv requested review from a team as code owners July 28, 2026 12:37
@liji-nv liji-nv changed the title [https://nvbugs/6475346][https://nvbugs/6473373][fix] Avoid stale CUD… [https://nvbugs/6475346 https://nvbugs/6473373][fix] Avoid stale CUD… Jul 28, 2026
@liji-nv liji-nv changed the title [https://nvbugs/6475346 https://nvbugs/6473373][fix] Avoid stale CUD… [https://nvbugs/6475346][fix] Avoid stale CUD… Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0c040cf1-04a5-4770-9f94-5afec7d5a17a

📥 Commits

Reviewing files that changed from the base of the PR and between d1c46ec and f2869b8.

📒 Files selected for processing (1)
  • tests/integration/test_lists/waives.txt
💤 Files with no reviewable changes (1)
  • tests/integration/test_lists/waives.txt

Walkthrough

CUDA graph pool ownership is no longer shared through Backend. Piecewise optimization creates its own pool handle, while PyTorchModelEngine starts without a pre-created pool. MRoPE input preparation now handles missing metadata and zero-delta generation batches, and related integration waivers are updated.

Changes

CUDA graph and MRoPE execution updates

Layer / File(s) Summary
Piecewise optimizer pool ownership
tensorrt_llm/_torch/compilation/backend.py, tensorrt_llm/_torch/compilation/piecewise_optimizer.py
Backend no longer stores or passes a graph pool handle, and piecewise_optimizer initializes the handle internally.
Engine CUDA graph pool initialization
tensorrt_llm/_torch/pyexecutor/model_engine.py
PyTorchModelEngine initializes its CUDA graph pool reference to None, with separate ownership for piecewise CUDA graphs.
Defensive MRoPE input preparation
tensorrt_llm/_torch/pyexecutor/model_engine.py
Context and generation MRoPE handling tolerates missing metadata, maintains aligned dummy-slot indexing, and clears all-zero delta reads.
Integration waiver updates
tests/integration/test_lists/waives.txt
Integration waiver entries are removed or narrowed for affected configurations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: reasonsolo, mikeiovine, mzweilz, jieli-matrix, mlefeb01

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific and matches the CUDA graph pool reuse fix, though it is truncated in the display.
Description check ✅ Passed The description covers the issue, fix, validation, and checklist, with only some template headings left implicit.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@liji-nv

liji-nv commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62197 [ run ] triggered by Bot. Commit: 9eb0439 Link to invocation

@chienchunhung chienchunhung 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.

Thanks for the PR!

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62197 [ run ] completed with state FAILURE. Commit: 9eb0439
/LLM/main/L0_MergeRequest_PR pipeline #50367 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

@BowenFu BowenFu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified the default path is unchanged: `torch_compile_config` defaults to None, so `_cuda_graph_mem_pool` was already None there — this only converges the torch.compile path onto it. The dropped `piecewise_optimizer` arg was dead (overwritten at piecewise_optimizer.py:281), and all 6 waiver removals match exactly one line each on main with nothing re-added.

Not blocking, but worth noting: the validation you cite (jobs 2707269/2707407) is the GB300 session-reuse sequence, which covers 6475346; the four RTX PRO 6000 unwaives for 6473373 ride on same-root-cause reasoning rather than a cited run on that platform. Also the L0 failure on this head is unrelated — the two distinct tests are sampler logprobs and NemotronH LoRA pp1, neither of which touches torch.compile (and test_lora_pp2_sanity is already waived under 6428124).

Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
@liji-nv

liji-nv commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62422 [ run ] triggered by Bot. Commit: 5bd0663 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62422 [ run ] completed with state FAILURE. Commit: 5bd0663
/LLM/main/L0_MergeRequest_PR pipeline #50584 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

@liji-nv

liji-nv commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62667 [ run ] triggered by Bot. Commit: 5bd0663 Link to invocation

Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/integration/test_lists/waives.txt (1)

91-104: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Separate unrelated waiver additions.

These new SKIPs cover unrelated Nemotron, Qwen, Wan, perf, and DFlash cases; move them to their owning fixes so this CUDA-graph PR remains attributable and reversible. As per coding guidelines, “Keep each pull request focused on one concern; split unrelated changes into separate pull requests.”

Also applies to: 142-144, 237-237, 254-254, 336-338, 366-367

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/test_lists/waives.txt` around lines 91 - 104, Remove the
unrelated waiver entries added alongside the listed Nemotron, Qwen, Wan,
performance, and DFlash cases from the current change, leaving only waivers
owned by this CUDA-graph fix. Move each removed SKIP entry to the pull request
or change that addresses its corresponding failure, preserving the existing
waiver format and attribution.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tests/integration/test_lists/waives.txt`:
- Around line 91-104: Remove the unrelated waiver entries added alongside the
listed Nemotron, Qwen, Wan, performance, and DFlash cases from the current
change, leaving only waivers owned by this CUDA-graph fix. Move each removed
SKIP entry to the pull request or change that addresses its corresponding
failure, preserving the existing waiver format and attribution.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3659d7ec-75a6-49e5-bddb-bce7602c17d5

📥 Commits

Reviewing files that changed from the base of the PR and between 5bd0663 and d1c46ec.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
  • tests/integration/test_lists/waives.txt

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62667 [ run ] completed with state SUCCESS. Commit: 5bd0663
/LLM/main/L0_MergeRequest_PR pipeline #50808 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

@liji-nv

liji-nv commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@liji-nv
liji-nv enabled auto-merge (squash) July 30, 2026 12:43
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62774 [ run ] triggered by Bot. Commit: f2869b8 Link to invocation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants