Repository navigation
[Cherry-pick][release/2.14] [inductor] Fix loop-local load CSE lifetime (#194786) - #194833
Conversation
Manual cherry-pick of 60598ed (pytorch#194786) onto release/2.14. Triton load placement and CSE lifetime used separate heuristics. An indirect load emitted inside a loop could remain cached after loop closure and be reused by an epilogue even though its temporary did not dominate that use. Use the selected load buffer as the source of truth for whether a CSE value survives loop closure, and stop hoisting loads that carry reduction masks before those masks are defined. Conflict resolution: * torch/_inductor/codegen/triton.py: upstream also deletes the reduction_axes_omitted bookkeeping added by pytorch#184287, which is not on this branch, so that deletion is already satisfied and the surrounding code is left as-is. The two substantive changes (the has_rmask() guard on lifting, and load_buffer is self.body as the CSE-lifetime test) apply unchanged. * test/inductor/test_indexing.py: upstream adds the regression test to ReductionInvariantIndexingTests, a class that pytorch#184287 introduced and which does not exist here. The regression test is ported verbatim into a new TestLoopLocalLoadCSELifetime class with the imports it needs (run_and_get_kernels, FileCheck, HAS_CUDA_AND_TRITON, config), all of which exist on this branch. The unrelated @parametrize("dense_indexing") hunk is dropped, since it belongs to a pytorch#184287 test. Fixes pytorch#194490 on the release branch.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194833
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit f02a9f9 with merge base 73db3ed ( GREEN LIGHT - PR requires human review:
reason: NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
test-infra's Release Binaries Validations checks out smoke_test.py from pytorch main but installs the published stable wheel. The regression check added in #195024 covers gh-194490, whose fix (#194786) landed after the 2.13 branch cut, so it reds all six linux CUDA 12.6 legs against the immutable 2.13.0 artifact with NameError('tmp19 is not defined'). Gate on the first release series containing the fix: 2.14, which has it via cherry-pick #194833. Reverting #195024 was the alternative, but it drops nightly coverage and leaves the next regression test added here to hit the same trap. Test Plan: 2.13.0 skips; 2.14.0, main and nightly run. ``` python -c " from torch.torch_version import TorchVersion for v in ['2.13.0+cu126','2.14.0+cu130','2.15.0a0+gitabc','2.15.0.dev20260829+cu126']: print(v, TorchVersion(v) < (2, 14)) " lintrunner -a --paths-cmd 'echo .ci/pytorch/smoke_test/smoke_test.py' ``` Authored with assistance from Claude Code. Pull Request resolved: #195306 Approved by: https://github.com/pytorchgreenlight, https://github.com/atalman
…ch#195306) test-infra's Release Binaries Validations checks out smoke_test.py from pytorch main but installs the published stable wheel. The regression check added in pytorch#195024 covers pytorchgh-194490, whose fix (pytorch#194786) landed after the 2.13 branch cut, so it reds all six linux CUDA 12.6 legs against the immutable 2.13.0 artifact with NameError('tmp19 is not defined'). Gate on the first release series containing the fix: 2.14, which has it via cherry-pick pytorch#194833. Reverting pytorch#195024 was the alternative, but it drops nightly coverage and leaves the next regression test added here to hit the same trap. Test Plan: 2.13.0 skips; 2.14.0, main and nightly run. ``` python -c " from torch.torch_version import TorchVersion for v in ['2.13.0+cu126','2.14.0+cu130','2.15.0a0+gitabc','2.15.0.dev20260829+cu126']: print(v, TorchVersion(v) < (2, 14)) " lintrunner -a --paths-cmd 'echo .ci/pytorch/smoke_test/smoke_test.py' ``` Authored with assistance from Claude Code. Pull Request resolved: pytorch#195306 Approved by: https://github.com/pytorchgreenlight, https://github.com/atalman
…ch#195306) test-infra's Release Binaries Validations checks out smoke_test.py from pytorch main but installs the published stable wheel. The regression check added in pytorch#195024 covers pytorchgh-194490, whose fix (pytorch#194786) landed after the 2.13 branch cut, so it reds all six linux CUDA 12.6 legs against the immutable 2.13.0 artifact with NameError('tmp19 is not defined'). Gate on the first release series containing the fix: 2.14, which has it via cherry-pick pytorch#194833. Reverting pytorch#195024 was the alternative, but it drops nightly coverage and leaves the next regression test added here to hit the same trap. Test Plan: 2.13.0 skips; 2.14.0, main and nightly run. ``` python -c " from torch.torch_version import TorchVersion for v in ['2.13.0+cu126','2.14.0+cu130','2.15.0a0+gitabc','2.15.0.dev20260829+cu126']: print(v, TorchVersion(v) < (2, 14)) " lintrunner -a --paths-cmd 'echo .ci/pytorch/smoke_test/smoke_test.py' ``` Authored with assistance from Claude Code. Pull Request resolved: pytorch#195306 Approved by: https://github.com/pytorchgreenlight, https://github.com/atalman
Manual cherry-pick of #194786 (
60598ed3c877) ontorelease/2.14. Fixes #194490 on the release branch.What the fix does
Triton load placement and CSE lifetime used separate heuristics. An indirect load emitted inside a reduction loop could stay in the CSE cache after the loop closed and be reused by an epilogue, even though its temporary did not dominate that use. Two changes:
get_load_bufferno longer lifts a load out of the loop when its indexing carries a reduction mask, since the mask is not defined outside the loop.loadnow uses the selected load buffer as the source of truth for CSE lifetime:load_buffer is self.body, rather than re-deriving it fromhas_rmask()/has_rindex().self.inside_reduction and self.range_trees[-1].is_loop and not indexing.has_rindex() + and not indexing.has_rmask() ): - # can lift a common load outside of reduction loop - # One exception is when this is an indirect_load. + # Lift loads whose address and mask are available outside the loop. return self.body - if not self.inside_reduction or (not indexing.has_rmask() and not has_rindex): + # Only CSE values emitted outside the loop remain valid after it closes. + if not self.inside_reduction or load_buffer is self.body: self.outside_loop_vars.add(result_var)Why it needed manual resolution
Both files conflicted, because
release/2.14predates #184287 — the PR whose narrowed-load work exposed this bug.torch/_inductor/codegen/triton.py— upstream also deletes thereduction_axes_omittedbookkeeping that #184287 introduced. That code is not on this branch, so the deletion is already satisfied and the surrounding lines are left as they are. Both substantive changes apply unchanged, andload_bufferis already in scope at the fix site (assigned fromget_load_bufferearlier inload).test/inductor/test_indexing.py— upstream adds the regression test toReductionInvariantIndexingTests, a class #184287 introduced that does not exist here. Rather than importing that whole class (whose other tests cover a feature this branch does not have), the regression testtest_loop_epilogue_indirect_load_scopeis ported verbatim into a newTestLoopLocalLoadCSELifetimeclass. Its helpers all exist on this branch:run_and_get_kernels(including theremove_quotekwarg),FileCheck,HAS_CUDA_AND_TRITONandtorch._inductor.config, added to the imports. The unrelated@parametrize("dense_indexing")hunk in the same upstream diff is dropped, since it parametrizes a #184287 test.Net result against
release/2.14:triton.py+4/-3,test_indexing.py+48/-2.Test plan
I could not execute it here — this checkout has no built PyTorch and the test requires CUDA and Triton — so it needs a run on CI or a GPU host before merge. Both files were syntax-checked, and the ported test is byte-identical to the upstream one apart from the class it lives in.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo
AI-Assisted: the conflict resolution and the test port were done with Claude Code. Author reviewed and validated all AI-generated content, per AI_POLICY.md.