Repository navigation
[inductor] Delete the post-fusion reindex retry - #193158
anijain2305 wants to merge 18 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193158
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 5 Unrelated FailuresAs of commit 8d79a45 with merge base 557649f ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…es out When vertical fusion fails, _can_fuse reindexes the pointwise onto the reduction's iteration domain and retries. Reindexing rewrites index expressions, so it can only rescue a fusion that failed because reads and writes of the same buffer were indexed differently. If node2 depends on a buffer node1 never writes, and that buffer is produced between the two nodes, the fusion is illegal whatever the indexing, and the retry rejects it again with "intermediate nodes between node1 & node2". Check that first. Buffer names and the ancestor graph do not change under loop mutation, which is what makes the answer stable across a reindex, so the pre-check is a necessary condition: when it says no, the retried can_fuse_vertical would have said no too. Also roll the reindex back when the retried checks still reject the pair. _try_reindex_pointwise_for_reduction rolls back its own failures, but a rejection that happens after it returns left the pointwise permanently reindexed on behalf of a fusion that never happened. Measured on the backward graph of FairChem UMA, captured as a standalone fx_graph_runnable: reindex attempts 1888 -> 247 apply_loop_reindexing 613 -> 1 possible fusions 107 -> 107 (unchanged) generated kernels 70 -> 70 (identical content hashes) Of the 576 reindexes that graph applied and kept, 560 were rejected afterwards for the topology reason above and none of the 414 distinct pairs involved ever fused. Being honest about the payoff: on that standalone graph this is worth ~10% of the compile, but on the same model compiled end to end it is worth nothing measurable (49.16s vs 49.34s over two interleaved pairs). The pre-check does fire there - 2238 calls, 2065 skips - but in situ those attempts were already exiting early, before the expensive part. fx_graph_runnable compiles the post-grad graph against a fresh ShapeEnv, without the replacements and ranges the real compile has, so statically_known_equals inside the reindex path stops rejecting early and the repro drives the expensive path far more often than production does. The change is kept because skipping work whose outcome is already determined is right on its own terms, not because it made this model faster. Test plan: ``` python test/inductor/test_perf.py python test/inductor/test_loop_ordering.py python test/inductor/test_fused_attention.py ``` test_perf (which asserts memory-traffic expectations and would catch a lost fusion) matches baseline exactly. test_loop_ordering has one pre-existing failure with and without the change. test_fused_attention's sdpa_rewriter failures are order-dependent flakes: a different test fails on each run, and all of them pass when run individually with and without the change. This PR was authored with the assistance of an AI coding agent. ghstack-source-id: 12954a4 Pull-Request: #193158
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
|
@eellison ping for review. |
[ghstack-poisoned]
[ghstack-poisoned]
can_fuse had a second chance for vertical fusion: when the checks failed, it reindexed the pointwise to the reduction's iteration domain and ran them again. This PR originally kept that retry and added a pre-check to skip it when graph topology already ruled the fusion out, because most retries were wasted - 560 of 576 on one model's backward graph. Per review, the retry itself is no longer needed: the case it was added for (#183521) is handled by the original loop-transform path, and that PR's own tests, test_floordiv_broadcast_vertical_fusion and test_floordiv_broadcast_with_preceding_reduction, pass without it. So delete the retry rather than optimize it, and with it the pre-check this PR had added. Note what stays. _try_reindex_pointwise_for_reduction is still live: it is called from shared_data_after_reordering_loop, which is the loop-transform path the review suggested handling this in. config.loop_reindexing_after_fusion still gates that call and the score threshold above it. Only the retry in can_fuse and its pre-check go away. No compile-time claim this time. The workload the earlier numbers came from is nondeterministic - it fabricates random inputs, and three runs of *identical* code produced 96, 100 and 101 triton kernels in 46.24s, 45.76s and 48.40s - so a difference of a second or two between the two variants cannot be resolved on it, and the measurements I took disagreed with each other. The justification here is that the code path is unnecessary, not that removing it is faster. Test plan: ``` python test/inductor/test_loop_ordering.py ``` 124 tests, OK, and the failure set is identical to a run with the retry still in place. Both tests from #183521 pass individually. This PR was authored with the assistance of an AI coding agent. ghstack-source-id: 8b4573a Pull-Request: #193158
can_fuse had a second chance for vertical fusion: when the checks failed, it reindexed the pointwise to the reduction's iteration domain and ran them again. This PR originally kept that retry and added a pre-check to skip it when graph topology already ruled the fusion out, because most retries were wasted - 560 of 576 on one model's backward graph. Per review, the retry itself is no longer needed: the case it was added for (#183521) is handled by the original loop-transform path, and that PR's own tests, test_floordiv_broadcast_vertical_fusion and test_floordiv_broadcast_with_preceding_reduction, pass without it. So delete the retry rather than optimize it, and with it the pre-check this PR had added. Note what stays. _try_reindex_pointwise_for_reduction is still live: it is called from shared_data_after_reordering_loop, which is the loop-transform path the review suggested handling this in. config.loop_reindexing_after_fusion still gates that call and the score threshold above it. Only the retry in can_fuse and its pre-check go away. No compile-time claim this time. The workload the earlier numbers came from is nondeterministic - it fabricates random inputs, and three runs of *identical* code produced 96, 100 and 101 triton kernels in 46.24s, 45.76s and 48.40s - so a difference of a second or two between the two variants cannot be resolved on it, and the measurements I took disagreed with each other. The justification here is that the code path is unnecessary, not that removing it is faster. Test plan: ``` python test/inductor/test_loop_ordering.py ``` 124 tests, OK, and the failure set is identical to a run with the retry still in place. Both tests from #183521 pass individually. This PR was authored with the assistance of an AI coding agent. ghstack-source-id: 8b4573a Pull-Request: #193158
[ghstack-poisoned]
can_fuse had a second chance for vertical fusion: when the checks failed, it reindexed the pointwise to the reduction's iteration domain and ran them again. This PR originally kept that retry and added a pre-check to skip it when graph topology already ruled the fusion out, because most retries were wasted - 560 of 576 on one model's backward graph. Per review, the retry itself is no longer needed: the case it was added for (#183521) is handled by the original loop-transform path, and that PR's own tests, test_floordiv_broadcast_vertical_fusion and test_floordiv_broadcast_with_preceding_reduction, pass without it. So delete the retry rather than optimize it, and with it the pre-check this PR had added. Note what stays. _try_reindex_pointwise_for_reduction is still live: it is called from shared_data_after_reordering_loop, which is the loop-transform path the review suggested handling this in. config.loop_reindexing_after_fusion still gates that call and the score threshold above it. Only the retry in can_fuse and its pre-check go away. No compile-time claim this time. The workload the earlier numbers came from is nondeterministic - it fabricates random inputs, and three runs of *identical* code produced 96, 100 and 101 triton kernels in 46.24s, 45.76s and 48.40s - so a difference of a second or two between the two variants cannot be resolved on it, and the measurements I took disagreed with each other. The justification here is that the code path is unnecessary, not that removing it is faster. Test plan: ``` python test/inductor/test_loop_ordering.py ``` 124 tests, OK, and the failure set is identical to a run with the retry still in place. Both tests from #183521 pass individually. This PR was authored with the assistance of an AI coding agent. ghstack-source-id: f8e9fdc Pull-Request: #193158
|
@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 |
|
Hi @anijain2305 , Platform detected: GB200 My manual run seems to confirm the pass/fail observation. Perhaps the test needs to be updated? Thank you! |
|
@pytorchbot revert -m "b200 regression" -c nosignal |
|
@pytorchbot successfully started a revert job. Check the current status here. |
This reverts commit e39e738. Reverted #193158 on behalf of https://github.com/anijain2305 due to b200 regression ([comment](#193158 (comment)))
|
@anijain2305 your PR has been successfully reverted. |
To give you more information on the status of the B200 and GB200: We can consider getting other projects who are sharing x86+B200 systems to move away, and try testing full on B200, but since the test runs too long, I am not sure if existing capacity would be enough. So TLDR: likely the failure is still only available via NVIDIA internal testing post landing. |
|
@claude is the test failure blackwell-specific? From the description "Why it breaks the test: The test test_persistent_reduction_cse_reindexed_epilogue expects that the persistent reduction kernel fuses the epilogue |
|
Claude finished @ngimel's task in 27m 1s —— View job Short answer: I agree with you — nothing in what this test asserts looks Blackwell-specific.The assertions are on the generated Triton source (load counts, one Details: why the assertions should be arch-independent, and what I think actually hid the signalWhat the test asserts
All of these are string counts over emitted source, so they depend on scheduling/codegen decisions, not on the runtime launch config. Device-conditional code in that path, and why each is inert here
So the mechanism in the bisect writeup ("without the reindex retry the epilogue doesn't fuse, so loads aren't CSE'd") should reproduce on any CUDA device where the test actually executes. My hypothesis for the missing PyTorch CI signalThe failing case is If PyTorch's pinned Triton ( The decisive check (I can't run it — no GPU in this environment)On the internal GB200 box, with the revert reapplied (i.e. retry deleted), run both parametrizations: Then read the skip/fail split:
Either way, I would not label this Blackwell-specific on the current evidence. |
can_fuse had a second chance for vertical fusion: when the checks failed, it reindexed the pointwise to the reduction's iteration domain and ran them again. This PR originally kept that retry and added a pre-check to skip it when graph topology already ruled the fusion out, because most retries were wasted - 560 of 576 on one model's backward graph. Per review, the retry itself is no longer needed: the case it was added for (pytorch#183521) is handled by the original loop-transform path, and that PR's own tests, test_floordiv_broadcast_vertical_fusion and test_floordiv_broadcast_with_preceding_reduction, pass without it. So delete the retry rather than optimize it, and with it the pre-check this PR had added. Note what stays. _try_reindex_pointwise_for_reduction is still live: it is called from shared_data_after_reordering_loop, which is the loop-transform path the review suggested handling this in. config.loop_reindexing_after_fusion still gates that call and the score threshold above it. Only the retry in can_fuse and its pre-check go away. No compile-time claim this time. The workload the earlier numbers came from is nondeterministic - it fabricates random inputs, and three runs of *identical* code produced 96, 100 and 101 triton kernels in 46.24s, 45.76s and 48.40s - so a difference of a second or two between the two variants cannot be resolved on it, and the measurements I took disagreed with each other. The justification here is that the code path is unnecessary, not that removing it is faster. Test plan: ``` python test/inductor/test_loop_ordering.py ``` 124 tests, OK, and the failure set is identical to a run with the retry still in place. Both tests from pytorch#183521 pass individually. This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#193158 Approved by: https://github.com/eellison
…)" This reverts commit e39e738. Reverted pytorch#193158 on behalf of https://github.com/anijain2305 due to b200 regression ([comment](pytorch#193158 (comment)))
|
Closing because this does prevent one fusion. And the compile time benefits have lowered as other PRs have been merged. |
Stack from ghstack (oldest at bottom):
can_fuse had a second chance for vertical fusion: when the checks failed, it
reindexed the pointwise to the reduction's iteration domain and ran them again.
This PR originally kept that retry and added a pre-check to skip it when graph
topology already ruled the fusion out, because most retries were wasted - 560 of
576 on one model's backward graph.
Per review, the retry itself is no longer needed: the case it was added for
(#183521) is handled by the original loop-transform path, and that PR's own
tests, test_floordiv_broadcast_vertical_fusion and
test_floordiv_broadcast_with_preceding_reduction, pass without it. So delete the
retry rather than optimize it, and with it the pre-check this PR had added.
Note what stays. _try_reindex_pointwise_for_reduction is still live: it is called
from shared_data_after_reordering_loop, which is the loop-transform path the
review suggested handling this in. config.loop_reindexing_after_fusion still
gates that call and the score threshold above it. Only the retry in can_fuse and
its pre-check go away.
No compile-time claim this time. The workload the earlier numbers came from is
nondeterministic - it fabricates random inputs, and three runs of identical
code produced 96, 100 and 101 triton kernels in 46.24s, 45.76s and 48.40s - so a
difference of a second or two between the two variants cannot be resolved on it,
and the measurements I took disagreed with each other. The justification here is
that the code path is unnecessary, not that removing it is faster.
Test plan:
124 tests, OK, and the failure set is identical to a run with the retry still in
place. Both tests from #183521 pass individually.
This PR was authored with the assistance of an AI coding agent.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo