code: def _perturb_inputs(
      inputs: Iterable[Any],
      input_roles: Tuple[int],
      baselines: Tuple[Union[int, float, Tensor], ...],
      perturbation_mask: Tuple[Union[Tensor, None], ...],
  ) -> Tuple[Any, ...]:
      """
      Perturb inputs based on perturbation mask and baselines
      """
  
      perturbed_inputs = []
      attr_inp_count = 0
  
      for inp, role in zip(inputs, input_roles):
          if role != InputRole.need_attr:
              perturbed_inputs.append(inp)
              continue
  
          pert_mask = perturbation_mask[attr_inp_count]
  
          # no perturbation is needed for this input
          if pert_mask is None:
              perturbed_inputs.append(inp)
          else:
              baseline = baselines[attr_inp_count]
  
              perturbed_inp = inp * pert_mask + baseline * (
                  1 - pert_mask
              )
              perturbed_inputs.append(perturbed_inp)
  
          attr_inp_count += 1
  
      perturbed_inputs = tuple(perturbed_inputs)
  
      return perturbed_inputs
  
file_path: captum/captum/attr/_core/dataloader_attr.py
imports: from collections import defaultdict
  from copy import copy
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
  import torch
  from captum._utils.common import _format_baseline, _format_feature_mask, _format_output, _format_tensor_into_tuples, _get_max_feature_index, _run_forward
  from captum._utils.typing import BaselineType
  from captum.attr._core.feature_ablation import FeatureAblation
  from captum.attr._utils.attribution import Attribution
  from torch import Tensor
label_desc: Use image node_id 3 for calling a global function with example usage: _perturb_inputs(inputs, input_roles, baselines, perturbation_mask) and returns: perturbed_inputs