Skip to content

Conversation

@pbelevich
Copy link
Contributor

@pbelevich pbelevich commented Sep 17, 2019

Stack from ghstack:

Differential Revision: D17427575

@pytorchbot pytorchbot added module: autograd Related to torch.autograd, and the autograd engine in general module: cpp Related to C++ API module: internals Related to internal abstractions in c10 and ATen module: operators module: pybind Related to our Python bindings / interactions with other Python libraries labels Sep 17, 2019
pbelevich added a commit that referenced this pull request Sep 17, 2019
ghstack-source-id: 680c8c6
Pull Request resolved: #26332
Copy link
Contributor

@yf225 yf225 left a comment

Choose a reason for hiding this comment

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

Overall looks awesome! I left a minor comment.

@eellison
Copy link
Contributor

This will break things in JIT because we have a pass that analyzes whether or not a Tensor has a gradient or not

@yf225
Copy link
Contributor

yf225 commented Sep 17, 2019

@eellison Do you mind elaborating more on the use cases that this will break? The at::Tensor::requires_grad_ API is supposed to be used from the C++ frontend, which I think shouldn't break JIT?

@eellison
Copy link
Contributor

eellison commented Sep 17, 2019

@eellison Do you mind elaborating more on the use cases that this will break? The at::Tensor::requires_grad_ API is supposed to be used from the C++ frontend, which I think shouldn't break JIT?

@eellison Do you mind elaborating more on the use cases that this will break? The at::Tensor::requires_grad_ API is supposed to be used from the C++ frontend, which I think shouldn't break JIT?

All of the functions in native_functions.yaml are exposed in JIT. We would like to land this in JIT as well just have to update our analysis pass before this lands.

pbelevich added a commit that referenced this pull request Sep 17, 2019
ghstack-source-id: bd597e0
Pull Request resolved: #26332
Copy link
Contributor

@yf225 yf225 left a comment

Choose a reason for hiding this comment

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

Thanks a lot @pbelevich !

@pbelevich pbelevich requested a review from yf225 October 9, 2019 17:19
Copy link
Contributor

@yf225 yf225 left a comment

Choose a reason for hiding this comment

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

Thanks a lot @pbelevich!

@eellison
Copy link
Contributor

eellison commented Oct 9, 2019

@bwasti showed me an example of c10 registration and I added requires_grad_ to torch/csrc/jit/register_prim_ops.cpp

Could you remove the register_prim_ops implementation ? Those are for registering ops that are not bound to the torch c++ library. There is no need to have it in C++ and in register_prim_ops, since the c++ ops are exposed to the JIT already.

return 0;
},
aliasAnalysisConservative()),
Operator(
Copy link
Contributor

@bwasti bwasti Oct 9, 2019

Choose a reason for hiding this comment

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

This looks good and should fix the issue in JIT

Copy link
Contributor

@bwasti bwasti left a comment

Choose a reason for hiding this comment

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

assuming all tests pass

@pbelevich
Copy link
Contributor Author

@eellison @bwasti I'm very confused with your comments. Should I change anything or not?

@bwasti
Copy link
Contributor

bwasti commented Oct 9, 2019

@pbelevich edited my comment

@bwasti
Copy link
Contributor

bwasti commented Oct 9, 2019

@eellison , this one wouldn't be exposed correctly. note the "conservative" annotation in the prim_ops registration.

@eellison
Copy link
Contributor

eellison commented Oct 9, 2019

@eellison , this one wouldn't be exposed correctly. note the "conservative" annotation in the prim_ops registration.

Do you know that the register_prim_ops schema is being matched to before the native_functions one?

@bwasti
Copy link
Contributor

bwasti commented Oct 9, 2019

@eellison
Copy link
Contributor

eellison commented Oct 9, 2019

@eellison that seems to be how it is used in the file,
https://bddppq.github.io/codebrowser/pytorch/pytorch/torch/csrc/jit/register_prim_ops.cpp.html#2823

I don't know if bugs have crept in -- the c10 dispatch code is extremely hard to understand. I believe, if there is an issue, there will be a runtime error
https://bddppq.github.io/codebrowser/pytorch/pytorch/aten/src/ATen/core/dispatch/Dispatcher.cpp.html#63

From looking at the code I would suspect this should raise, since it's the same schema with a different options. If doesn't than i would think that's a bug. cc @smessmer

@pbelevich pbelevich requested a review from smessmer October 10, 2019 14:18
Copy link
Contributor

@smessmer smessmer left a comment

Choose a reason for hiding this comment

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

lgtm

@eellison
Copy link
Contributor

Copy link
Contributor

@smessmer smessmer left a comment

Choose a reason for hiding this comment

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

oh wait I'm a bit confused here. The entry in native_functions.yaml should already create a jit op for this in register_aten_ops.cpp. Why is the one in register_prim_ops.cpp needed?

@eellison This doesn't crash because register_prim_ops.cpp isn't the c10 operator library, that's a shortcut directly to jit which should only be used if absolutely needed.

@pbelevich
Copy link
Contributor Author

@smessmer @bwasti can you please reach a consensus?

Copy link
Contributor

@smessmer smessmer left a comment

Choose a reason for hiding this comment

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

withdrawing my concerns with recent changes

@facebook-github-bot
Copy link
Contributor

@pbelevich merged this pull request in 46f96d1.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Oct 24, 2019
Summary: Pull Request resolved: pytorch/pytorch#26332

Test Plan: Imported from OSS

Differential Revision: D17427575

Pulled By: pbelevich

fbshipit-source-id: 5500169a4fa0ef9cc2a7272e13b6e2d89df09260
@facebook-github-bot facebook-github-bot deleted the gh/pbelevich/8/head branch October 28, 2019 22:17
thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
Summary: Pull Request resolved: pytorch#26332

Test Plan: Imported from OSS

Differential Revision: D17427575

Pulled By: pbelevich

fbshipit-source-id: 5500169a4fa0ef9cc2a7272e13b6e2d89df09260
},
aliasAnalysisConservative()),
Operator(
"aten::requires_grad_(Tensor(a!) self, bool _requires_grad=True) -> Tensor(a!)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

@pbelevich hey any reason we have this schema with _requires_grad instead of requires_grad? This is creating discrepancy between the jit api and the python api as it take requires_grad..

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

Labels

Merged module: autograd Related to torch.autograd, and the autograd engine in general module: cpp Related to C++ API module: internals Related to internal abstractions in c10 and ATen module: pybind Related to our Python bindings / interactions with other Python libraries oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.