chr5tphr / zennit

Zennit is a high-level framework in Python using PyTorch for explaining/exploring neural networks using attribution methods like LRP.
Other
200 stars 32 forks source link

Default Rule #51

Closed rachtibat closed 3 years ago

rachtibat commented 3 years ago

Hi,

I'd like to know which rule Zennit applies if the layer is unknown? More precisely: which rule is applied to BatchNorm2d when not using a canonizer?

I would be able to figure this out on my own with a debugger, but unfortunately VS Code and Pycharm won't let me set a breakpoint in the backward pass of Zennit, but in the forward pass it works.

Thanks!

chr5tphr commented 3 years ago

Hey Reduan,

rules modify the gradient of the modules they are applied to. If you or your composite does not assign a rule to a specific layer, the gradient is not modified, ie. the gradient is the default rule. For some layers, like activations, all built-in composites use the Pass rule, which you could also use if you do not want your layer to modify the gradient (which of course only works if your output and input have the same sizes).

If you apply the canonizer, the BatchNorm is merged into the adjacent linear layer, and becomes the identity, therefore its relevance, which is the gradient, also becomes the identity. If you do not use the canonizer, and do not set your composite to assign the Pass rule to BatchNorm layers, the relevance of the BatchNorm will simply be the gradient.

rachtibat commented 3 years ago

Hi Chris,

Thanks a lot! Now everything is clear.

Best