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: Args:
  
      model (nn.Module):  The reference to PyTorch model instance.
      multiply_by_inputs (bool, optional): Indicates whether to factor
                  model inputs' multiplier in the final attribution scores.
                  In the literature this is also known as local vs global
                  attribution. If inputs' multiplier isn't factored in
                  then that type of attribution method is also called local
                  attribution. If it is, then that type of attribution
                  method is called global.
                  More detailed can be found here:
                  https://arxiv.org/abs/1711.06104
  
                  In case of DeepLift, if `multiply_by_inputs`
                  is set to True, final sensitivity scores
                  are being multiplied by (inputs - baselines).
                  This flag applies only if `custom_attribution_func` is
                  set to None.
  
      eps (float, optional): A value at which to consider output/input change
                  significant when computing the gradients for non-linear layers.
                  This is useful to adjust, depending on your model's bit depth,
                  to avoid numerical issues during the gradient computation.
                  Default: 1e-10
docstr_tok: ["Args",":","model","(","nn.Module",")",":","The","reference","to","PyTorch","model","instance",".","multiply_by_inputs","(","bool",",","optional",")",":","Indicates","whether","to","factor","model","inputs","'","multiplier","in","the","final","attribution","scores",".","In","the","literature","this","is","also","known","as","local","vs","global","attribution",".","If","inputs","'","multiplier","is","n't","factored","in","then","that","type","of","attribution","method","is","also","called","local","attribution",".","If","it","is",",","then","that","type","of","attribution","method","is","called","global",".","More","detailed","can","be","found","here",":","https",":","\/\/arxiv.org\/abs\/1711.06104","In","case","of","DeepLift",",","if","`","multiply_by_inputs","`","is","set","to","True",",","final","sensitivity","scores","are","being","multiplied","by","(","inputs","-","baselines",")",".","This","flag","applies","only","if","`","custom_attribution_func","`","is","set","to","None",".","eps","(","float",",","optional",")",":","A","value","at","which","to","consider","output\/input","change","significant","when","computing","the","gradients","for","non-linear","layers",".","This","is","useful","to","adjust",",","depending","on","your","model","'s","bit","depth",",","to","avoid","numerical","issues","during","the","gradient","computation",".","Default",":","1e-10"]
code: def __init__(
      self,
      model: Module,
      multiply_by_inputs: bool = True,
      eps: float = 1e-10,
  ) -> None:
      r"""
      Args:
  
          model (nn.Module):  The reference to PyTorch model instance.
          multiply_by_inputs (bool, optional): Indicates whether to factor
                      model inputs' multiplier in the final attribution scores.
                      In the literature this is also known as local vs global
                      attribution. If inputs' multiplier isn't factored in
                      then that type of attribution method is also called local
                      attribution. If it is, then that type of attribution
                      method is called global.
                      More detailed can be found here:
                      https://arxiv.org/abs/1711.06104
  
                      In case of DeepLift, if `multiply_by_inputs`
                      is set to True, final sensitivity scores
                      are being multiplied by (inputs - baselines).
                      This flag applies only if `custom_attribution_func` is
                      set to None.
  
          eps (float, optional): A value at which to consider output/input change
                      significant when computing the gradients for non-linear layers.
                      This is useful to adjust, depending on your model's bit depth,
                      to avoid numerical issues during the gradient computation.
                      Default: 1e-10
      """
      GradientAttribution.__init__(self, model)
      self.model = model
      self.eps = eps
      self.forward_handles: List[RemovableHandle] = []
      self.backward_handles: List[RemovableHandle] = []
      self._multiply_by_inputs = multiply_by_inputs
  
imports: import typing
  import warnings
  from typing import Any, Callable, cast, List, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from captum._utils.common import _expand_additional_forward_args, _expand_target, _format_additional_forward_args, _format_baseline, _format_output, _format_tensor_into_tuples, _is_tuple, _register_backward_hook, _run_forward, _select_targets, ExpansionTypes
  from captum._utils.gradient import apply_gradient_requirements, undo_gradient_requirements
  from captum._utils.typing import BaselineType, Literal, TargetType, TensorOrTupleOfTensorsGeneric
  from captum.attr._utils.attribution import GradientAttribution
  from captum.attr._utils.common import _call_custom_attribution_func, _compute_conv_delta_and_format_attrs, _format_callable_baseline, _tensorize_baseline, _validate_input
  from captum.log import log_usage
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.hooks import RemovableHandle
label_desc: Use image node_id 1 to create a new DeepLift object from inherited base classes: GradientAttribution with example: obj = DeepLift(model, multiply_by_inputs, eps)