class_docstr: Implements DeepLIFT algorithm based on the following paper:
  Learning Important Features Through Propagating Activation Differences,
  Avanti Shrikumar, et. al.
  https://arxiv.org/abs/1704.02685
  
  and the gradient formulation proposed in:
  Towards better understanding of gradient-based attribution methods for
  deep neural networks,  Marco Ancona, et.al.
  https://openreview.net/pdf?id=Sy21R9JAW
  
  This implementation supports only Rescale rule. RevealCancel rule will
  be supported in later releases.
  In addition to that, in order to keep the implementation cleaner, DeepLIFT
  for internal neurons and layers extends current implementation and is
  implemented separately in LayerDeepLift and NeuronDeepLift.
  Although DeepLIFT's(Rescale Rule) attribution quality is comparable with
  Integrated Gradients, it runs significantly faster than Integrated
  Gradients and is preferred for large datasets.
  
  Currently we only support a limited number of non-linear activations
  but the plan is to expand the list in the future.
  
  Note: As we know, currently we cannot access the building blocks,
  of PyTorch's built-in LSTM, RNNs and GRUs such as Tanh and Sigmoid.
  Nonetheless, it is possible to build custom LSTMs, RNNS and GRUs
  with performance similar to built-in ones using TorchScript.
  More details on how to build custom RNNs can be found here:
  https://pytorch.org/blog/optimizing-cuda-rnn-with-torchscript/
class_docstr_tok: ["Implements","DeepLIFT","algorithm","based","on","the","following","paper",":","Learning","Important","Features","Through","Propagating","Activation","Differences",",","Avanti","Shrikumar",",","et",".","al",".","https",":","\/\/arxiv.org\/abs\/1704.02685","and","the","gradient","formulation","proposed","in",":","Towards","better","understanding","of","gradient-based","attribution","methods","for","deep","neural","networks",",","Marco","Ancona",",","et.al",".","https",":","\/\/openreview.net\/pdf","?","id=Sy21R9JAW","This","implementation","supports","only","Rescale","rule",".","RevealCancel","rule","will","be","supported","in","later","releases",".","In","addition","to","that",",","in","order","to","keep","the","implementation","cleaner",",","DeepLIFT","for","internal","neurons","and","layers","extends","current","implementation","and","is","implemented","separately","in","LayerDeepLift","and","NeuronDeepLift",".","Although","DeepLIFT","'s","(","Rescale","Rule",")","attribution","quality","is","comparable","with","Integrated","Gradients",",","it","runs","significantly","faster","than","Integrated","Gradients","and","is","preferred","for","large","datasets",".","Currently","we","only","support","a","limited","number","of","non-linear","activations","but","the","plan","is","to","expand","the","list","in","the","future",".","Note",":","As","we","know",",","currently","we","can","not","access","the","building","blocks",",","of","PyTorch","'s","built-in","LSTM",",","RNNs","and","GRUs","such","as","Tanh","and","Sigmoid",".","Nonetheless",",","it","is","possible","to","build","custom","LSTMs",",","RNNS","and","GRUs","with","performance","similar","to","built-in","ones","using","TorchScript",".","More","details","on","how","to","build","custom","RNNs","can","be","found","here",":","https",":","\/\/pytorch.org\/blog\/optimizing-cuda-rnn-with-torchscript\/"]
docstr: For the modules that perform in-place operations such as ReLUs, we cannot
  use inputs from forward hooks. This is because in that case inputs
  and outputs are the same. We need access the inputs in pre-hooks and
  set necessary hooks on inputs there.
docstr_tok: ["For","the","modules","that","perform","in-place","operations","such","as","ReLUs",",","we","can","not","use","inputs","from","forward","hooks",".","This","is","because","in","that","case","inputs","and","outputs","are","the","same",".","We","need","access","the","inputs","in","pre-hooks","and","set","necessary","hooks","on","inputs","there","."]
code: def _forward_pre_hook(
      self, module: Module, inputs: Union[Tensor, Tuple[Tensor, ...]]
  ) -> None:
      """
      For the modules that perform in-place operations such as ReLUs, we cannot
      use inputs from forward hooks. This is because in that case inputs
      and outputs are the same. We need access the inputs in pre-hooks and
      set necessary hooks on inputs there.
      """
      inputs = _format_tensor_into_tuples(inputs)
      module.input = inputs[0].clone().detach()
      module.input_grad_fns = inputs[0].grad_fn  # type: ignore
  
      def tensor_backward_hook(grad):
          if module.saved_grad is None:
              raise RuntimeError(
                  """Module {} was detected as not supporting correctly module
                          backward hook. You should modify your hook to ignore the given
                          grad_inputs (recompute them by hand if needed) and save the
                          newly computed grad_inputs in module.saved_grad. See MaxPool1d
                          as an example.""".format(
                      module
                  )
              )
          return module.saved_grad
  
      # the hook is set by default but it will be used only for
      # failure cases and will be removed otherwise
      handle = inputs[0].register_hook(tensor_backward_hook)
      module.input_hook = handle
  
imports: import typing
  import warnings
  from typing import Any, Callable, List, Tuple, Union, cast
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.hooks import RemovableHandle
  from captum.attr._utils.attribution import GradientAttribution
  from captum.attr._utils.common import ExpansionTypes, _call_custom_attribution_func, _compute_conv_delta_and_format_attrs, _expand_additional_forward_args, _expand_target, _format_additional_forward_args, _format_attributions, _format_baseline, _format_callable_baseline, _format_input, _format_tensor_into_tuples, _is_tuple, _run_forward, _tensorize_baseline, _validate_input
  from captum.attr._utils.gradient import apply_gradient_requirements, undo_gradient_requirements
  from captum.attr._utils.typing import BaselineType, Literal, TargetType, TensorOrTupleOfTensorsGeneric
label_desc: Use image node_id 8 for calling the DeepLift obj's underlying member method code with example usage: obj._forward_pre_hook(module, inputs) and returns: module