New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify and extend ValueRanges #104557
Simplify and extend ValueRanges #104557
Conversation
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/104557
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 19eb958: NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice !! Have a few comments.
Is it worth committing the fuzzing script that Nuno wrote https://gist.github.com/nunoplopes/dc08bee4f3fb3609f916aa1e9389273a ? Or something like it, maybe as a slow test.
lower: Union[sympy.Expr, SympyBoolean] | ||
upper: Union[sympy.Expr, SympyBoolean] | ||
is_bool: bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its a little funny that we're tracking the dtype only if it's a bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. It's in my radar to improve it eventually to track the type properly and make sure that the type of the bounds and the type of the object is sound. For now, bool it is, given that booleans are just very different to floats and integers in sympy.
def truncdiv(cls, a, b): | ||
x = cls.truediv(a, b) | ||
if x == ValueRanges.unknown(): | ||
return x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this equivalent, or fixing a bug ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equivalent and noticeably simpler.
if a == 0: | ||
return 0 | ||
return a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jc, why did you have to return a here instead of 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to return a zero that's both a sympy object and it's of the correct dtype.
torch/utils/_sympy/value_ranges.py
Outdated
while b > 0: | ||
if b % 2 == 1: | ||
acc = cls.mul(acc, a) | ||
a = cls.mul(a, a) | ||
b = b // 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not just call into sympy.pow at this point ? Feel like there's probably a way of implementing this simpler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let me rewrite this. This one's a weird op, as -3.0 ** x
is not well defined, but -3 ** x
is well defined for x integer. I'll split it into a
integer and not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I heavily simplified this logic, now it looks much better.
For the testing, I plan to push some proper testing soonish, where we test these ranges on the FX interpreter, for the nodes that we use in that interpreter, and then keep Ed's tests for the SymPy nodes. I also plan to trim the SymPy interpreter to just implement the functions we currently use for the guards and the indexing on inductor. |
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
@eellison addressed the review |
The next two are also ready and should be quite easy reviews :) |
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 [ghstack-poisoned]
This PR: - It adds a few boolean variants of some methods that were missing - It simplifies the implementation of plenty of the operations - Adds ModularIndexing to the SymPy interpreter cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 ipiszy ngimel yf225 chenyang78 kadeng muchulee8 [ghstack-poisoned]
Stack from ghstack (oldest at bottom):
This PR:
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @ngimel @yf225 @chenyang78 @kadeng @muchulee8