docstr: attrib_type: 'vanilla', 'smoothgrad', 'smoothgrad_sq', 'vargrad'
code: def _compute_attribution_and_evaluate(
      self,
      model: Module,
      inputs: TensorOrTupleOfTensorsGeneric,
      baselines: BaselineType = None,
      target: Union[None, int] = None,
      additional_forward_args: Any = None,
      type: str = "vanilla",
      approximation_method: str = "gausslegendre",
      multiply_by_inputs=True,
      nt_samples_batch_size=None,
  ) -> Tuple[Tensor, ...]:
      r"""
      attrib_type: 'vanilla', 'smoothgrad', 'smoothgrad_sq', 'vargrad'
      """
      ig = IntegratedGradients(
          model, multiply_by_inputs=multiply_by_inputs
      )
      self.assertEqual(ig.multiplies_by_inputs, multiply_by_inputs)
      if not isinstance(inputs, tuple):
          inputs = (inputs,)  # type: ignore
      inputs: Tuple[Tensor, ...]
  
      if baselines is not None and not isinstance(baselines, tuple):
          baselines = (baselines,)
  
      if baselines is None:
          baselines = _tensorize_baseline(inputs, _zeros(inputs))
  
      if type == "vanilla":
          attributions, delta = ig.attribute(
              inputs,
              baselines,
              additional_forward_args=additional_forward_args,
              method=approximation_method,
              n_steps=500,
              target=target,
              return_convergence_delta=True,
          )
          model.zero_grad()
          attributions_without_delta, delta = ig.attribute(
              inputs,
              baselines,
              additional_forward_args=additional_forward_args,
              method=approximation_method,
              n_steps=500,
              target=target,
              return_convergence_delta=True,
          )
          model.zero_grad()
          self.assertEqual([inputs[0].shape[0]], list(delta.shape))
          delta_external = ig.compute_convergence_delta(
              attributions,
              baselines,
              inputs,
              target=target,
              additional_forward_args=additional_forward_args,
          )
          assertTensorAlmostEqual(
              self, delta, delta_external, delta=0.0, mode="max"
          )
      else:
          nt = NoiseTunnel(ig)
          n_samples = 5
          attributions, delta = nt.attribute(
              inputs,
              nt_type=type,
              nt_samples=n_samples,
              stdevs=0.00000002,
              baselines=baselines,
              target=target,
              additional_forward_args=additional_forward_args,
              method=approximation_method,
              n_steps=500,
              return_convergence_delta=True,
              nt_samples_batch_size=nt_samples_batch_size,
          )
          attributions_without_delta = nt.attribute(
              inputs,
              nt_type=type,
              nt_samples=n_samples,
              stdevs=0.00000002,
              baselines=baselines,
              target=target,
              additional_forward_args=additional_forward_args,
              method=approximation_method,
              n_steps=500,
              nt_samples_batch_size=3,
          )
          self.assertEqual(nt.multiplies_by_inputs, multiply_by_inputs)
          self.assertEqual(
              [inputs[0].shape[0] * n_samples], list(delta.shape)
          )
  
      for input, attribution in zip(inputs, attributions):
          self.assertEqual(attribution.shape, input.shape)
      if multiply_by_inputs:
          assertTensorAlmostEqual(
              self, delta, torch.zeros(delta.shape), 0.07, "max"
          )
  
      # compare attributions retrieved with and without
      # `return_convergence_delta` flag
  
      for attribution, attribution_without_delta in zip(
          attributions, attributions_without_delta
      ):
          assertTensorAlmostEqual(
              self, attribution, attribution_without_delta, delta=0.05
          )
  
      return cast(Tuple[Tensor, ...], attributions)
  
imports: import unittest
  from typing import Any, cast, Tuple, Union
  import torch
  from captum._utils.common import _zeros
  from captum._utils.typing import BaselineType, Tensor, TensorOrTupleOfTensorsGeneric
  from captum.attr._core.integrated_gradients import IntegratedGradients
  from captum.attr._core.noise_tunnel import NoiseTunnel
  from captum.attr._utils.common import _tensorize_baseline
  from tests.helpers.basic import assertTensorAlmostEqual, BaseTest
  from tests.helpers.basic_models import BasicModel, BasicModel2, BasicModel3, BasicModel4_MultiArgs, BasicModel5_MultiArgs, BasicModel6_MultiTensor, BasicModel_MultiLayer
  from torch.nn import Module
label_desc: Use image node_id 40 for calling the Test obj's underlying member method code with example usage: obj._compute_attribution_and_evaluate(model, inputs, baselines, target, additional_forward_args, type, approximation_method, multiply_by_inputs, nt_samples_batch_size) and returns: cast