Skip to content

Replace sympy.Mod with custom Mod object#96270

Closed
Chillee wants to merge 2 commits intogh/chillee/195/basefrom
gh/chillee/195/head
Closed

Replace sympy.Mod with custom Mod object#96270
Chillee wants to merge 2 commits intogh/chillee/195/basefrom
gh/chillee/195/head

Conversation

@Chillee
Copy link
Copy Markdown
Collaborator

@Chillee Chillee commented Mar 8, 2023

@pytorch-bot pytorch-bot bot added release notes: fx release notes category labels Mar 8, 2023
Chillee added a commit that referenced this pull request Mar 8, 2023
ghstack-source-id: 7b7c9c3
Pull Request resolved: #96270
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Mar 8, 2023

🔗 Helpful Links

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

Note: Links to docs will display an error until the docs builds have been completed.

❌ 24 Failures

As of commit 5c251da:

NEW FAILURES - The following jobs have failed:

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

self.env[node] = self.run_node(node)
except Exception as e:
if self.extra_traceback:
if hasattr(self, "extra_traceback") and self.extra_traceback:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was breaking for me 🤔

isinstance(base, sympy.Integer)
and isinstance(modulus, sympy.Integer)
):
return base % modulus
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream mod has a number of seemingly non-objectionable other simplifications, which may be worth taking. See https://github.com/sympy/sympy/blob/master/sympy/core/mod.py

At a brief glance, here are rules we might like:

  • Mod by two can use even/odd assumptions
  • Simplifying nested Mod

):
return base % modulus

if isinstance(base, sympy.Add):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sympy has a comment like

        # (x + y + 2) % x -> Mod(y + 2, x)

which I thought was pretty useful for understanding what their Add rule is simplifying for

if (isinstance(term, sympy.Integer) and term < 0) or (
isinstance(term, sympy.Mul)
and isinstance(term.args[0], sympy.Integer)
and term.args[0] < 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition looks wrong. Why can't we use sympy assumptions to determine if the term is negative or not?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just mimicked from the existing ModularIndexing code. cc: @ngimel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against using sympy assymptions, I think when I just tried to put comparison in ModularIndexing it errored out, but I don't remember.
This exemption shouldn't be necessary really, in ModularIndexing it exists only to work around triton bug. (e.g. with valid simplifications (x - y) % x will turn in to -y % x and iirc triton has problems with negative FloorDivs or modulos, but we probably don't need to care about it in symbolic_shapes

Copy link
Copy Markdown
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not convinced by the Triton workaround code

@albanD albanD removed their request for review March 8, 2023 20:01
cc soumith voznesenskym penguinwu anijain2305 EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

[ghstack-poisoned]
Chillee added a commit that referenced this pull request Mar 10, 2023
ghstack-source-id: f509479
Pull Request resolved: #96270
@github-actions
Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions bot added the Stale label May 10, 2023
@github-actions github-actions bot closed this Jun 9, 2023
@facebook-github-bot facebook-github-bot deleted the gh/chillee/195/head branch July 9, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants