-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Preserve python backtrace in autograd engine errors. #43608
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
Preserve python backtrace in autograd engine errors. #43608
Conversation
This PR attempts to address #42560. We add a "Python Traceback" component to the error message recording the original location from where the exception was thrown. This approach isn't ideal since we're extending the exception message itself. The alternative I considered was extending our Future to record this information in addition to just the message. The tricky part about this was avoiding python dependency. Ideally, I'd like to avoid a python dependency in our Future class. Even if we do avoid the python depedency in our base class by creating a subclass for python, we would still end up having a python dependency in things like autograd engine's GraphTask. For the example in #42560, the exception trace would now look like: ``` > Traceback (most recent call last): > File "test_autograd.py", line 6914, in test_preserve_backtrace > Foo.apply(t).sum().backward() > File "torch/tensor.py", line 214, in backward > torch.autograd.backward(self, gradient, retain_graph, create_graph) > File "autograd/__init__.py", line 127, in backward > allow_unreachable=True) # allow_unreachable flag > RuntimeError: something > Python Traceback (most recent call last): > File "torch/autograd/function.py", line 87, in apply > return self._forward_cls.backward(self, *args) > File "test_autograd.py", line 6909, in backward > raise ValueError("something") ``` Differential Revision: [D23337371](https://our.internmc.facebook.com/intern/diff/D23337371/) [ghstack-poisoned]
This PR attempts to address #42560. We add a "Python Traceback" component to the error message recording the original location from where the exception was thrown. This approach isn't ideal since we're extending the exception message itself. The alternative I considered was extending our Future to record this information in addition to just the message. The tricky part about this was avoiding python dependency. Ideally, I'd like to avoid a python dependency in our Future class. Even if we do avoid the python depedency in our base class by creating a subclass for python, we would still end up having a python dependency in things like autograd engine's GraphTask. For the example in #42560, the exception trace would now look like: ``` > Traceback (most recent call last): > File "test_autograd.py", line 6914, in test_preserve_backtrace > Foo.apply(t).sum().backward() > File "torch/tensor.py", line 214, in backward > torch.autograd.backward(self, gradient, retain_graph, create_graph) > File "autograd/__init__.py", line 127, in backward > allow_unreachable=True) # allow_unreachable flag > RuntimeError: something > Python Traceback (most recent call last): > File "torch/autograd/function.py", line 87, in apply > return self._forward_cls.backward(self, *args) > File "test_autograd.py", line 6909, in backward > raise ValueError("something") ``` Differential Revision: [D23337371](https://our.internmc.facebook.com/intern/diff/D23337371/) ghstack-source-id: 110722744 Pull Request resolved: #43608
|
Hi, I don't think that match the issue. For example, the |
As I mentioned in the PR summary, to propagate the original exception we need to store this information as part of the Future which would incur a python dependency: "This approach isn't ideal since we're extending the exception message itself. |
What I had in mind is to save it as a pytorch/torch/csrc/autograd/engine.cpp Line 391 in f531815
|
We probably need to save the |
|
Abandoning in favor of #43684. |
Stack from ghstack:
This PR attempts to address #42560. We add a "Python Traceback"
component to the error message recording the original location from where the
exception was thrown.
This approach isn't ideal since we're extending the exception message itself.
The alternative I considered was extending our Future to record this
information in addition to just the message. The tricky part about this was
avoiding python dependency. Ideally, I'd like to avoid a python dependency in
our Future class. Even if we do avoid the python depedency in our base class by
creating a subclass for python, we would still end up having a python
dependency in things like autograd engine's GraphTask.
For the example in #42560, the exception trace would now look like:
Differential Revision: D23337371