Repository navigation
Fix: raise RuntimeError when cudagraph partitions are empty - #176619
mhusnain-tech wants to merge 25 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/176619
Note: Links to docs will display an error until the docs builds have been completed. ❌ 20 New Failures, 3 Cancelled Jobs, 2 Unrelated Failures, 5 Unclassified FailuresAs of commit 3e2b1ec with merge base 88f350b ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
CANCELLED JOBS - The following jobs were cancelled. Please retry:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
kshitij12345
left a comment
There was a problem hiding this comment.
I think we should add a test to make sure this isn't regressed.
|
Hi @kshitij12345, thank you for the review. I agree that adding a regression test is important. I am working on adding a test case to verify that the RuntimeError is correctly raised when partitions are empty. I will update the PR shortly. |
|
Hi @kshitij12345, I have successfully added the regression test to this PR in test/inductor/test_cudagraph_trees.py. It verifies the fix for issue #176611 by ensuring a RuntimeError is raised when no graphable partitions are found with cudagraph_or_error=True. Ready for review! |
|
Hi @BoyuanFeng, I have addressed your comments and marked the conversations as resolved. I've also updated the implementation in output_code.py to include the specific error message as discussed. Could you please take another look at the latest commits? Thanks! |
|
Hi @BoyuanFeng, just following up to see if you've had a chance to look at the latest updates. Let me know if any further changes are needed. Thanks! |
|
@pytorchbot label "topic: not user facing" |
|
Hi @kshitij12345, @BoyuanFeng — just a gentle follow-up on this. I have addressed all the feedback, added the requested regression tests in test_cudagraph_trees.py, and resolved the conversations. Could one of the maintainers please approve the CI to run? It’s currently blocked awaiting approval for the latest commits. I've also added the missing label. Thanks for your time! |
|
CC: @jansel While we’re finalizing the divisibility logic in #177156, I wanted to highlight this Inductor fix as well. It addresses a
Since this falls under Inductor stability, I'd appreciate your eyes on it when you have a moment to move this toward a merge. Thanks! |
|
CC: @jansel @BoyuanFeng @kshitij12345 Thanks for the reviews and for triggering the CI tests. I have addressed the linting errors and the undefined reference identified in the recent test runs. Specifically, I have:
The latest commits ( Thanks! |
| mock_post_compile.return_value = [] | ||
|
|
||
| def fn(x): | ||
| return x * 2 |
There was a problem hiding this comment.
Instead of patching, you can use
def f(x):
return torch.cond(x.sum() > 0, lambda x: x * 2, lambda x: x * 3, (x,))which leads to cudagraph partition.
| log_cudagraph_skip_and_bump_counter( | ||
| "skipping cudagraphs as len(compiled_graph.partition_maps) == 0" | ||
| ) | ||
| if V.config.inductor.cudagraph_or_error: |
There was a problem hiding this comment.
Shouldn't we hit either if or elif or else and error before we hit the runtime error here? I think this branch is not required.
|
Hi @kshitij12345, I've refactored the code to remove the redundant branches and the monkey patching in tests as suggested. I'm now using torch.cond to trigger the partition error naturally. Ready for another look! |
| obs.op_outputs[aten.rand.default][2], | ||
| ) | ||
|
|
||
| def test_cudagraph_empty_partition_raises_error(self, mock_post_compile): |
There was a problem hiding this comment.
mock_post_compile is unused.
| maybe_handle_backward_generation(compiled_graph, boxed_forward_device_index) | ||
| # Raise an error if no CUDA graphable partitions are found and the user | ||
| # has explicitly enabled the 'cudagraph_or_error' configuration. | ||
| if config.inductor.cudagraph_or_error and len(compiled_graph.partition_maps) == 0: |
There was a problem hiding this comment.
We should use log_cudagraph_skip_and_bump_counter (as it does some booking keeping about cudagraph related counters) and catch the relevant error in the test (probably a torch._inductor.exc.InductorError is raised).
I think the original messages were helpful in pointing the reason
# Log reasons and raise error if cudagraph_or_error=True
if cudagraph_fail_reasons:
log_cudagraph_skip_and_bump_counter(f"skipping cudagraphs due to {cudagraph_fail_reasons=}")
elif compiled_graph.partition_maps is None:
log_cudagraph_skip_and_bump_counter("skipping cudagraphs as compiled_graph.partition_maps is None")
else:
log_cudagraph_skip_and_bump_counter("skipping cudagraphs as len(compiled_graph.partition_maps) == 0")Ref:
pytorch/torch/_inductor/cudagraph_utils.py
Lines 206 to 215 in d3c36f0
|
Thanks for the detailed feedback and the reference to log_cudagraph_skip_and_bump_counter. I have refactored the PR with the following changes:
All tests are passing locally. Ready for another look! |
Resolves style and formatting violations reported by the linter in output_code.py to maintain consistency
Add @unittest.skipUnless decorator to test_cudagraph_empty_partition_raises_error to skip the test when CUDA is not available, fixing CI failures on non-GPU machines.
…re empty When compiled_graph.partition_maps is empty and triton.cudagraph_or_error is enabled, raise RuntimeError instead of silently skipping cudagraphs. This ensures users get explicit feedback when cudagraph compilation fails due to empty partitions.
Removed RuntimeError for empty partition_maps in cudagraphs.
Replace torch.cond-based reproducer, which triggers the existing control-flow cudagraph rejection path, with a cudagraph_unsafe custom op that exercises the empty partition_maps branch directly.
|
Successfully rebased |
af63694 to
54e91b9
Compare
…176619) This commit ensures that 'log_cudagraph_skip_and_bump_counter' is called when 'cudagraph_partition_post_compile' returns early due to empty partitions. This prevents silent failures when 'cudagraph_or_error=True' is set, ensuring the expected RuntimeError is raised instead of silently falling back to eager execution. Verified using the reproduction script in issue pytorch#176611. Pull Request resolved: pytorch#176619 Approved by: https://github.com/kshitij12345, https://github.com/BoyuanFeng, https://github.com/jansel
…ytorch#176619)" This reverts commit 7d2985a. Reverted pytorch#176619 on behalf of https://github.com/jeffdaily due to broke cuda and rocm while they were in unstable state; test/inductor/test_cudagraph_trees.py::TestSAC::test_cudagraph_empty_partition_raises_error [GH job link](https://github.com/pytorch/pytorch/actions/runs/25483802051/job/74779603743) [HUD commit link](https://hud.pytorch.org/pytorch/pytorch/commit/7d2985aa3f07125f06df1d7e81d4e4f049b8d0cb) ([comment](pytorch#176619 (comment)))
Removed unnecessary blank lines in the test for CUDA graph.
|
@claude review these changes, have all the prior comments been fixed? |
|
Claude finished @jansel's task in 32m 34s —— View job Yes — all prior review comments have been substantively addressed, and the current trunk/lint CI failures are unrelated infrastructure noise, but the review found three small test-robustness issues worth fixing (most notably the test silently depends on PR Review: #176619 — full detailsPrior Comments Status
Current CI Failures — all unrelated
Testing — remaining issues
RecommendationRequest Changes (minor) — the substance of every prior review comment is resolved and the fix itself (
|
|
@claude review these changes again |
|
Claude finished @jansel's task in 26m 43s —— View job Re-reviewed: all four items from my last pass are addressed except three test cleanups (misplaced class, dead decorator, global PR Review: #176619 — full detailsSummaryThe PR makes Status of prior review comments
Code Quality
log_cudagraph_skip_and_bump_counter(
f"skipping cudagraphs due to {cudagraph_fail_reasons=}"
)This renders the literal variable name into a user-visible warning — This branch is also not just a formatting concern. It is reachable when Testing
CINothing on the latest commit RecommendationRequest Changes (minor). The core fix is correct and every substantive prior comment is resolved. Blocking items are the three unaddressed test cleanups (wrong class, dead decorator, un-scoped
|
…s=None branches; only raise on empty partitions
…raising behavior for unrelated skip branches
…176619) This commit ensures that 'log_cudagraph_skip_and_bump_counter' is called when 'cudagraph_partition_post_compile' returns early due to empty partitions. This prevents silent failures when 'cudagraph_or_error=True' is set, ensuring the expected RuntimeError is raised instead of silently falling back to eager execution. Verified using the reproduction script in issue pytorch#176611. Pull Request resolved: pytorch#176619 Approved by: https://github.com/kshitij12345, https://github.com/BoyuanFeng, https://github.com/jansel
…ytorch#176619)" This reverts commit 7d2985a. Reverted pytorch#176619 on behalf of https://github.com/jeffdaily due to broke cuda and rocm while they were in unstable state; test/inductor/test_cudagraph_trees.py::TestSAC::test_cudagraph_empty_partition_raises_error [GH job link](https://github.com/pytorch/pytorch/actions/runs/25483802051/job/74779603743) [HUD commit link](https://hud.pytorch.org/pytorch/pytorch/commit/7d2985aa3f07125f06df1d7e81d4e4f049b8d0cb) ([comment](pytorch#176619 (comment)))
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
This commit ensures that 'log_cudagraph_skip_and_bump_counter' is called when 'cudagraph_partition_post_compile' returns early due to empty partitions.
This prevents silent failures when 'cudagraph_or_error=True' is set, ensuring the expected RuntimeError is raised instead of silently falling back to eager execution. Verified using the reproduction script in issue #176611.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo