Fix grad_fn bindings when saved variable freed (#56499)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/54472
Adds HANDLE_TH_ERRORS to python bindings for grad_fn attrs and updates tests.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56499
Reviewed By: albanD
Differential Revision: D27920742
Pulled By: soulitzer
fbshipit-source-id: d4f7ac8c0aa2173d25517277c393f8c66de68951