Fix some tensor operators to return NotImplemented for invalid inputs#57934
Fix some tensor operators to return NotImplemented for invalid inputs#57934asi1024 wants to merge 3 commits intopytorch:masterfrom
NotImplemented for invalid inputs#57934Conversation
💊 CI failures summary and remediationsAs of commit 3069f58 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions to the (internal) Dr. CI Users group. |
albanD
left a comment
There was a problem hiding this comment.
Thanks for the PR that looks quite good.
I am not sure what test_binary_ufuncs is testing for these. In particular, does it properly cover all the reverse cases and make sure they return the right value?
| {"__nonzero__", THPVariable_bool_scalar, METH_NOARGS, NULL}, | ||
| {"__invert__", THPVariable_invert, METH_NOARGS, NULL}, | ||
| {"__matmul__", castPyCFunctionWithKeywords(TypeError_to_NotImplemented_<THPVariable_matmul>), METH_VARARGS | METH_KEYWORDS, NULL}, | ||
| {"__rmatmul__", castPyCFunctionWithKeywords(TypeError_to_NotImplemented_<THPVariable_matmul>), METH_VARARGS | METH_KEYWORDS, NULL}, |
There was a problem hiding this comment.
Is THPVariable_matmul actually handling the reverse version properly?
In particular if two valid inputs are given to it and it does not throw an error.
Codecov Report
@@ Coverage Diff @@
## master #57934 +/- ##
==========================================
+ Coverage 76.82% 76.84% +0.01%
==========================================
Files 1986 1986
Lines 197448 197459 +11
==========================================
+ Hits 151693 151735 +42
+ Misses 45755 45724 -31 |
|
@albanD Thank you for your review! |
|
BTW, when I created this PR, I had a misunderstanding that I need to fix |
|
Thanks for the update. Could you make sure that the CI in green (in particular, flake is not happy with the assert False, you can replace it with raise RuntimeError...). |
|
I suggest just updating those that are easiest for the tests to pass and leaving a comment in the code about the remainders. This is a nice code cleanup but few users will appreciate the change |
albanD
left a comment
There was a problem hiding this comment.
LGTM thanks for the tests
|
@albanD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
|
Thanks @asi1024! |
|
Thanks! 😄 |
|
I'm afraid this broke some master-only CI builds: https://app.circleci.com/pipelines/github/pytorch/pytorch/320932/workflows/2a61be9b-ecad-475b-bb9a-0c03b6c97d71/jobs/13402438 I think bfloat16 should be added to the cuda types. Could you send a new PR with the same content as this one + the bfloat16 dtype on cuda? (the bot is going to mark this one reverted very soon) |
|
This pull request has been reverted by 5e83c62. |
…ts (pytorch#57934) Summary: Fixes pytorch#57719. This PR fixes `torch.Tensor{__rsub__, __rdiv__, __rtruediv__, __pow__, __rmatmul__}` to return `NotImplemented` instead of raising a `TypeError`. cc/ mruberry: The first commit of this PR is the same as pytorch@1d209db excepts the commit message. Pull Request resolved: pytorch#57934 Reviewed By: mruberry Differential Revision: D28351931 Pulled By: albanD fbshipit-source-id: 985457a44dba24d2496794dfb8c1661cbcd4ff8f
…ts (pytorch#57934) Summary: Fixes pytorch#57719. This PR fixes `torch.Tensor{__rsub__, __rdiv__, __rtruediv__, __pow__, __rmatmul__}` to return `NotImplemented` instead of raising a `TypeError`. cc/ mruberry: The first commit of this PR is the same as pytorch@1d209db excepts the commit message. Pull Request resolved: pytorch#57934 Reviewed By: mruberry Differential Revision: D28351931 Pulled By: albanD fbshipit-source-id: 985457a44dba24d2496794dfb8c1661cbcd4ff8f
…ts (pytorch#58216) Summary: Same as pytorch#57934. (cc/ albanD) Pull Request resolved: pytorch#58216 Reviewed By: ailzhang Differential Revision: D28494886 Pulled By: albanD fbshipit-source-id: 380205867ee1cde90e1c6fcfe2a31749e1243530
Fixes #57719.
This PR fixes
torch.Tensor{__rsub__, __rdiv__, __rtruediv__, __pow__, __rmatmul__}to returnNotImplementedinstead of raising aTypeError.cc/ @mruberry: The first commit of this PR is the same as 1d209db excepts the commit message.