code: def infidelity_perturb_func_decorator(
      multipy_by_inputs: bool = True,
  ) -> Callable:
      r"""An auxiliary, decorator function that helps with computing
      perturbations given perturbed inputs. It can be useful for cases
      when `pertub_func` returns only perturbed inputs and we
      internally compute the perturbations as
      (input - perturbed_input) / (input - baseline) if
      multipy_by_inputs is set to True and
      (input - perturbed_input) otherwise.
  
      If users decorate their `pertub_func` with
      `@infidelity_perturb_func_decorator` function then their `pertub_func`
      needs to only return perturbed inputs.
  
      Args:
  
          multipy_by_inputs (bool): Indicates whether model inputs'
                  multiplier is factored in the computation of
                  attribution scores.
  
      """
  
      def sub_infidelity_perturb_func_decorator(
          pertub_func: Callable,
      ) -> Callable:
          r"""
          Args:
  
              pertub_func(Callable): Input perturbation function that takes inputs
                  and optionally baselines and returns perturbed inputs
  
          Returns:
  
              default_perturb_func(Callable): Internal default perturbation
              function that computes the perturbations internally and returns
              perturbations and perturbed inputs.
  
          Examples::
              >>> @infidelity_perturb_func_decorator(True)
              >>> def perturb_fn(inputs):
              >>>    noise = torch.tensor(np.random.normal(0, 0.003,
              >>>                         inputs.shape)).float()
              >>>    return inputs - noise
              >>> # Computes infidelity score using `perturb_fn`
              >>> infidelity = infidelity(model, perturb_fn, input, ...)
  
          """
  
          def default_perturb_func(
              inputs: TensorOrTupleOfTensorsGeneric,
              baselines: BaselineType = None,
          ):
              r""" """
              inputs_perturbed = (
                  pertub_func(inputs, baselines)
                  if baselines is not None
                  else pertub_func(inputs)
              )
              inputs_perturbed = _format_tensor_into_tuples(
                  inputs_perturbed
              )
              inputs = _format_tensor_into_tuples(inputs)
              baselines = _format_baseline(baselines, inputs)
              if baselines is None:
                  perturbations = tuple(
                      safe_div(
                          input - input_perturbed,
                          input,
                          default_denom=1.0,
                      )
                      if multipy_by_inputs
                      else input - input_perturbed
                      for input, input_perturbed in zip(
                          inputs, inputs_perturbed
                      )
                  )
              else:
                  perturbations = tuple(
                      safe_div(
                          input - input_perturbed,
                          input - baseline,
                          default_denom=1.0,
                      )
                      if multipy_by_inputs
                      else input - input_perturbed
                      for input, input_perturbed, baseline in zip(
                          inputs, inputs_perturbed, baselines
                      )
                  )
              return perturbations, inputs_perturbed
  
          return default_perturb_func
  
      return sub_infidelity_perturb_func_decorator
  
file_path: captum/captum/metrics/_core/infidelity.py
imports: from typing import Any, Callable, cast, Tuple, Union
  import torch
  from captum._utils.common import _expand_additional_forward_args, _expand_target, _format_additional_forward_args, _format_baseline, _format_tensor_into_tuples, _run_forward, ExpansionTypes, safe_div
  from captum._utils.typing import BaselineType, TargetType, TensorOrTupleOfTensorsGeneric
  from captum.log import log_usage
  from captum.metrics._utils.batching import _divide_and_aggregate_metrics
  from torch import Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: infidelity_perturb_func_decorator(multipy_by_inputs) and returns: sub_infidelity_perturb_func_decorator, default_perturb_func, perturbations,  inputs_perturbed