add tensor.to to script#15976
Conversation
| non_blocking = non_blocking if non_blocking is not None else False | ||
| code = template.format(to_str=to_str, device=device, non_blocking=non_blocking) | ||
| scope = {} | ||
| exec(code, globals(), scope) |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
| } | ||
| if (!device && !scalarType && !copy) { | ||
| return self; | ||
| } else if (!device) { |
There was a problem hiding this comment.
Is it possible for both device and scalarType to be nullopts?
There was a problem hiding this comment.
I was just replicating the exiting logic which is:
if (!device && !scalarType && !copy) {
Py_INCREF(self);
return self;
} else if (!device) {
return THPVariable_Wrap(dispatch_to(self_, *scalarType, non_blocking, copy));
} else if (!scalarType) {
return THPVariable_Wrap(dispatch_to(self_, *device, non_blocking, copy));
} else {
return THPVariable_Wrap(dispatch_to(self_, *device, *scalarType, non_blocking, copy));
}
I could explicitly check also check for the case where copy=False and device & scalarType aren't set. That wouldn't really make sense in user code
There was a problem hiding this comment.
It errors in pytorch, so not much point in supporting it in script:
>>> a.to(copy=True)
Assertion failed: (initialized()), function operator*, file ../c10/util/Optional.h, line 596.
| "aten::device(str a) -> Device", | ||
| [](const Node* node) -> Operation { | ||
| return [](Stack& stack) { | ||
| push(stack, c10::Device(pop(stack).toStringRef())); |
There was a problem hiding this comment.
Why toStringRef? IValue supports Device
There was a problem hiding this comment.
This shouldn't have been added - it already exists. Will delete. Good catch
facebook-github-bot
left a comment
There was a problem hiding this comment.
@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Previously it only worked with keyword arguments. Now it is fully compatible. Fix for: pytorch#15478 Pull Request resolved: pytorch#15976 Differential Revision: D13643979 Pulled By: eellison fbshipit-source-id: 6a47bce7db362da80452adffebd2732f8e62a240
Previously it only worked with keyword arguments. Now it is fully compatible.
Fix for: #15478