Skip to content

[lint] Fix set linter nested f-string parsing - #183632

Closed
eellison wants to merge 1 commit into
gh/eellison/1019/basefrom
gh/eellison/1019/head
Closed

eellison wants to merge 1 commit into
gh/eellison/1019/basefrom
gh/eellison/1019/head

Conversation

@eellison

@eellison eellison commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

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.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented May 13, 2026 •

Copy link
Copy Markdown

🔗 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 SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 0ad2b96 with merge base 8e63642 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@eellison

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 14, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

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
@github-actions
github-actions Bot deleted the gh/eellison/1019/head branch June 14, 2026 02:28
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants