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
Debugging feature for "modified by an inplace operation" errors #15803
Comments
Question: can't you use the Here is an example where it shows up the exact line where the error occurs: import torch
with torch.autograd.set_detect_anomaly(True):
a = torch.rand(1, requires_grad=True)
c = torch.rand(1, requires_grad=True)
b = a ** 2 * c ** 2
b += 1
b *= c + a
d = b.exp_()
d *= 5
b.backward() And the stack trace:
which points directly to |
Closing as this can be obtained with |
Great, thanks. This might be a good thing to add to the section on in-place operations in the autograd mechanics tutorial. I'm happy to add a sentence or two, but the contributing doc doesn't mention how to modify tutorials or notes. |
Maybe check in https://github.com/pytorch/tutorials ? |
To clarify for other readers, the anomaly detection will not necessarily point you at the inplace operation that caused the failure. Instead, it will point you at the operation that could not compute its gradient in the backward pass. The inplace operation to blame may occur anywhere after that, modifying one of the tensors that participated in the line found by the anomaly detection. Example:
The last line will cause a |
Hi, |
Agreed with @redwrasse . anomaly detection doesn't isolate the problematic in-place operation, which can still be a real pain to track down. Definitely interested in better tools for debugging this problem. |
Feature
Better error logging for inplace operations that throw errors in automatic differentiation.
Motivation
In complex computational graphs, locating the operation causing the error is nontrivial. A feature for isolating the offending operation would save a lot of developer time.
Pitch
See here for a more concrete suggestion. To quote:
Alternatives
Just being able to log all inplace operations would be useful.
The text was updated successfully, but these errors were encountered: