Skip to content

Conversation

@wanchaol
Copy link
Collaborator

@wanchaol wanchaol commented Jul 23, 2019

Stack from ghstack:

Differential Revision: D16466590

@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: internals Related to internal abstractions in c10 and ATen labels Jul 23, 2019
@wanchaol wanchaol requested review from driazati, eellison and suo July 23, 2019 18:22
Copy link
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

I haven't really looked into it but i think all of the implementation is more or less a copy-pasta of the torch.tensor code. Can you refactor the code ?

[jit] support torch.as_tensor in script

gh-metadata: pytorch pytorch 23247 gh/wanchaol/32/head
Copy link
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Looks good! i think there are a couple errors in shape analysis that need fixing.

Also in the interest of supporting GRU in script it's worth mentioning that you could rewrite:

torch.as_tensor(lengths, dtype=torch.int64) to lengths.to(dtype=torch.int64) which is currently supported

IValue dtype;
IValue device;
if (if_set_requires_grad) {
pop(stack, data, dtype, device, requires_grad);
Copy link
Contributor

@eellison eellison Jul 23, 2019

Choose a reason for hiding this comment

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

It's a little confusing to check if this function is correct you have to look back at all of its callsites and see if if the schema matches to verify correctness, which kind of breaks abstraction of the function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what do you mean by this? this abstraction only differed in a flag where one schema contains requires_grad and the other not

Copy link
Contributor

@eellison eellison Jul 25, 2019

Choose a reason for hiding this comment

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

maybe add comment that torch::tensor has a fourth requires_grad arg that as_tensor does not have. or not

Copy link
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Looks good, just one function that is copy-pasta'd to be refactored and should be ready to go

IValue dtype;
IValue device;
if (if_set_requires_grad) {
pop(stack, data, dtype, device, requires_grad);
Copy link
Contributor

@eellison eellison Jul 25, 2019

Choose a reason for hiding this comment

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

maybe add comment that torch::tensor has a fourth requires_grad arg that as_tensor does not have. or not

Copy link
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

LGTM. One small comment about refactoring but should be good to go

@zou3519 zou3519 deleted the gh/wanchaol/32/head branch July 29, 2019 21:41
zdevito pushed a commit to zdevito/ATen that referenced this pull request Jul 29, 2019
Summary: Pull Request resolved: pytorch/pytorch#23247

Test Plan: Imported from OSS

Differential Revision: D16466590

Pulled By: wanchaol

fbshipit-source-id: cf52721eacd177d9040564790382db13a9fcc2fe
@facebook-github-bot
Copy link
Contributor

@wanchaol merged this pull request in c779eff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: internals Related to internal abstractions in c10 and ATen oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants