-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[WIP] Fix cpp grad accessor API #40887
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
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.
@albanD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
💊 CI failures summary and remediationsAs of commit 9ee011a (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
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.
@albanD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
@albanD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
Even though the code compiles just fine right now (and all tests pass fine), if I add back the bad overload (for BC reasons with a warning), the compiler actually use the bad overload... cc @glaringlee |
|
@albanD |
|
I did that on my local commit. And when I recompile and run the test, the warning actually fires a lot of times (when I remove the once). Note that the exact same code with just that function removed works fine! My understanding is that the compiler uses the "non-const" overload even though it could be using the const one. And that means that potentially all users are going to see this warning if we add this overload back... |
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.
@albanD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Update the API to access grad in cpp to avoid unexpected thread safety issues.
In particular, with the current API, a check like
t.grad().defined()is not thread safe.t.mutable_grad()that should be used when getting a mutable version of the saved gradient. This function is not thread safe.Tensor& grad()API is now removed. We could not do a deprecation cycle as most of our call side use non-const Tensors that use the non-const overload. This would lead to most calls hitting the warning. This would be too verbose for all the users.