running backward on a loss function which contain explanation
See original GitHub issueHello,
I am trying to run a backward pass on an objective function that contains an explanation. The goal is to run a manipulate attack on explanations. However, it is strange that the explanation attained by the attribute
method from captum does not require gradient even though the input for which the explanation is being computed requires gradient. For example in the following code snippet:
sm = Saliency(vgg_model)
expl = sm.attribute(x_adv, target=17)
The expl
tensor is a leaf tensor and doesn’t require gradient.
There’s further another issue with “LRP” in this application. When computing backward pass, I encounter this error:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [4096, 1000]], which is output 0 of TBackward, is at version 7; expected version 6 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
I would really appreciate it if you could help me with these issues.
Best, -Ahmad
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Loss and Loss Functions for Training Deep Learning Neural ...
Cross-entropy loss is minimized, where smaller values represent a better model than larger values. A model that predicts perfect probabilities ...
Read more >What does the backward() function do? - PyTorch Forums
The graph is used by loss.backward() to compute gradients. optimizer.zero_grad() and optimizer.step() do not affect the graph of autograd ...
Read more >pytorch - connection between loss.backward() and optimizer ...
When we do loss. backward() the process of backpropagation starts at the loss and goes through all of its parents all the way...
Read more >Neural Networks — PyTorch Tutorials 0.2.0_4 documentation
Loss Function MSELoss which computes the mean-squared error between the input and the target. So, when we call loss. backward() , the whole...
Read more >How does Backward Propagation Work in Neural Networks?
Building on this, the first step in Backward Propagation to calculate the error. In our regression problem, we shall take the loss function...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @ahmadajal , here is a workaround to obtain explanations that require gradient. We essentially need to override the default gradient function, to add an additional parameter create_graph=True, which enables higher order derivatives.
We will look into approaches to expose this option more easily, but this approach should work in the meantime, with attr requiring gradients here.
We will also look into the LRP issue further, would you be able to provide an example to reproduce this? It seems this may be related to inplace operations, would you also be able to try with replacing any inplace operations (e.g. set inplace to False on ReLUs if applicable) in your model and see if that resolves the issue?
Do we have any solution now? I also have exactly the same error when trying backward loss containing LRP explanations.