Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add tensor.to to script#15976

Closed
eellison wants to merge 4 commits into
pytorch:masterfrom
eellison:test_to
Closed

add tensor.to to script#15976
eellison wants to merge 4 commits into
pytorch:masterfrom
eellison:test_to

Conversation

@eellison
Copy link
Copy Markdown
Contributor

Previously it only worked with keyword arguments. Now it is fully compatible.

Fix for: #15478

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jan 11, 2019
Comment thread test/test_jit.py Outdated
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this exec doing?

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for both device and scalarType to be nullopts?

Copy link
Copy Markdown
Contributor Author

@eellison eellison Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread torch/csrc/jit/register_prim_ops.cpp Outdated
"aten::device(str a) -> Device",
[](const Node* node) -> Operation {
return [](Stack& stack) {
push(stack, c10::Device(pop(stack).toStringRef()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why toStringRef? IValue supports Device

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't have been added - it already exists. Will delete. Good catch

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ezyang ezyang added the merged label Jun 25, 2019
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants