-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Clarifies compare_with_numpy behavior #40064
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
ngimel
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.
It's good we are getting rid of tolist()s.
| # which takes care of negative strides if present. | ||
| torch_fn, np_fn = funcs | ||
| self.compare_with_numpy(torch_fn, np_fn, data, device, dtype) | ||
| if dtype.is_floating_point or dtype.is_complex: |
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.
so this ignored device altogether? Nice.
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.
No. Historically it would create a list from a tensor and then compare_with_numpy would put that list into a tensor on the appropriate device.
The updated test just has fewer steps to get to the same place.
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Currently compare_with_numpy requires a device and dtype, but these arguments are ignored if a tensor is provided. This PR updates the function to only take device and dtype if a tensor-like object is given. This should prevent confusion that you could, for example, pass a CPU float tensor but provided a CUDA device and integer dtype. Several tests are updated to reflect this behavior. Pull Request resolved: pytorch#40064 Differential Revision: D22058072 Pulled By: mruberry fbshipit-source-id: b494bb759855977ce45b79ed3ffb0319a21c324c
Currently compare_with_numpy requires a device and dtype, but these arguments are ignored if a tensor is provided. This PR updates the function to only take device and dtype if a tensor-like object is given. This should prevent confusion that you could, for example, pass a CPU float tensor but provided a CUDA device and integer dtype.
Several tests are updated to reflect this behavior.