-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Don't end on inplace operators in einsum #22111
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
apaszke
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.
I'm ok with merging this, but we should also understand why is an in-place operation at the end of a Function a problem.
| for (int i = dim-1; i>=0; i--) | ||
| if (sum_dims[i]) | ||
| result.squeeze_(i); | ||
| sizes.erase(sizes.begin() + i); |
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.
nit: can you please add braces here? Braceless nested statements make me nervous 😬
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.
Me, too, even if I'm the one to blame for them in the first place.
|
So in terms of root cause we can take
|
|
Which is... reasonable? I mean, if the |
|
Einsum may legitimately return a view, so maybe Function should handle finding a view with grad_fn?
|
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.
@soumith is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Returning the result of an inplace `squeeze_` in `einsum` (which itself is traced) interacts badly with `autograd.Function`. I must admit that I'm not 100% certain whether it should be necessary to change this, but I consider this a good change overall. Fixes: pytorch/pytorch#22072 Pull Request resolved: pytorch/pytorch#22111 Differential Revision: D15974990 Pulled By: soumith fbshipit-source-id: 477e7f23833f02999085f665c175d062e7d32acd
Returning the result of an inplace
squeeze_ineinsum(which itself is traced) interacts badly withautograd.Function.I must admit that I'm not 100% certain whether it should be necessary to change this, but I consider this a good change overall.
Fixes: #22072