Repository navigation
Conversation
This adds the SIMD/Triton lowering for nested grouped reductions and enables the scheduler feature. The tests are kept with the lowering so the generated-code expectations and behavioral coverage can be reviewed beside the code that emits the nested kernels. Authored with Claude. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/182897
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ⏳ 54 Pending, 1 Unrelated FailureAs of commit ec73699 with merge base da74fec ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This adds the SIMD/Triton lowering for nested grouped reductions and enables the scheduler feature. The tests are kept with the lowering so the generated-code expectations and behavioral coverage can be reviewed beside the code that emits the nested kernels. Authored with Claude. [ghstack-poisoned]
This adds the SIMD/Triton lowering for nested grouped reductions and enables the scheduler feature. The tests are kept with the lowering so the generated-code expectations and behavioral coverage can be reviewed beside the code that emits the nested kernels. Authored with Claude. [ghstack-poisoned]
This adds the SIMD/Triton lowering for nested grouped reductions and enables the scheduler feature. The tests are kept with the lowering so the generated-code expectations and behavioral coverage can be reviewed beside the code that emits the nested kernels. Authored with Claude. [ghstack-poisoned]
This adds the SIMD/Triton lowering for nested grouped reductions and enables the scheduler feature. The tests are kept with the lowering so the generated-code expectations and behavioral coverage can be reviewed beside the code that emits the nested kernels. Authored with Claude. [ghstack-poisoned]
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: pytorch#183432, pytorch#183632
…82897)" This reverts commit 333b108. Reverted pytorch#182897 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#182897 (comment)))
This adds the SIMD/Triton lowering for nested grouped reductions and enables the scheduler feature. The tests are kept with the lowering so the generated-code expectations and behavioral coverage can be reviewed beside the code that emits the nested kernels. Authored with Claude. ghstack-source-id: 7aec74d Pull Request resolved: #182897
|
@pytorchbot merge -f "skipped test that was unrelated anyway" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: pytorch#183432, pytorch#183632
…82897)" This reverts commit 333b108. Reverted pytorch#182897 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#182897 (comment)))
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: pytorch#183432, pytorch#183632
|
@eellison the oncall skill thinks this regressed the instruction count benchmark: is this expected? |
|
@pytorchbot revert -c nosignal -m "Conservatively reverting as a part of the investigation in #185255 - please help, I could be wrong, I'm not getting a good repro of the issue." |
|
@pytorchbot successfully started a revert job. Check the current status here. |
Reverting PR 182897 failedReason: Command Details for Dev Infra teamRaised by workflow job |
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/jansel ghstack dependencies: pytorch#183432, pytorch#183632
…82897)" This reverts commit cd1cd1d. Reverted pytorch#182897 on behalf of https://github.com/jeffdaily due to broke rocm test/inductor/test_nested_reduction.py::NestedReductionInternalsNonPersistentTest::test_dynamic_layernorm_block_amax_kernel_form [GH job link](https://github.com/pytorch/pytorch/actions/runs/25900585488/job/76125680015) [HUD commit link](https://hud.pytorch.org/pytorch/pytorch/commit/cd1cd1d5adbedcd6144ee28a15dc7567e0a574fb) ([comment](pytorch#182897 (comment)))
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: pytorch#183432, pytorch#183632
…82897)" This reverts commit 333b108. Reverted pytorch#182897 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#182897 (comment)))
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: pytorch#183432, pytorch#183632
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/jansel ghstack dependencies: pytorch#183432, pytorch#183632
…82897)" This reverts commit cd1cd1d. Reverted pytorch#182897 on behalf of https://github.com/jeffdaily due to broke rocm test/inductor/test_nested_reduction.py::NestedReductionInternalsNonPersistentTest::test_dynamic_layernorm_block_amax_kernel_form [GH job link](https://github.com/pytorch/pytorch/actions/runs/25900585488/job/76125680015) [HUD commit link](https://hud.pytorch.org/pytorch/pytorch/commit/cd1cd1d5adbedcd6144ee28a15dc7567e0a574fb) ([comment](pytorch#182897 (comment)))
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: pytorch#183432, pytorch#183632
…82897)" This reverts commit 333b108. Reverted pytorch#182897 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#182897 (comment)))
* [inductor] Lower nested reductions in SIMD codegen This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over `D`, followed by a local grouped reduction over a small block inside that same `D` axis, for example `x_normed.reshape(B, D // G, G).amax(-1)`. Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw `(B, D)`, while the grouped stage saw `(B, D // G, G)`. That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel. The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis: `[XBLOCK, RBLOCK]` is reshaped to `[XBLOCK, RBLOCK / G, G]`, then Triton reduces axis 2 to produce `[XBLOCK, RBLOCK / G]`. The kernel also forces `min_rblock = G` so the parent tile always contains at least one whole local group. Most of the implementation is in `torch/_inductor/codegen/simd.py`. `_GroupedReductionLayout` describes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers in `torch/_inductor/codegen/triton.py`. Scheduler dispatch is updated so `FusedNestedReductions` routes to `codegen_nested_reduction`, is excluded from combo kernels, and increments `metrics.codegen_nested_reduction`. The scope is intentionally conservative. This commit enables `triton.nested_reduction` by default, but only supports grouped reductions that split the parent R axis; `GroupedAxis.X` is still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance. Authored with Claude. Pull Request resolved: pytorch#182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: pytorch#183432, pytorch#183632
Stack from ghstack (oldest at bottom):
[inductor] Lower nested reductions in SIMD codegen
This commit adds the first SIMD/Triton lowering for nested grouped reductions. The target pattern is an outer reduction such as LayerNorm/RMSNorm over
D, followed by a local grouped reduction over a small block inside that sameDaxis, for examplex_normed.reshape(B, D // G, G).amax(-1). Before this commit, the two reductions used different iteration views of the same logical data: the outer stage saw(B, D), while the grouped stage saw(B, D // G, G). That mismatch meant Inductor had to materialize the intermediate and launch a separate grouped-reduction kernel.The new lowering keeps the outer reduction as the owner of the Triton kernel's grid, tiling, and persistent/looped reduction choice. After the ordinary SIMD outer reduction is emitted, codegen remaps the grouped reduction body into the same parent tile. For this commit's supported case, the local group splits the parent R axis:
[XBLOCK, RBLOCK]is reshaped to[XBLOCK, RBLOCK / G, G], then Triton reduces axis 2 to produce[XBLOCK, RBLOCK / G]. The kernel also forcesmin_rblock = Gso the parent tile always contains at least one whole local group.Most of the implementation is in
torch/_inductor/codegen/simd.py._GroupedReductionLayoutdescribes the R-axis grouped geometry, derived iteration families switch codegen between parent-full and reduced-output views, and the nested ops handlers remap loads/stores while emitting reshape, reduce, and broadcast operations through new helpers intorch/_inductor/codegen/triton.py. Scheduler dispatch is updated soFusedNestedReductionsroutes tocodegen_nested_reduction, is excluded from combo kernels, and incrementsmetrics.codegen_nested_reduction.The scope is intentionally conservative. This commit enables
triton.nested_reductionby default, but only supports grouped reductions that split the parent R axis;GroupedAxis.Xis still rejected here. Group size must be static, power-of-two, and within the existing min-block limits, and nested lowering still excludes higher-rank grouped layouts, multiple grouped reductions, split reductions, cooperative reduction, C++ wrapper support, and tuple/stateful reductions such as argmax or Welford variance.Authored with Claude.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @mlazos