-
Couldn't load subscription status.
- Fork 25.7k
fix grad(torch.tensor()) using lift() operator #77650
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
[ghstack-poisoned]
🔗 Helpful links
❌ 1 New FailuresAs of commit 10e0553 (more details on the Dr. CI page): Expand to see more
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages
|
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.
autograd changes sound ok. I'll let Richard review the functorch side.
|
@pytorchbot merge on green |
|
Hey @bdhirsh. |
Summary: Pull Request resolved: #77650 Approved by: https://github.com/zou3519 Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/cfc87cad02e47a3a62b4328454e825748c7be4fd Reviewed By: b0noI Differential Revision: D36451898 Pulled By: bdhirsh fbshipit-source-id: 4fc62a40f275ea5a27f3f985927433224c62328a
Confirmed that this fixes pytorch/functorch#806 locally.
The problem was that in the
torch.tensor()constructor we needed to exclude both the functorch FrontMode + BackMode keys until we callat::lift, since both keys can potentially wrap their outputs intoTensorWrappers.Separately, Richard also pointed out that we want
at::lift()to be a primitive op w.r.t. functorch. Otherwise, if we have multiple layers of transforms likegrad(grad(...)), the first layer will decomposeat::lift()into a no-op, and the second layer won't seeat::lift()at all (and won't perform a second level of wrapping.I made
at::lift()a CompositeExplicitAutograd op, but also needed to explicitly op it out of autograd's view tracking / error checking logic.The idea is that technically
lifthas incorrect alias info, because the no-op kernel forliftjust returns the input tensor instead of creating a fresh one. But we don't actually want autograd to care aboutlift-liftshould never be called with arequires_grad=Truetensor.Unfortunately that still doesn't fix this extra test though. Gonna take a deeper look at why later:
Stack from ghstack: