pytorch / captum

Model interpretability and understanding for PyTorch
https://captum.ai
BSD 3-Clause "New" or "Revised" License
4.95k stars 499 forks source link

DeepLift documentation unclear #1115

Open marc-gav opened 1 year ago

marc-gav commented 1 year ago

I am trying to understand how to use LayerDeepLift and I'm reading the documentation page: https://captum.ai/api/layer.html#layer-deeplift

The object LayerDeepLift is initialized by providing a model: captum.attr.LayerDeepLift(model, layer, multiply_by_inputs=True)

But then the attribute function documentation references a forward_function the hasn't been mentioned before:

inputs (Tensor or tuple[Tensor, ...]) – Input for which layer attributions are computed. If forward_func takes a single tensor as input, a single input tensor should be provided. If forward_func takes multiple tensors as input, a tuple of the input tensors should be provided. It is assumed that for all given input tensors, dimension 0 corresponds to the number of examples (aka batch size), and if multiple input tensors are provided, the examples must be aligned appropriately.

I noticed this because LayerIntegratedGradient actually asks for a forward_func in the object intialization:

captum.attr.LayerIntegratedGradients(forward_func, layer, device_ids=None, multiply_by_inputs=True)[source]

vivekmig commented 1 year ago

Hi @marc-gav , thanks for catching this issue! You are right, the documentation should refer to model in LayerDeepLift rather than forward_func. This distinction is particularly for methods that use hooks (such as DeepLift and LRP), which require access to the model, while other methods can utilize any function (which could also be a model or a function wrapper around a model). We will update the documentation to be consistent for this.