-
Notifications
You must be signed in to change notification settings - Fork 25k
Add error message for complex alpha and non-complex inputs #54964
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, the following would error out with a strange error message: ``` import torch x=torch.randn(2) torch.rsub(x, 1, alpha=2j) Traceback (most recent call last) <ipython-input-2-caf2a1c03d0b> in <module> 1 import torch 2 x=torch.randn(2) ----> 3 torch.rsub(x, 1, alpha=2j) RuntimeError: value cannot be converted to type float without overflow: (-0,-2) ``` The reason why this is happening is because the alpha check doesn't check for if `x` is not complex and `alpha` is complex. The error gets thrown further along in the implementation of torch.sub, when it coerces `alpha` to be the same dtype as the input tensor: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp#L53 This PR fixes the bad error message by adding a new check to the alpha check. Test Plan: - pytest test/test_binary_ufuncs.py - NB: add, sub, and rsub all share the same alpha check. The test only tests it for torch.add, but that should be sufficient. [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 1733ae7 (more details on the Dr. CI page):
1 failure not recognized by patterns:
ci.pytorch.org: 1 failedThis 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. |
zou3519
added a commit
that referenced
this pull request
Mar 30, 2021
Previously, the following would error out with a strange error message: ``` import torch x=torch.randn(2) torch.rsub(x, 1, alpha=2j) Traceback (most recent call last) <ipython-input-2-caf2a1c03d0b> in <module> 1 import torch 2 x=torch.randn(2) ----> 3 torch.rsub(x, 1, alpha=2j) RuntimeError: value cannot be converted to type float without overflow: (-0,-2) ``` The reason why this is happening is because the alpha check doesn't check for if `x` is not complex and `alpha` is complex. The error gets thrown further along in the implementation of torch.sub, when it coerces `alpha` to be the same dtype as the input tensor: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp#L53 This PR fixes the bad error message by adding a new check to the alpha check. Test Plan: - pytest test/test_binary_ufuncs.py - NB: add, sub, and rsub all share the same alpha check. The test only tests it for torch.add, but that should be sufficient. ghstack-source-id: 61d5b74 Pull Request resolved: #54964
anjali411
approved these changes
Mar 30, 2021
Previously, the following would error out with a strange error message: ``` import torch x=torch.randn(2) torch.rsub(x, 1, alpha=2j) Traceback (most recent call last) <ipython-input-2-caf2a1c03d0b> in <module> 1 import torch 2 x=torch.randn(2) ----> 3 torch.rsub(x, 1, alpha=2j) RuntimeError: value cannot be converted to type float without overflow: (-0,-2) ``` The reason why this is happening is because the alpha check doesn't check for if `x` is not complex and `alpha` is complex. The error gets thrown further along in the implementation of torch.sub, when it coerces `alpha` to be the same dtype as the input tensor: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp#L53 This PR fixes the bad error message by adding a new check to the alpha check. Test Plan: - pytest test/test_binary_ufuncs.py - NB: add, sub, and rsub all share the same alpha check. The test only tests it for torch.add, but that should be sufficient. Differential Revision: [D27504017](https://our.internmc.facebook.com/intern/diff/D27504017) [ghstack-poisoned]
zou3519
added a commit
that referenced
this pull request
Apr 7, 2021
Previously, the following would error out with a strange error message: ``` import torch x=torch.randn(2) torch.rsub(x, 1, alpha=2j) Traceback (most recent call last) <ipython-input-2-caf2a1c03d0b> in <module> 1 import torch 2 x=torch.randn(2) ----> 3 torch.rsub(x, 1, alpha=2j) RuntimeError: value cannot be converted to type float without overflow: (-0,-2) ``` The reason why this is happening is because the alpha check doesn't check for if `x` is not complex and `alpha` is complex. The error gets thrown further along in the implementation of torch.sub, when it coerces `alpha` to be the same dtype as the input tensor: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp#L53 This PR fixes the bad error message by adding a new check to the alpha check. Test Plan: - pytest test/test_binary_ufuncs.py - NB: add, sub, and rsub all share the same alpha check. The test only tests it for torch.add, but that should be sufficient. ghstack-source-id: 943e7ea Pull Request resolved: #54964
Codecov Report
@@ Coverage Diff @@
## gh/zou3519/349/base #54964 +/- ##
=======================================================
- Coverage 77.43% 77.42% -0.02%
=======================================================
Files 1895 1895
Lines 187516 187518 +2
=======================================================
- Hits 145196 145178 -18
- Misses 42320 42340 +20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stack from ghstack:
Previously, the following would error out with a strange error message:
The reason why this is happening is because the alpha check doesn't check for if
x
is not complex andalpha
is complex.The error gets thrown further along in the implementation of torch.sub,
when it coerces
alpha
to be the same dtype as the input tensor:https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp#L53
This PR fixes the bad error message by adding a new check to the alpha check.
Test Plan:
Differential Revision: D27504017