-
Notifications
You must be signed in to change notification settings - Fork 26.3k
out-variant for torch.batch_norm_elemt #27621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
yes, compilation error, the same is I had got locally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a Tensor& here and I think your problem will go away. You might need to adjust your inner code to directly return output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is returning a reference to a local variable (tensor) safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I'm understanding your suggestion. Are you suggesting replacing Tensor as the return type of batch_norm_elemt_cuda_out and batch_norm_elemt_cuda by Tensor&?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we change return type, in theory, the error should persist: Oct 09 19:39:07 /var/lib/jenkins/workspace/aten/src/ATen/native/cuda/Normalization.cu(67): error: cannot overload functions distinguished by return type alone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is returning a reference to a local variable (tensor) safe?
No it is not. However, the convention is that _out functions return the reference for out that was passed in. It should look something like:
Tensor& foo_out(Tensor& output, const Tensor& input) {
// ...
return output;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we change return type, in theory, the error should persist
I'm not sure I follow. There might be other errors in your code, but your error message is consistent with this C++ code:
// Auto-generated in NativeFunctions.h
Tensor& foo_out(Tensor& output, const Tensor& input);
// Your implementation
Tensor foo_out(Tensor& output, const Tensor& input) {
...
}
This is exactly the situation a C++ compiler will complain about an overload distinguished only in return type.
By the way, you can find out exactly what signature ATen is expecting by inspecting the generated native functions header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ezyang Thanks for explanation! I now understand you, I'll try the suggested return type for the _out-variant.
|
clang-tidy check error seems unrelated And compilation fails with: Do I need to rebase? Also, https://github.com/vadimkantorov/pytorch/blob/master/aten/src/ATen/native/cuda/Normalization.cuh/#L678-L679 in an extreme case could reallocate, and then returning a reference to |
Yep.
You should error in that case. Replace this with a |
a = torch.rand(2,3,4)
a_ = a.transpose(-1, -2)
b_ = someltwisefunc(a_.reshape(2, -1)) # reshape seems to reallocate (checked by data_ptr), view will error out
b = b_.view_as(a) |
|
Squashed and rebased. I hope it's done correctly (I added remote upstream, fetched it, squashed commits and then rebased, it's my first time using git remote add upstream https://github.com/pytorch/pytorch.git
git fetch upstream master
git rebase -i HEAD~2 # pick + squash
git rebase upstream/master
git push -fIf compilation works, I'll replace |
|
Build failure is real |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view here, to avoid realloc
|
The rest of the code looks reasonable! |
Is it because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way would be to remove returns here and replace them by return output at the end. Should I do that @ezyang?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I would do.
Tensor -> Tensor& as out-variant return type batch_norm_elemt_cuda_template: reshape -> view for output batch_norm_elemt_cuda_template return type: Tensor& -> void
|
finally it compiled :) |
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Following dicussion with ezyang in pytorch/pytorch#26288 Pull Request resolved: pytorch/pytorch#27621 Differential Revision: D17978858 Pulled By: ezyang fbshipit-source-id: f843b691a67f1dc48b87ed6a633007d193150cf7
Summary: Following dicussion with ezyang in pytorch#26288 Pull Request resolved: pytorch#27621 Differential Revision: D17978858 Pulled By: ezyang fbshipit-source-id: f843b691a67f1dc48b87ed6a633007d193150cf7
Following dicussion with @ezyang in #26288