Skip to content

[None][perf] autotuner: share one CUDA graph pool per tuning pass - #21419

Merged
hyukn merged 2 commits into
NVIDIA:mainfrom
xguannv:user/xguan/autotuner-shared-graph-pool
Nov 4, 2026
Merged

hyukn merged 2 commits into
NVIDIA:mainfrom
xguannv:user/xguan/autotuner-shared-graph-pool

Conversation

@xguannv

@xguannv xguannv commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Dev Engineer Review

  • choose_one() shares a CUDA graph memory pool across profiling captures in one tuning pass. The pool is cleared when the pass ends.
  • Each capture keeps its own NCCL-window owner. A failed capture abandons its owner and causes later captures to use a fresh pool.
  • No public API changes or unrelated scope changes are reported. Performance measurements are author-reported and not independently verified here.
  • Current review finding counts are unavailable.

QA Engineer Review

  • Modified tests/unittest/_torch/misc/test_autotuner.py. The added tests are test_profiling_captures_share_one_graph_pool_per_tuning_pass and test_failed_profiling_capture_moves_to_a_fresh_graph_pool.
  • The tests cover pool reuse within a tuning pass, pool disposal between passes, per-capture owner release, and recovery with a fresh pool after capture failure.
  • The added test cases are not listed in the inspected CI or manual-QA lists. The CI list includes a different selector from the same file: test_autotuner_distributed_strategy.
  • Coverage verdict: sufficient for the shared-pool lifecycle and failure-recovery behavior. The author reports 98 tests passed on GB300 on a branch based on main; testing on this PR’s base was not done.

Per-File QA Perspective

  • tensorrt_llm/_torch/autotuner.py: Verify that captures share a pool only within one choose_one() pass, that the pool is cleared after the pass, and that a failed capture leads to a fresh pool without changing per-capture NCCL-window owner handling.
  • tests/unittest/_torch/misc/test_autotuner.py: Tests shared-pool lifecycle and recovery after capture failure. The added test cases are not listed in CI or manual-QA lists; the CI list includes a different selector from this file.

Description

During autotuning, each tactic's profiling capture used a new CUDA graph pool (torch.cuda.graph_pool_handle()) and reset the graph right after the measurement. With expandable_segments, the reset unmaps the pool's pages, so the next capture maps them again, once per tactic and profile.

The captures of one choose_one() tuning pass now share one torch.cuda.MemPool, which keeps the freed blocks mapped for the next capture. The pool is dropped when the pass ends. It is not kept across passes because the warmup forwards between them would otherwise see its memory on top of their own peak. Each capture still gets and releases its own NCCL-window owner, and a failed capture abandons its owner and moves the rest of the pass to a new pool.

Measurements:

  • GB300, expandable segments, capture + replay + reset of a graph with a 1.5 GiB output: 13 ms per capture with a new pool each time, 0.13 ms with one shared pool. Over 50 captures, num_device_alloc goes from 50 to 1. Dropping the shared pool returns reserved memory to 0; the old code kept the last pool's 1.5 GiB until the next capture.

  • Rubin (SM107), Kimi K3 disaggregated context workers (16 ranks; before and after are in different allocations):

    rank 0, inside the autotune window before after
    autotune window 1535 s 771 s
    VMM driver time 926 s 158 s
    cuMemCreate calls 495,210 153,927

Test Coverage

  • tests/unittest/_torch/misc/test_autotuner.py:
    • test_profiling_captures_share_one_graph_pool_per_tuning_pass: all captures of a tuning pass use one pool, and the next pass uses another.
    • test_failed_profiling_capture_moves_to_a_fresh_graph_pool: after a failed capture, the rest of the pass uses a fresh pool.
  • Ran on GB300 on a branch based on main from 2026-10-28: test_autotuner.py + test_nccl_window_graph.py 98 passed. With the old autotuner.py, both new tests fail on their assertions (for example, 24 captures in 24 pools). Not yet run on this base; CI will cover it.

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.

…s's profiling captures

Each profiling capture used a new graph pool and reset it right after the
measurement. With expandable segments the reset unmaps the pool's pages,
so the next capture maps them again, once per tactic and profile. The
captures of one choose_one() tuning pass now share one torch.cuda.MemPool,
which keeps the freed blocks mapped for the next capture. The pool is
dropped when the pass ends, so its memory is not held across forward
passes. Each capture still gets and releases its own NCCL-window owner,
and a failed capture abandons its owner and moves the rest of the pass to
a new pool.

Tests: one pool per tuning pass and a new pool per pass; a failed capture
moves the rest of the pass to a fresh pool.

Signed-off-by: Xin Guan <[email protected]>
@xguannv
xguannv requested a review from a team as a code owner November 2, 2026 07:28
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

AutoTuner shares a CUDA graph memory pool across captures in a profiling pass. It clears the shared pool when the outermost profiling scope exits or when a capture fails. Tests cover pool reuse and capture failure handling.

Changes

Profiling graph-pool lifecycle

Layer / File(s) Summary
Manage and use the profiling pool
tensorrt_llm/_torch/autotuner.py, tests/unittest/_torch/misc/test_autotuner.py
AutoTuner lazily creates a shared pool for captures within a profiling pass. It uses fresh pools outside the scope and clears the shared reference after a capture failure or outermost scope exit. Tests check pool reuse, owner release, and failure handling.

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

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant AutoTuner
  participant ProfilingPool
  participant GraphCapture
  AutoTuner->>ProfilingPool: Enter profiling scope
  AutoTuner->>ProfilingPool: Get shared pool handle
  ProfilingPool-->>AutoTuner: Return pool handle
  AutoTuner->>GraphCapture: Capture graph with pool handle
  alt Capture succeeds
    GraphCapture-->>AutoTuner: Release graph owner
  else Capture fails
    GraphCapture-->>AutoTuner: Abandon graph owner
    GraphCapture->>ProfilingPool: Clear shared pool reference
  end
  AutoTuner->>ProfilingPool: Clear pool at outermost scope exit
Loading

Suggested reviewers: schetlur-nv

Merge Risk: Minimal · up to 6331d

The change shares profiling memory within a tuning pass; no material merge-blocking risk was established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the performance change: sharing one CUDA graph pool across an autotuning pass. It follows the required ticket, type, and summary format.
Description check Passed The description explains the problem, solution, performance impact, memory behavior, test coverage, and validation results. It includes the required sections and completed checklist acknowledgment.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between a914c2e and 6331d41.

Files selected for processing: 1
  • tensorrt_llm/_torch/autotuner.py

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

@svc-trtllm-gh-bot svc-trtllm-gh-bot added the Community want to contribute PRs initiated from Community label Nov 2, 2026

@JunyiXu-nv JunyiXu-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.

Runtime part LGTM: the shared pool is reset between captures, dropped after the pass and after a failed capture, and the default path is unchanged.

@github-actions

github-actions Bot commented Nov 3, 2026

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.

@xguannv

xguannv commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82203 [ run ] triggered by Bot. Commit: 6331d41 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82203 [ run ] completed with state SUCCESS. Commit: 6331d41
/LLM/main/L0_MergeRequest_PR pipeline #67832 completed with status: 'UNSTABLE'

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

Link to invocation

@xguannv

xguannv commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82378 [ run ] triggered by Bot. Commit: 6331d41 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82378 [ run ] completed with state SUCCESS. Commit: 6331d41
/LLM/main/L0_MergeRequest_PR pipeline #67995 completed with status: 'SUCCESS'

CI Report

Link to invocation

@hyukn
hyukn merged commit b98a7e0 into NVIDIA:main Nov 4, 2026
@xguannv xguannv changed the title [None][perf] autotuner: share one CUDA graph pool across a tuning pas… [None][perf] autotuner: share one CUDA graph pool across a tuning pass's profiling captures Nov 4, 2026
@xguannv xguannv changed the title [None][perf] autotuner: share one CUDA graph pool across a tuning pass's profiling captures [None][perf] autotuner: share one CUDA graph pool per tuning pass Nov 4, 2026
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.

6 participants