Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/185760
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (5 Unrelated Failures)As of commit c041a2c with merge base 757703a ( FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review these changes |
|
Claude finished @jansel's task in 1m 43s —— View job Code Review: Skip cudagraphs for kernel-free inductor graphs
Overall: This looks good. The approach is well-motivated — checking at the scheduler level after codegen is the right narrow point where the kernel/no-kernel distinction is known. The implementation is minimal and correctly placed. Implementation (
|
eellison
left a comment
There was a problem hiding this comment.
is there a reason this wouldnt' be covered by the min_partition size = 1?
|
My agent says the min-partition-size check only runs inside the graph partitioning path ( |
Inductor can lower a CUDA graph that only contains metadata/view work, such as a reshape that remains a view. The non-partition cudagraph path still wrapped that compiled callable, so the first execution attempted to capture a CUDA graph with no kernel launches and emitted the empty CUDA Graph warning.
Fix this by checking the lowered scheduler after codegen and marking cudagraphs disabled when there are no scheduler nodes other than NopKernelSchedulerNode. This uses Inductor's actual lowered work instead of guessing from FX ops, so reshape can still cudagraph when it really lowers to compute, while pure view graphs skip capture cleanly.
I considered suppressing the CUDA warning or deciding from the FX graph, but warning suppression could hide real capture problems and FX-level checks do not know whether reshape becomes a view or a clone. The scheduler check is the narrow point where the kernel/no-kernel distinction is available.
Benchmark Results:
Simulated previous behavior by monkeypatching the new no-kernel check to return True for a CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False. Median first 3 calls: before 0.052442s, after 0.045516s. Median steady 5000 calls: before 0.242688s, after 0.091426s. Before counters: {'cudagraph_recorded_non_static_inputs': 1}; after counters: {'cudagraph_skips': 1}.
Test Plan:
python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_skips_cudagraphs
lintrunner -a
Manual repro: CUDA reshape-only graph emitted 0 empty CUDA Graph warnings and counters {'cudagraph_skips': 1}.
Manual sanity: CUDA x + 1 graph still recorded cudagraphs with counters {'cudagraph_recorded_non_static_inputs': 1}.
Fixes #149653
Generated by my agent
ghstack-source-id: fbcb12c
Pull-Request: #185760
eellison
left a comment
There was a problem hiding this comment.
Looks good, although, can we please unify the num kernel logic ? reuse the existing code ?
|
Agent, address that comment above. |
Inductor can lower a CUDA graph that only contains metadata/view work, such as a reshape that remains a view. The non-partition cudagraph path still wrapped that compiled callable, so the first execution attempted to capture a CUDA graph with no kernel launches and emitted the empty CUDA Graph warning.
Fix this by checking the lowered scheduler after codegen and marking cudagraphs disabled when the scheduler reports zero kernel nodes. The kernel-node count is shared with the graph-partition min-size logic, so both paths use the same definition of real scheduler kernel work while excluding NopKernelSchedulerNode. This uses Inductor's actual lowered work instead of guessing from FX ops, so reshape can still cudagraph when it really lowers to compute, while pure view graphs skip capture cleanly.
I considered suppressing the CUDA warning or deciding from the FX graph, but warning suppression could hide real capture problems and FX-level checks do not know whether reshape becomes a view or a clone. The scheduler check is the narrow point where the kernel/no-kernel distinction is available.
Benchmark Results:
Simulated previous behavior by monkeypatching the new no-kernel check to return True for a CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False. Median first 3 calls: before 0.052442s, after 0.045516s. Median steady 5000 calls: before 0.242688s, after 0.091426s. Before counters: {'cudagraph_recorded_non_static_inputs': 1}; after counters: {'cudagraph_skips': 1}.
Test Plan:
python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_skips_cudagraphs
python test/inductor/test_cudagraph_trees.py -k test_cudagraph_min_partition_size_skip_small
python test/inductor/test_cudagraph_trees.py -k test_cudagraph_min_partition_size_allow_large
lintrunner -a
Manual repro: CUDA reshape-only graph emitted 0 empty CUDA Graph warnings and counters {'cudagraph_skips': 1}.
Manual sanity: CUDA x + 1 graph still recorded cudagraphs with counters {'cudagraph_recorded_non_static_inputs': 1}.
Fixes #149653
Generated by my agent
ghstack-source-id: b78ffd1
Pull-Request: #185760
|
My agent says I addressed the kernel-count unification feedback by moving the NopKernelSchedulerNode-excluding count into Scheduler.count_kernel_nodes and reusing it from both the whole-graph cudagraph skip and the graph-partition min-size check. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (mps, 1, 1, macos-m2-15) Details for Dev Infra teamRaised by workflow job |
|
@claude are those CI failures related to this PR? |
|
Claude finished @jansel's task in 4m 22s —— View job CI Failure AnalysisNo, none of the CI failures are related to this PR. This PR only touches three files, all in the Inductor cudagraph/scheduler path:
The reported failures are in unrelated areas:
The three "broken trunk" failures are explicitly flagged by Dr. CI as failing on the merge base (rebasing onto Recommendation: Rebase onto |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 4 checks: pull / linux-jammy-aarch64-py3.10 / test-osdc (default, 5, 5, mt-l-arm64g4-16-62), torchtitan-test / torchtitan-x-pytorch-test / test-osdc (torchtitan_features_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8), trunk / linux-jammy-aarch64-py3.10 / test-osdc (default, 4, 5, mt-l-arm64g3-16-62), trunk / macos-py3-arm64 / test (mps, 1, 1, macos-m2-15) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
Agent address the following and respond with a confidence level on how safe to reland this is. -- Revert Analysis: "Skip cudagraphs for kernel-free inductor graphs" (PR #185760 / D108074417)SummaryPR #185760 was imported as D108074417 and subsequently reverted (commit The ChangeThe PR added a post-codegen scheduler check in The intent was to avoid capturing an empty CUDA graph (which triggers a "CUDA Graph is empty" warning) for graphs that only contain view operations. Key code added (in if (
cudagraphs
and not V.graph.disable_cudagraphs_reason
and not config.graph_partition
and not _graph_has_kernel_invocations(graph)
):
V.graph.disable_cudagraphs_reason = "skipping cudagraphs for kernel-free graph"
counters["inductor"]["cudagraph_skips"] += 1Where Failing TestTest: Error: The test expects both compiled functions to participate in the cudagraph tree, but the kernel-free function is incorrectly excluded, breaking cudagraph tree assertions. Root CauseThe test does the following: class Mod(torch.nn.Linear):
def forward(self, x):
return self.weight.T @ x, self.weight.T, self.weight[0:4]
m = Mod(10, 10).cuda()
@torch.compile(mode="reduce-overhead")
def foo(mod, x):
return mod(x) # has matmul kernel + view ops
@torch.compile(mode="reduce-overhead")
def foo2(x):
return x[2:] # ONLY a slice/view operation — NO kernel
for _ in range(3):
torch.compiler.cudagraph_mark_step_begin()
out1, alias_1, alias_2 = foo(m, x)
out2 = foo2(out1) # <-- this graph is kernel-free
out2.sum().backward()
# Asserts about cudagraph tree structure:
node = self.curr_node()
first_node = next(node._path_from_root)
self.assertFalse(first_node.unaliased_in_all_paths[0])What goes wrong:
Key config context: In fbcode, Suggested FixThe fix should not completely disable cudagraphs for kernel-free graphs. Instead, it should handle the "empty CUDA graph" case within the cudagraph tree mechanism itself. There are several approaches: Option A: Skip only the CUDA graph recording but still participate in the tree (Recommended)Instead of setting # In compile_fx.py, instead of disabling cudagraphs entirely:
if (
cudagraphs
and not V.graph.disable_cudagraphs_reason
and not config.graph_partition
and not _graph_has_kernel_invocations(graph)
):
# Mark as kernel-free but DON'T disable cudagraphs tree participation
V.graph.kernel_free_cudagraph = True
counters["inductor"]["cudagraph_skips"] += 1Then in the cudagraph tree's recording logic, check Option B: Only skip for standalone graphs (not in a tree sequence)Only apply the skip when the function is known to be standalone (no other cudagraph functions before/after it in the same step): if (
cudagraphs
and not V.graph.disable_cudagraphs_reason
and not config.graph_partition
and not _graph_has_kernel_invocations(graph)
# Only skip if this is a standalone graph, not part of a tree sequence
and not V.graph.has_cudagraph_tree_inputs # needs new tracking
):
V.graph.disable_cudagraphs_reason = "skipping cudagraphs for kernel-free graph"However, this is harder to implement since tree membership isn't known at compile time. Option C: Suppress the warning instead of disabling cudagraphsThe simplest fix — suppress the "CUDA Graph is empty" warning for intentionally kernel-free graphs rather than disabling cudagraphs entirely: if (
cudagraphs
and not V.graph.disable_cudagraphs_reason
and not config.graph_partition
and not _graph_has_kernel_invocations(graph)
):
# Flag to suppress the empty-graph warning but still use cudagraph tree
V.graph.suppress_empty_cudagraph_warning = True
counters["inductor"]["cudagraph_skips"] += 1This is the least invasive but doesn't save the (minor) overhead of recording an empty graph. Option D: Move the check to runtime in the cudagraph treeCheck at runtime (during cudagraph tree execution) whether the function is standalone vs. part of a sequence. If standalone and kernel-free, skip recording. If part of a sequence, still participate in the tree. Additional Context
References
|
Inductor can lower a CUDA graph that only contains metadata/view work, such as a reshape that remains a view. The non-partition cudagraph path still wrapped that compiled callable, so the first execution attempted to capture a CUDA graph with no kernel launches and emitted the empty CUDA Graph warning.
Fix this by checking the lowered scheduler after codegen and marking cudagraphs disabled when there are no scheduler nodes other than NopKernelSchedulerNode. This uses Inductor's actual lowered work instead of guessing from FX ops, so reshape can still cudagraph when it really lowers to compute, while pure view graphs skip capture cleanly.
I considered suppressing the CUDA warning or deciding from the FX graph, but warning suppression could hide real capture problems and FX-level checks do not know whether reshape becomes a view or a clone. The scheduler check is the narrow point where the kernel/no-kernel distinction is available.
Benchmark Results:
Simulated previous behavior by monkeypatching the new no-kernel check to return True for a CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False. Median first 3 calls: before 0.052442s, after 0.045516s. Median steady 5000 calls: before 0.242688s, after 0.091426s. Before counters: {'cudagraph_recorded_non_static_inputs': 1}; after counters: {'cudagraph_skips': 1}.
Test Plan:
python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_skips_cudagraphs
lintrunner -a
Manual repro: CUDA reshape-only graph emitted 0 empty CUDA Graph warnings and counters {'cudagraph_skips': 1}.
Manual sanity: CUDA x + 1 graph still recorded cudagraphs with counters {'cudagraph_recorded_non_static_inputs': 1}.
Fixes pytorch#149653
Generated by my agent
Pull Request resolved: pytorch#185760
Approved by: https://github.com/eellison
…)" This reverts commit b1e3edd. Reverted pytorch#185760 on behalf of https://github.com/wdvr due to reverting due to failing signal on D108074417 - discussed with author ([comment](pytorch#185760 (comment)))
Inductor can lower a CUDA graph that only contains scheduler nop nodes. A pure view graph such as reshape or slice does not launch CUDA kernels, so recording it as a CUDA graph emits the empty CUDA Graph warning. The original fix disabled cudagraphs for these lowered graphs entirely, but that was too broad for cudagraph trees: a kernel-free compiled function can still create aliases of cudagraph-managed tensors, and removing it from the tree breaks alias/lifetime bookkeeping for later nodes. Fix this by carrying a kernel_free_cudagraph bit from GraphLowering into cudagraph wrapping. For non-tree cudagraph wrapping, kernel-free callables skip CUDA graph capture and run directly. For cudagraph trees, the callable still becomes a tree node, but CUDAGraphNode does not allocate or replay a torch.cuda.CUDAGraph for it. Instead, the first run executes under the cudagraph memory-pool manager and records output metadata with the existing _add_first_outputs alias/liveness path, so view aliases and allocation-only outputs remain tracked by the tree without entering an empty CUDA graph capture. The flag is also threaded through graph-partition post-compile so zero-kernel partitions use the same path. The alternatives were either suppressing the warning around empty captures or disabling cudagraph tree participation. Suppression still records an empty CUDA graph and hides real capture issues; disabling tree participation regresses alias tracking. Keeping an explicit kernel-free tree node is the narrow fix because it avoids empty capture while preserving the tree's ownership and lifetime model. Test Plan: python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_suppresses_empty_warning python test/inductor/test_cudagraph_trees.py -k test_kernel_free_allocation_uses_cudagraph_pool python test/inductor/test_cudagraph_trees.py -k test_aliasing_static_ref python test/inductor/test_cudagraph_trees.py -k test_cudagraph_min_partition_size_skip_small python test/inductor/test_cudagraph_trees.py -k test_cudagraph_min_partition_size_allow_large lintrunner -a Manual repro: CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False emitted 0 empty CUDA Graph warnings, produced correct output, and kept a cudagraph manager for tree bookkeeping. Manual regression: allocation-only torch.empty_like graph emitted 0 empty CUDA Graph warnings with graph_partition=False and graph_partition=True while triton.slow_path_cudagraph_asserts=True. Attempted: python test/test_cuda.py -k test_graph_warn_if_has_zero_nodes. This local environment failed during import before test selection because torchvision was built for CUDA 13.0 while PyTorch was built for CUDA 12.8. Fixes #149653 Generated by my agent ghstack-source-id: 201ad90 Pull-Request: #185760
|
My agent says I addressed the revert by keeping kernel-free compiled functions in cudagraph tree bookkeeping without recording an empty torch.cuda.CUDAGraph. The updated path records output metadata and alias/lifetime state under the cudagraph memory-pool manager, threads the flag through partition wrapping, and adds regressions for the no-partition alias case plus allocation-only kernel-free graphs with slow pool assertions. Confidence to reland: medium-high, because the reverted aliasing case and the fresh-allocation pool case now pass locally; remaining risk is normal CI coverage across internal configurations. |
|
@claude review these changes |
|
Claude finished @jansel's task in 6m 34s —— View job Code Review: reland of "Skip cudagraphs for kernel-free inductor graphs"
This reland correctly fixes the root cause of the revert, and I'd rate it high confidence to reland. What changed vs. the reverted versionThe original PR set This version implements Option A from the revert analysis: it keeps the node in the tree but skips only the CUDA graph capture/replay. A new
This is the right call. Because allocations during the eager run still land in Correctness review — no blocking issues
Test coverageThe exact regression scenario is now pinned: Minor / non-blocking observations
Reland confidenceHigh. The fix attacks the documented root cause directly (tree participation preserved instead of full disable), and the precise failing configuration ( |
#185760)" (#187347) Revert "Skip cudagraphs for kernel-free inductor graphs (#185760)" This reverts commit b1e3edd. Reverted #185760 on behalf of https://github.com/wdvr due to reverting due to failing signal on D108074417 - discussed with author ([comment](#185760 (comment))) (cherry picked from commit 82a2694) Co-authored-by: PyTorch MergeBot <[email protected]>
|
My agent says I triaged the current Dr. CI failures. TorchBench training failed before Inductor with eager_two_runs_differ, and the MI350 ROCm failures are in Triton autotune/static launcher/opinfo paths unrelated to the kernel-free cudagraph tree changes. I reran the failed trunk, inductor, and torchtitan-test jobs for fresh signal. |
|
@claude based on the thread above is this safe to reland? Give a confidence level. |
|
Claude finished @jansel's task in 1m 11s —— View job Reland safety assessment
Confidence to reland: High (~85%). Why the revert is actually fixedThe revert was caused by This reland switches to Option A from the revert analysis: it no longer disables cudagraphs. Instead it threads a
This is the correct mechanism: allocations during the eager run land in The exact failing config is now pinned: What gives me confidence
Residual risk (the ~15%)
RecommendationReland, but make the final merge gate an explicit full run of |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Inductor can lower a CUDA graph that only contains metadata/view work, such as a reshape that remains a view. The non-partition cudagraph path still wrapped that compiled callable, so the first execution attempted to capture a CUDA graph with no kernel launches and emitted the empty CUDA Graph warning.
Fix this by checking the lowered scheduler after codegen and marking cudagraphs disabled when there are no scheduler nodes other than NopKernelSchedulerNode. This uses Inductor's actual lowered work instead of guessing from FX ops, so reshape can still cudagraph when it really lowers to compute, while pure view graphs skip capture cleanly.
I considered suppressing the CUDA warning or deciding from the FX graph, but warning suppression could hide real capture problems and FX-level checks do not know whether reshape becomes a view or a clone. The scheduler check is the narrow point where the kernel/no-kernel distinction is available.
Benchmark Results:
Simulated previous behavior by monkeypatching the new no-kernel check to return True for a CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False. Median first 3 calls: before 0.052442s, after 0.045516s. Median steady 5000 calls: before 0.242688s, after 0.091426s. Before counters: {'cudagraph_recorded_non_static_inputs': 1}; after counters: {'cudagraph_skips': 1}.
Test Plan:
python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_skips_cudagraphs
lintrunner -a
Manual repro: CUDA reshape-only graph emitted 0 empty CUDA Graph warnings and counters {'cudagraph_skips': 1}.
Manual sanity: CUDA x + 1 graph still recorded cudagraphs with counters {'cudagraph_recorded_non_static_inputs': 1}.
Fixes pytorch#149653
Generated by my agent
Pull Request resolved: pytorch#185760
Approved by: https://github.com/eellison
…)" This reverts commit b1e3edd. Reverted pytorch#185760 on behalf of https://github.com/wdvr due to reverting due to failing signal on D108074417 - discussed with author ([comment](pytorch#185760 (comment)))
Inductor can lower a CUDA graph that only contains metadata/view work, such as a reshape that remains a view. The non-partition cudagraph path still wrapped that compiled callable, so the first execution attempted to capture a CUDA graph with no kernel launches and emitted the empty CUDA Graph warning.
Fix this by checking the lowered scheduler after codegen and marking cudagraphs disabled when there are no scheduler nodes other than NopKernelSchedulerNode. This uses Inductor's actual lowered work instead of guessing from FX ops, so reshape can still cudagraph when it really lowers to compute, while pure view graphs skip capture cleanly.
I considered suppressing the CUDA warning or deciding from the FX graph, but warning suppression could hide real capture problems and FX-level checks do not know whether reshape becomes a view or a clone. The scheduler check is the narrow point where the kernel/no-kernel distinction is available.
Benchmark Results:
Simulated previous behavior by monkeypatching the new no-kernel check to return True for a CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False. Median first 3 calls: before 0.052442s, after 0.045516s. Median steady 5000 calls: before 0.242688s, after 0.091426s. Before counters: {'cudagraph_recorded_non_static_inputs': 1}; after counters: {'cudagraph_skips': 1}.
Test Plan:
python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_skips_cudagraphs
lintrunner -a
Manual repro: CUDA reshape-only graph emitted 0 empty CUDA Graph warnings and counters {'cudagraph_skips': 1}.
Manual sanity: CUDA x + 1 graph still recorded cudagraphs with counters {'cudagraph_recorded_non_static_inputs': 1}.
Fixes pytorch#149653
Generated by my agent
Pull Request resolved: pytorch#185760
Approved by: https://github.com/eellison
Inductor can lower a CUDA graph that only contains metadata/view work, such as a reshape that remains a view. The non-partition cudagraph path still wrapped that compiled callable, so the first execution attempted to capture a CUDA graph with no kernel launches and emitted the empty CUDA Graph warning.
Fix this by checking the lowered scheduler after codegen and marking cudagraphs disabled when there are no scheduler nodes other than NopKernelSchedulerNode. This uses Inductor's actual lowered work instead of guessing from FX ops, so reshape can still cudagraph when it really lowers to compute, while pure view graphs skip capture cleanly.
I considered suppressing the CUDA warning or deciding from the FX graph, but warning suppression could hide real capture problems and FX-level checks do not know whether reshape becomes a view or a clone. The scheduler check is the narrow point where the kernel/no-kernel distinction is available.
Benchmark Results:
Simulated previous behavior by monkeypatching the new no-kernel check to return True for a CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False. Median first 3 calls: before 0.052442s, after 0.045516s. Median steady 5000 calls: before 0.242688s, after 0.091426s. Before counters: {'cudagraph_recorded_non_static_inputs': 1}; after counters: {'cudagraph_skips': 1}.
Test Plan:
python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_skips_cudagraphs
lintrunner -a
Manual repro: CUDA reshape-only graph emitted 0 empty CUDA Graph warnings and counters {'cudagraph_skips': 1}.
Manual sanity: CUDA x + 1 graph still recorded cudagraphs with counters {'cudagraph_recorded_non_static_inputs': 1}.
Fixes pytorch#149653
Generated by my agent
Pull Request resolved: pytorch#185760
Approved by: https://github.com/eellison
…)" This reverts commit b1e3edd. Reverted pytorch#185760 on behalf of https://github.com/wdvr due to reverting due to failing signal on D108074417 - discussed with author ([comment](pytorch#185760 (comment)))
Inductor can lower a CUDA graph that only contains metadata/view work, such as a reshape that remains a view. The non-partition cudagraph path still wrapped that compiled callable, so the first execution attempted to capture a CUDA graph with no kernel launches and emitted the empty CUDA Graph warning.
Fix this by checking the lowered scheduler after codegen and marking cudagraphs disabled when there are no scheduler nodes other than NopKernelSchedulerNode. This uses Inductor's actual lowered work instead of guessing from FX ops, so reshape can still cudagraph when it really lowers to compute, while pure view graphs skip capture cleanly.
I considered suppressing the CUDA warning or deciding from the FX graph, but warning suppression could hide real capture problems and FX-level checks do not know whether reshape becomes a view or a clone. The scheduler check is the narrow point where the kernel/no-kernel distinction is available.
Benchmark Results:
Simulated previous behavior by monkeypatching the new no-kernel check to return True for a CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False. Median first 3 calls: before 0.052442s, after 0.045516s. Median steady 5000 calls: before 0.242688s, after 0.091426s. Before counters: {'cudagraph_recorded_non_static_inputs': 1}; after counters: {'cudagraph_skips': 1}.
Test Plan:
python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_skips_cudagraphs
lintrunner -a
Manual repro: CUDA reshape-only graph emitted 0 empty CUDA Graph warnings and counters {'cudagraph_skips': 1}.
Manual sanity: CUDA x + 1 graph still recorded cudagraphs with counters {'cudagraph_recorded_non_static_inputs': 1}.
Fixes pytorch#149653
Generated by my agent
Pull Request resolved: pytorch#185760
Approved by: https://github.com/eellison
Stack from ghstack (oldest at bottom):
Inductor can lower a CUDA graph that only contains metadata/view work, such as a reshape that remains a view. The non-partition cudagraph path still wrapped that compiled callable, so the first execution attempted to capture a CUDA graph with no kernel launches and emitted the empty CUDA Graph warning.
Fix this by checking the lowered scheduler after codegen and marking cudagraphs disabled when there are no scheduler nodes other than NopKernelSchedulerNode. This uses Inductor's actual lowered work instead of guessing from FX ops, so reshape can still cudagraph when it really lowers to compute, while pure view graphs skip capture cleanly.
I considered suppressing the CUDA warning or deciding from the FX graph, but warning suppression could hide real capture problems and FX-level checks do not know whether reshape becomes a view or a clone. The scheduler check is the narrow point where the kernel/no-kernel distinction is available.
Benchmark Results:
Simulated previous behavior by monkeypatching the new no-kernel check to return True for a CUDA reshape-only graph with triton.cudagraphs=True and graph_partition=False. Median first 3 calls: before 0.052442s, after 0.045516s. Median steady 5000 calls: before 0.242688s, after 0.091426s. Before counters: {'cudagraph_recorded_non_static_inputs': 1}; after counters: {'cudagraph_skips': 1}.
Test Plan:
python test/inductor/test_cudagraph_trees.py -k test_view_only_cuda_graph_skips_cudagraphs
lintrunner -a
Manual repro: CUDA reshape-only graph emitted 0 empty CUDA Graph warnings and counters {'cudagraph_skips': 1}.
Manual sanity: CUDA x + 1 graph still recorded cudagraphs with counters {'cudagraph_recorded_non_static_inputs': 1}.
Fixes #149653
Generated by my agent
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo