Closed chr5tphr closed 1 year ago
How far has the work progressed? Actually, this is excactly want I would need for my research. It would be awesome if zennit had this functionality or at least a workaround for further research and testing.
Edit: I tried and failed to get the gradient of and attribution map (relevances).
Hey @HeinrichAD
thanks for the bump!
I have pushed a draft version in #159 and will try to get around finishing this up the following days. I have not yet fully tested this, but if you are feeling brave, you can try it out:
$ pip install git+https://github.com/chr5tphr/zennit.git@second-order-gradients
Here's an example of how to compute the gradient (of a function of) the attribution wrt. the input:
Thank you for the fast response and for your commitment. I will test it, maybe not today, but tomorrow. I will let you know if I succeeded (or not).
I added my comments/feedback to the pull request itself.
I am currently working on supporting second-order gradients, i.e. gradients of the modified gradients, which is used for example to compute adversarial explanations. The current issue which prevents second order gradients is that the gradient modification introduced by rules will also be applied when in the second-order backward pass. This will prevented by disabling the modification temporarily when computing the second-order gradient, likely using something like a
no_modification
context for composites/attributors/rules.As also pointed out in #125, handles are not stored for the backward hooks for tensors. Storing and removing the hooks before the second-order backward pass would correctly compute the modified-gradient derivatives, although then the same graph cannot be used to compute the modified gradient for a different gradient output. By adding the context, I am considering to also enable complete removal of the tensor backward hooks.