code: def test_tracin_xor(
      self,
      reduction: Optional[str],
      tracin_constructor: Callable,
      mode: str,
      use_gpu: bool,
  ) -> None:
      with tempfile.TemporaryDirectory() as tmpdir:
          batch_size = 4
  
          net, dataset = self._test_tracin_xor_setup(tmpdir, use_gpu)
  
          testset = F.normalize(
              torch.empty(100, 2).normal_(mean=0, std=0.5), dim=1
          )
          mask = ~torch.logical_xor(
              testset[:, 0] > 0, testset[:, 1] > 0
          )
          testlabels = (
              torch.where(mask, torch.tensor(1), torch.tensor(-1))
              .unsqueeze(1)
              .float()
          )
          if use_gpu:
              testset = testset.cuda()
              testlabels = testlabels.cuda()
  
          self.assertTrue(callable(tracin_constructor))
  
          if mode == "check_idx":
              self.assertTrue(isinstance(reduction, str))
              criterion = nn.MSELoss(reduction=cast(str, reduction))
  
              tracin = tracin_constructor(
                  net,
                  dataset,
                  tmpdir,
                  batch_size,
                  criterion,
              )
              test_scores = tracin.influence((testset, testlabels))
              idx = torch.argsort(test_scores, dim=1, descending=True)
              # check that top 5 influences have matching binary classification
              for i in range(len(idx)):
                  influence_labels = dataset.labels[idx[i][0:5], 0]
                  self.assertTrue(
                      torch.all(testlabels[i, 0] == influence_labels)
                  )
  
          if mode == "sample_wise_trick":
              criterion = nn.MSELoss(reduction="none")
  
              tracin = tracin_constructor(
                  net,
                  dataset,
                  tmpdir,
                  batch_size,
                  criterion,
                  sample_wise_grads_per_batch=False,
              )
  
              # With sample-wise trick
              criterion = nn.MSELoss(reduction="sum")
              tracin_sample_wise_trick = tracin_constructor(
                  net,
                  dataset,
                  tmpdir,
                  batch_size,
                  criterion,
                  sample_wise_grads_per_batch=True,
              )
              test_scores = tracin.influence((testset, testlabels))
              test_scores_sample_wise_trick = (
                  tracin_sample_wise_trick.influence(
                      (testset, testlabels)
                  )
              )
              assertTensorAlmostEqual(
                  self, test_scores, test_scores_sample_wise_trick
              )
  
file_path: captum/tests/influence/_core/test_tracin_xor.py
imports: import os
  import tempfile
  from collections import OrderedDict
  from typing import Callable, cast, Optional
  import torch
  import torch.nn
  import torch.nn.functional
  from captum.influence._core.tracincp import TracInCP
  from parameterized import parameterized
  from tests.helpers.basic import assertTensorAlmostEqual, BaseTest
  from tests.influence._utils.common import _wrap_model_in_dataparallel, BasicLinearNet, BinaryDataset, build_test_name_func, DataInfluenceConstructor
label_desc: Use image node_id 2 for calling the TestTracInXOR obj's underlying member method code with example usage: obj.test_tracin_xor(reduction, tracin_constructor, mode, use_gpu) without return types