-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Improve performance of canonicalize_bool_expr #135621
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/135621
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit d71d51a with merge base b7eb725 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| """ | ||
| def integer_coefficient(x): | ||
| if isinstance(x, sympy.Integer): | ||
| if x.is_Integer: |
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.
It's surprising to me that the attribute test is faster than isinstance; is this because there's some metaclass shenanigans in sympy or something?
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.
isinstance is slow regardless of metaclass complexity. If you know you have a sympy.Expr, attribute test is faster.
| elif isinstance(x, sympy.Mul): | ||
| return math.prod([abs(int(arg)) for arg in x.args if isinstance(arg, sympy.Integer)]) | ||
| elif x.is_Mul: | ||
| return abs(int(x.args[0])) if x.args[0].is_Integer else 1 |
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.
I guess your point here is that if there are multiple integral factors they're guaranteed to have already been folded
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.
Yep. Added a comment mentioning this.
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.
Not sure why tests are failing though
Pull Request resolved: #135622 Approved by: https://github.com/ezyang ghstack dependencies: #135621
Pull Request resolved: #135652 Approved by: https://github.com/ezyang ghstack dependencies: #135621, #135622
Pull Request resolved: #135621 Approved by: https://github.com/ezyang
Pull Request resolved: #135622 Approved by: https://github.com/ezyang ghstack dependencies: #135621
Pull Request resolved: #135652 Approved by: https://github.com/ezyang ghstack dependencies: #135621, #135622
Pull Request resolved: pytorch#135621 Approved by: https://github.com/ezyang
Pull Request resolved: pytorch#135622 Approved by: https://github.com/ezyang ghstack dependencies: pytorch#135621
Pull Request resolved: pytorch#135652 Approved by: https://github.com/ezyang ghstack dependencies: pytorch#135621, pytorch#135622
Pull Request resolved: pytorch#135621 Approved by: https://github.com/ezyang
Pull Request resolved: pytorch#135622 Approved by: https://github.com/ezyang ghstack dependencies: pytorch#135621
Pull Request resolved: pytorch#135652 Approved by: https://github.com/ezyang ghstack dependencies: pytorch#135621, pytorch#135622
ghstack-source-id: b5b800b Pull Request resolved: pytorch/pytorch#135621
Stack from ghstack (oldest at bottom):