captum icon indicating copy to clipboard operation
captum copied to clipboard

Add support for Tuples of Modules in LayerLRP

Open alexandrelarouche opened this issue 1 year ago • 0 comments

🚀 Feature

It seems to me there is no reason why LayerLRP is restricted to lists only. It seems any ordered iterable should do the trick here. I would like us to be able to run LayerLRP with a tuple directly.

Motivation

This avoid a confusing error I encountered, namely:

  File "/home/allar/code/gfn-explain/scripts/experiments/complex_nn/inception/r_captum.py", line 74, in main
    layer_vals = layer_explainer.attribute(
  File "/home/allar/.pyenv/versions/gfn/lib/python3.10/site-packages/captum/attr/_core/layer/layer_lrp.py", line 233, in attribute
    relevances = self._get_output_relevance(output)
  File "/home/allar/.pyenv/versions/gfn/lib/python3.10/site-packages/captum/attr/_core/layer/layer_lrp.py", line 282, in _get_output_relevance
    return self._get_single_output_relevance(self.layer, output)
  File "/home/allar/.pyenv/versions/gfn/lib/python3.10/site-packages/captum/attr/_core/layer/layer_lrp.py", line 258, in _get_single_output_relevance
    normalized_relevances = layer.rule.relevance_output
AttributeError: 'tuple' object has no attribute 'rule'

Pitch

Simply add checks / modify the if statements of the class where there is a type check for list to account for tuples also.

Alternatives

N/A

Additional context

N/A

alexandrelarouche avatar Aug 15 '24 19:08 alexandrelarouche