-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Use a custom Symbol class for performance #135651
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/135651
Note: Links to docs will display an error until the docs builds have been completed. ❌ 24 New FailuresAs of commit bf891a1 with merge base d2207c5 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| def make_symbol(prefix: SymT, idx: int, **kwargs) -> sympy.Symbol: | ||
| # TODO: maybe put the assumptions here directly | ||
| return sympy.Symbol(f"{prefix_str[prefix]}{idx}", **kwargs) | ||
| class PrefixedSymbol(sympy.Symbol): |
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.
needs a comment I suppose
| else: | ||
| return name_str.startswith(tuple(prefix_str[p] for p in prefix)) | ||
| assert isinstance(sym, sympy.Symbol) | ||
| # TODO: remove all these Symbols and use PrefixedSymbol |
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.
lol, I think I did think about storing the prefix explicitly and then gave up when trying to figure out how to update everyone.
| return name_str.startswith(tuple(prefix_str[p] for p in prefix)) | ||
| assert isinstance(sym, sympy.Symbol) | ||
| # TODO: remove all these Symbols and use PrefixedSymbol | ||
| sym_name = sym.name.lower() |
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 hate this so frickin much lol. @shunting314, @jansel let's not take changes like this please lol (c.f. #127342 )
torch/utils/_sympy/symbol.py
Outdated
| def symbol_is_type(sym: sympy.Basic, prefix: Union[SymT, Tuple[SymT, ...]]) -> bool: | ||
| if isinstance(sym, PrefixedSymbol): | ||
| # This function is called a *lot* of times, so it needs to be fast | ||
| if type(prefix) == tuple: |
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.
maybe is here is slightly faster?
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.
Hmm, do you think we can afford an assert type(prefix) == SymT in the else case? Because otherwise I'm afraid of someone feeding us a list and not have typechecking on lol
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.
Didn't see any measurable difference. Fixed now
ghstack-source-id: 08df448 Pull Request resolved: pytorch#135651
|
So is this hopeless or is there still hope haha |
|
I don't think this is easy to do this across the codebase. I'll close this for now and open it later if the performance becomes too much of a bottleneck. |
Stack from ghstack (oldest at bottom):
cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @voznesenskym @penguinwu @EikanWang @Guobing-Chen @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang