code: def add_interim_values(module, input, output):
      """The forward hook used to save interim tensors, detached
      from the graph. Used to calculate the multipliers
      """
      try:
          del module.x
      except AttributeError:
          pass
      try:
          del module.y
      except AttributeError:
          pass
      module_type = module.__class__.__name__
      if module_type in op_handler:
          func_name = op_handler[module_type].__name__
          # First, check for cases where we don't need to save the x and y tensors
          if func_name == "passthrough":
              pass
          else:
              # check only the 0th input varies
              for i in range(len(input)):
                  if i != 0 and type(output) is tuple:
                      assert (
                          input[i] == output[i]
                      ), "Only the 0th input may vary!"
              # if a new method is added, it must be added here too. This ensures tensors
              # are only saved if necessary
              if func_name in ["maxpool", "nonlinear_1d"]:
                  # only save tensors if necessary
                  if type(input) is tuple:
                      setattr(
                          module,
                          "x",
                          torch.nn.Parameter(input[0].detach()),
                      )
                  else:
                      setattr(
                          module,
                          "x",
                          torch.nn.Parameter(input.detach()),
                      )
                  if type(output) is tuple:
                      setattr(
                          module,
                          "y",
                          torch.nn.Parameter(output[0].detach()),
                      )
                  else:
                      setattr(
                          module,
                          "y",
                          torch.nn.Parameter(output.detach()),
                      )
  
file_path: shap/shap/explainers/_deep/deep_pytorch.py
imports: import warnings
  import numpy
  from packaging import version
  from .._explainer import Explainer
  from .deep_utils import _check_additivity
label_desc: Use image node_id 2 for calling a global function with example usage: add_interim_values(module, input, output) without return types