-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Return NotImplemented from tensor arithmetic operators #26507
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
Return NotImplemented from tensor arithmetic operators #26507
Conversation
4304869 to
720f0ab
Compare
ezyang
left a comment
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.
Nifty!
|
@pytorchbot rebase this please |
|
Waiting on CI |
|
Sorry, I can't merge this because there are conflicts. To merge this yourself, run the commands below: (To learn more about this bot, see Bot commands.) |
720f0ab to
2024e0c
Compare
|
@pytorchbot rebase this please |
|
Sorry, I can't merge this because there are conflicts. To merge this yourself, run the commands below: (To learn more about this bot, see Bot commands.) |
|
Gosh, this PR conflicts a lot for some reason. |
|
Oh, you didn't grant maintainers rights to update the PR, so the bot can't update it. Could you please rebase again to clear up the errors? |
2024e0c to
ec97fe6
Compare
That's odd, "Allow edits from maintainers." is shown a selected on my screen. Could it be an issue with submitting from the Quansight repo? cc @rgommers |
Weirdly enough, I think it is. Just tried on PR 25629 and that failed as well. Our repository settings are a bit unusual, I'll look into it. Tried adding I'll try to look for a more structural fix, because if it is repository settings then it will happen on other repos as well. |
|
I had pytorchbot accept the invitation. |
|
@pytorchbot rebase this please |
|
Sorry, I can't merge this because there are conflicts. To merge this yourself, run the commands below: (To learn more about this bot, see Bot commands.) |
|
Didn't work :/ |
|
Hmm, then I have no idea. Will have to do some trial and error on a dummy repo. @peterbell10 for next PRs I suggest to open them from your own fork until we figure this out. |
ec97fe6 to
7268b60
Compare
facebook-github-bot
left a comment
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.
@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
should we be returning NotImplemented for the inplace functions? That doesn't seem correct. Also, this doesn't work fork for functions that are written in native_functions.yaml and aren't explicitly bound. |
|
The docs specify that it is valid for inplace functions too:
Rereviewing this diff, I regret not asking for tests though... |
Summary: Fixes pytorch#26333 This effectively rewrites all infix arithmetic operators *op* as: ```python def __op__(self, other): try: return self.op(other) except TypeError: return NotImplemented ``` Where `TypeError` is raised from the argument parser when `other` is not a `Tensor`. This should be okay, so long as `TypeError` isn't raised by the function for any other reasons. I couldn't find any examples where this was an issue. Pull Request resolved: pytorch#26507 Differential Revision: D17669097 Pulled By: ezyang fbshipit-source-id: 2c1a1087057c9298915d713d3fea7d682d014c72
Summary: Fixes pytorch#26333 This effectively rewrites all infix arithmetic operators *op* as: ```python def __op__(self, other): try: return self.op(other) except TypeError: return NotImplemented ``` Where `TypeError` is raised from the argument parser when `other` is not a `Tensor`. This should be okay, so long as `TypeError` isn't raised by the function for any other reasons. I couldn't find any examples where this was an issue. Pull Request resolved: pytorch#26507 Differential Revision: D17669097 Pulled By: ezyang fbshipit-source-id: 2c1a1087057c9298915d713d3fea7d682d014c72

Fixes #26333
This effectively rewrites all infix arithmetic operators op as:
Where
TypeErroris raised from the argument parser whenotheris not aTensor. This should be okay, so long asTypeErrorisn't raised by the function for any other reasons. I couldn't find any examples where this was an issue.