-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Updates torch.tensor, torch.as_tensor, and sparse ctors to use the device of inputs tensors they're given, by default #41984
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
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.
💊 CI failures summary and remediationsAs of commit 8419daf (more details on the Dr. CI page):
Extra GitHub checks: 1 failed
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 on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 18 times. |
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.
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.
Fixes #144957 Closes #73838 cc @albanD @ezyang Currently, `tensor_a.new_tensor()` will return a on-cpu tensor no matter where is `tensor_a`. This differs from the document and is a side-effect of #41984. See #144957 how current logic breaks dynamo. This PR restore the documented behavior and add tests for `new_tensor`. Pull Request resolved: #144958 Approved by: https://github.com/ezyang
…ch#144958) Fixes pytorch#144957 Closes pytorch#73838 cc @albanD @ezyang Currently, `tensor_a.new_tensor()` will return a on-cpu tensor no matter where is `tensor_a`. This differs from the document and is a side-effect of pytorch#41984. See pytorch#144957 how current logic breaks dynamo. This PR restore the documented behavior and add tests for `new_tensor`. Pull Request resolved: pytorch#144958 Approved by: https://github.com/ezyang
BC-Breaking Note
This PR changes the behavior of the torch.tensor, torch.as_tensor, and sparse constructors. When given a tensor as input and a device is not explicitly specified, these constructors now always infer their device from the tensor. Historically, if the optional dtype kwarg was provided then these constructors would not infer their device from tensor inputs. Additionally, for the sparse ctor a runtime error is now thrown if the indices and values tensors are on different devices and the device kwarg is not specified.
PR Summary
This PR's functional change is a single line:
=>
in
internal_new_from_data
. This line entangled whether the function was performing type inference with whether it inferred its device from an input tensor, and in practice meant thatwould return a tensor on the CPU, not the default CUDA device, while
would return a tensor on the device of
t
!This behavior is niche and odd, but came up while @aocsa was fixing #40648.
An additional side affect of this change is that the indices and values tensors given to a sparse constructor must be on the same device, or the sparse ctor must specify the dtype kwarg. The tests in test_sparse.py have been updated to reflect this behavior.