Skip to content

Simplify FloorDiv(ModularIndexing) and generalize remove_zero_terms - #176345

Closed
eellison wants to merge 6 commits into
gh/eellison/959/basefrom
gh/eellison/959/head
Closed

eellison wants to merge 6 commits into
gh/eellison/959/basefrom
gh/eellison/959/head

Conversation

@eellison

@eellison eellison commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Two indexing simplification improvements:

  1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
    ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
    a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
    producing cleaner index expressions for reshape + reduction patterns.

  2. remove_zero_terms in visit_indexing_div is generalized: the condition
    for dropping a variable v from the base changes from requiring
    gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
    handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Mar 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/176345

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:

❌ 9 New Failures

As of commit c981b70 with merge base 2ff017b (image):

NEW FAILURES - The following jobs have failed:

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

@pytorch-bot

pytorch-bot Bot commented Mar 3, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

eellison added a commit that referenced this pull request Mar 3, 2026
Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

ghstack-source-id: 689c1ea
Pull Request resolved: #176345
@pytorch-bot pytorch-bot Bot added the ciflow/torchtitan Run TorchTitan integration tests label Apr 1, 2026
eellison added 2 commits April 2, 2026 08:35
…ero_terms"

Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo

[ghstack-poisoned]
…ero_terms"

Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@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 Apr 14, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@pytorch-bot

pytorch-bot Bot commented Apr 14, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@eellison eellison added the topic: not user facing topic category label Apr 14, 2026
@eellison

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

BoyuanFeng pushed a commit that referenced this pull request Apr 15, 2026
…176345)

Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

Pull Request resolved: #176345
Approved by: https://github.com/shunting314
pytorchmergebot pushed a commit to scotts/pytorch that referenced this pull request Apr 15, 2026
…ytorch#176345)

Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

Pull Request resolved: pytorch#176345
Approved by: https://github.com/shunting314
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ytorch#176345)

Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

Pull Request resolved: pytorch#176345
Approved by: https://github.com/shunting314
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ytorch#176345)

Two indexing simplification improvements:

1. FloorDiv(ModularIndexing(b, d1, m), d2) now simplifies to
   ModularIndexing(b, d1*d2, m//d2) when d2 divides m. This collapses
   a nested FloorDiv-over-ModularIndexing into a single ModularIndexing,
   producing cleaner index expressions for reshape + reduction patterns.

2. remove_zero_terms in visit_indexing_div is generalized: the condition
   for dropping a variable v from the base changes from requiring
   gcd(rest, divisor) == divisor to v < gcd(rest, divisor). This
   handles more cases where v is small enough not to affect the FloorDiv.

Also adds base < divisor → 0 simplification for visit_indexing_div.

Authored with Claude.

Pull Request resolved: pytorch#176345
Approved by: https://github.com/shunting314
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants