Appropriately handle exceptions in autograd engine. (#36019)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/36019
Once the autograd engine is finished with a GraphTask it would call
`markCompleted` on the Future. This could trigger callbacks on the Future that
could throw exceptions.
If one of the callbacks did throw an exception, we would call setErrorIfNeeded,
which would be no-op since the Future is already marked as completed. This
would effectively mean we would be swallowing exceptions. To avoid this, we do
the following:
1) Rethrow the exception in `mark_graph_task_completed`.
2) In `setErrorIfNeeded`, log the error if we are ignoring it.
ghstack-source-id: 101607329
Test Plan: Verified appropriate logging.
Differential Revision: D20854806
fbshipit-source-id: 76bdf403cfd6d92f730ca1483ad5dba355f83e58