Skip to content

Add support for Tuples of Modules in LayerLRP #1329

Open
@alexandrelarouche

Description

@alexandrelarouche

🚀 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions