Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/183632
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: ✅ No FailuresAs of commit 0ad2b96 with merge base 8e63642 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced May 13, 2026
drisspg
approved these changes
May 14, 2026
Skylion007
approved these changes
May 14, 2026
Contributor
Author
|
@pytorchbot merge |
Collaborator
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 |
pytorchmergebot
pushed a commit
that referenced
this pull request
May 15, 2026
* [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: #182897 Approved by: https://github.com/jansel ghstack dependencies: #183432, #183632
pytorchmergebot
pushed a commit
that referenced
this pull request
May 20, 2026
* [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: #182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: #183432, #183632
pytorchmergebot
pushed a commit
to khushi-411/pytorch
that referenced
this pull request
May 20, 2026
* [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
pytorchmergebot
pushed a commit
that referenced
this pull request
May 20, 2026
* [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: #182897 Approved by: https://github.com/mlazos, https://github.com/drisspg ghstack dependencies: #183432, #183632
pytorchmergebot
pushed a commit
to weishi-deng/pytorch
that referenced
this pull request
May 21, 2026
* [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
pytorchmergebot
pushed a commit
to weishi-deng/pytorch
that referenced
this pull request
May 21, 2026
* [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
gplutop7
pushed a commit
to gplutop7/pytorch
that referenced
this pull request
Jul 15, 2026
The set linter's bracket parser kept f-string state in the same stack as token indices, so nested f-strings could later be interpreted as an index and crash. Track f-string nesting separately and add a regression case. Authored by Codex. Pull Request resolved: pytorch#183632 Approved by: https://github.com/drisspg, https://github.com/Skylion007 ghstack dependencies: pytorch#183432
gplutop7
pushed a commit
to gplutop7/pytorch
that referenced
this pull request
Jul 15, 2026
* [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
gplutop7
pushed a commit
to gplutop7/pytorch
that referenced
this pull request
Jul 15, 2026
* [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
gplutop7
pushed a commit
to gplutop7/pytorch
that referenced
this pull request
Jul 15, 2026
* [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
aws-kingrj
pushed a commit
to amazon-contributing/upstream-to-pytorch
that referenced
this pull request
Jul 29, 2026
The set linter's bracket parser kept f-string state in the same stack as token indices, so nested f-strings could later be interpreted as an index and crash. Track f-string nesting separately and add a regression case. Authored by Codex. Pull Request resolved: pytorch#183632 Approved by: https://github.com/drisspg, https://github.com/Skylion007 ghstack dependencies: pytorch#183432
aws-kingrj
pushed a commit
to amazon-contributing/upstream-to-pytorch
that referenced
this pull request
Jul 29, 2026
* [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
aws-kingrj
pushed a commit
to amazon-contributing/upstream-to-pytorch
that referenced
this pull request
Jul 29, 2026
* [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
aws-kingrj
pushed a commit
to amazon-contributing/upstream-to-pytorch
that referenced
this pull request
Jul 29, 2026
* [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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
The set linter's bracket parser kept f-string state in the same stack as token indices, so nested f-strings could later be interpreted as an index and crash. Track f-string nesting separately and add a regression case.
Authored by Codex.