code: def test_tracin_self_influence(
      self,
      reduction: str,
      tracin_constructor: Callable,
      unpack_inputs: bool,
      use_gpu: Union[bool, str],
  ) -> None:
      with tempfile.TemporaryDirectory() as tmpdir:
          (
              net,
              train_dataset,
          ) = get_random_model_and_data(
              tmpdir,
              unpack_inputs,
              False,
              use_gpu,
          )
  
          # compute tracin_scores of training data on training data
          criterion = nn.MSELoss(reduction=reduction)
          batch_size = 5
  
          tracin = tracin_constructor(
              net,
              train_dataset,
              tmpdir,
              batch_size,
              criterion,
          )
          train_scores = tracin.influence(
              _format_batch_into_tuple(
                  train_dataset.samples,
                  train_dataset.labels,
                  unpack_inputs,
              ),
              k=None,
          )
          # calculate self_tracin_scores
          self_tracin_scores = tracin.self_influence()
  
          # check that self_tracin scores equals the diagonal of influence scores
          assertTensorAlmostEqual(
              self,
              torch.diagonal(train_scores),
              self_tracin_scores,
              delta=0.01,
              mode="max",
          )
  
          # check that setting `outer_loop_by_checkpoints=False` and
          # `outer_loop_by_checkpoints=True` gives the same self influence scores
          # this test is only relevant for implementations of `TracInCPBase`, as
          # implementations of `InfluenceFunctionBase` do not use checkpoints.
          if isinstance(tracin, TracInCPBase):
              self_tracin_scores_by_checkpoints = (
                  tracin.self_influence(  # type: ignore
                      DataLoader(train_dataset, batch_size=batch_size),
                      outer_loop_by_checkpoints=True,
                  )
              )
              assertTensorAlmostEqual(
                  self,
                  self_tracin_scores_by_checkpoints,
                  self_tracin_scores,
                  delta=0.01,
                  mode="max",
              )
  
file_path: captum/tests/influence/_core/test_tracin_self_influence.py
imports: import tempfile
  from typing import Callable, Union
  import torch
  import torch.nn
  from captum.influence._core.arnoldi_influence_function import ArnoldiInfluenceFunction
  from captum.influence._core.influence_function import NaiveInfluenceFunction
  from captum.influence._core.tracincp import TracInCP, TracInCPBase
  from captum.influence._core.tracincp_fast_rand_proj import TracInCPFast
  from parameterized import parameterized
  from tests.helpers.basic import assertTensorAlmostEqual, BaseTest
  from tests.influence._utils.common import _format_batch_into_tuple, build_test_name_func, DataInfluenceConstructor, get_random_model_and_data
  from torch.utils.data import DataLoader
label_desc: Use image node_id 1 for calling the TestTracInSelfInfluence obj's underlying member method code with example usage: obj.test_tracin_self_influence(reduction, tracin_constructor, unpack_inputs, use_gpu) without return types