[BC-breaking] C++ API parity: at::Tensor::grad#26150
[BC-breaking] C++ API parity: at::Tensor::grad#26150pbelevich wants to merge 7 commits intogh/pbelevich/2/basefrom
Conversation
…+ API parity: at::Tensor::grad"
|
@pbelevich Thanks for the tests! Curious did you resolve why there is a difference in behavior between Python and C++ for the following code? # Python
In [1]: import torch
In [2]: x = torch.ones(1, dtype=float, requires_grad=True)
In [3]: x.backward()
In [4]: x.grad
Out[4]: tensor([1.], dtype=torch.float64)// C++
auto tensor = torch::ones(1, at::TensorOptions().dtype(at::kFloat).requires_grad(true));
tensor.backward();
std::cout << tensor.grad() << std::endl;
// [ Tensor (undefined) ]From our earlier discussion, Python |
Pull Request resolved: #26150
Pull Request resolved: #26150
Pull Request resolved: #26150
Pull Request resolved: #26150
Pull Request resolved: #26150
Pull Request resolved: #26150
Pull Request resolved: #26150
Pull Request resolved: #26150
Pull Request resolved: #26150
Pull Request resolved: #26150
yf225
left a comment
There was a problem hiding this comment.
Thanks a lot for fixing Tensor::backward()! I believe we will need a BC-breaking note in the PR description to explain what previously working C++ API use cases would break after this PR.
yf225
left a comment
There was a problem hiding this comment.
We can land this PR after BC-breaking note is added
|
This appears to have broken the XLA build cc @ailzhang |
|
Thanks @suo! pytorch/xla#1065 will be merged soon to fix it! :D |
|
@pbelevich merged this pull request in 98ccae0. |
ghstack-source-id: 0006728 Pull Request resolved: pytorch#26150
|
where is the actual note saying what is BC breaking? |
|
ok, it looks like the BC issue is that for non-1-element tensors you no longer create the grad_output to pass through backwards. |
Summary: Pull Request resolved: pytorch#26150 Test Plan: Imported from OSS Differential Revision: D17427579 Pulled By: pbelevich fbshipit-source-id: 68d012076aa86dee9f23fad71a2d265d75f56d22
Stack from ghstack:
Pull Request resolved: #26150
Differential Revision: D17427579