class_docstr: Computes internal influence by approximating the integral of gradients
  for a particular layer along the path from a baseline input to the
  given input.
  If no baseline is provided, the default baseline is the zero tensor.
  More details on this approach can be found here:
  https://arxiv.org/abs/1802.03788
  
  Note that this method is similar to applying integrated gradients and
  taking the layer as input, integrating the gradient of the layer with
  respect to the output.
class_docstr_tok: ["Computes","internal","influence","by","approximating","the","integral","of","gradients","for","a","particular","layer","along","the","path","from","a","baseline","input","to","the","given","input",".","If","no","baseline","is","provided",",","the","default","baseline","is","the","zero","tensor",".","More","details","on","this","approach","can","be","found","here",":","https",":","\/\/arxiv.org\/abs\/1802.03788","Note","that","this","method","is","similar","to","applying","integrated","gradients","and","taking","the","layer","as","input",",","integrating","the","gradient","of","the","layer","with","respect","to","the","output","."]
code: def _attribute(
      self,
      inputs: Tuple[Tensor, ...],
      baselines: Tuple[Union[Tensor, int, float], ...],
      target: TargetType = None,
      additional_forward_args: Any = None,
      n_steps: int = 50,
      method: str = "gausslegendre",
      attribute_to_layer_input: bool = False,
      step_sizes_and_alphas: Union[
          None, Tuple[List[float], List[float]]
      ] = None,
  ) -> Union[Tensor, Tuple[Tensor, ...]]:
      if step_sizes_and_alphas is None:
          # retrieve step size and scaling factor for specified approximation method
          step_sizes_func, alphas_func = approximation_parameters(
              method
          )
          step_sizes, alphas = step_sizes_func(n_steps), alphas_func(
              n_steps
          )
      else:
          step_sizes, alphas = step_sizes_and_alphas
  
      # Compute scaled inputs from baseline to final input.
      scaled_features_tpl = tuple(
          torch.cat(
              [
                  baseline + alpha * (input - baseline)
                  for alpha in alphas
              ],
              dim=0,
          ).requires_grad_()
          for input, baseline in zip(inputs, baselines)
      )
  
      additional_forward_args = _format_additional_forward_args(
          additional_forward_args
      )
      # apply number of steps to additional forward args
      # currently, number of steps is applied only to additional forward arguments
      # that are nd-tensors. It is assumed that the first dimension is
      # the number of batches.
      # dim -> (bsz * #steps x additional_forward_args[0].shape[1:], ...)
      input_additional_args = (
          _expand_additional_forward_args(
              additional_forward_args, n_steps
          )
          if additional_forward_args is not None
          else None
      )
      expanded_target = _expand_target(target, n_steps)
  
      # Returns gradient of output with respect to hidden layer.
      layer_gradients, _ = compute_layer_gradients_and_eval(
          forward_fn=self.forward_func,
          layer=self.layer,
          inputs=scaled_features_tpl,
          target_ind=expanded_target,
          additional_forward_args=input_additional_args,
          device_ids=self.device_ids,
          attribute_to_layer_input=attribute_to_layer_input,
      )
      # flattening grads so that we can multiply it with step-size
      # calling contiguous to avoid `memory whole` problems
      scaled_grads = tuple(
          layer_grad.contiguous().view(n_steps, -1)
          * torch.tensor(step_sizes)
          .view(n_steps, 1)
          .to(layer_grad.device)
          for layer_grad in layer_gradients
      )
  
      # aggregates across all steps for each tensor in the input tuple
      attrs = tuple(
          _reshape_and_sum(
              scaled_grad,
              n_steps,
              inputs[0].shape[0],
              layer_grad.shape[1:],
          )
          for scaled_grad, layer_grad in zip(
              scaled_grads, layer_gradients
          )
      )
      return _format_output(len(attrs) > 1, attrs)
  
file_path: captum/captum/attr/_core/layer/internal_influence.py
imports: from typing import Any, Callable, List, Tuple, Union
  import torch
  from captum._utils.common import _expand_additional_forward_args, _expand_target, _format_additional_forward_args, _format_output
  from captum._utils.gradient import compute_layer_gradients_and_eval
  from captum._utils.typing import BaselineType, TargetType
  from captum.attr._utils.approximation_methods import approximation_parameters
  from captum.attr._utils.attribution import GradientAttribution, LayerAttribution
  from captum.attr._utils.batching import _batch_attribution
  from captum.attr._utils.common import _format_input_baseline, _reshape_and_sum, _validate_input
  from captum.log import log_usage
  from torch import Tensor
  from torch.nn import Module
label_desc: Use image node_id 3 for calling the InternalInfluence obj's underlying member method code with example usage: obj._attribute(inputs, baselines, target, additional_forward_args, n_steps, method, attribute_to_layer_input, step_sizes_and_alphas) and returns: _format_output