@albanD's #15219 augmented with SavedVariable::weak_grad_fn_ (#23502)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/10532 via https://github.com/pytorch/pytorch/issues/15219 and lots of analysis by albanD.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/23502
Differential Revision: D16881340
Pulled By: ezyang
fbshipit-source-id: b483fe6c89ed9d27674c3347c043fe509ba80007