docstr: checks that 2 implementations of `InfluenceFunctionBase` return the same
  output, where the output is either self influence scores, or influence scores,
  as determined by the `mode` input. this is a helper used by other tests. the
  implementations are compared using the same data, but the model and saved
  checkpoints can be different, and is specified using the `model_type` argument.
docstr_tok: ["checks","that","2","implementations","of","`","InfluenceFunctionBase","`","return","the","same","output",",","where","the","output","is","either","self","influence","scores",",","or","influence","scores",",","as","determined","by","the","`","mode","`","input",".","this","is","a","helper","used","by","other","tests",".","the","implementations","are","compared","using","the","same","data",",","but","the","model","and","saved","checkpoints","can","be","different",",","and","is","specified","using","the","`","model_type","`","argument","."]
code: def _test_compare_implementations(
      self,
      model_type: str,
      influence_constructor_1: Callable,
      influence_constructor_2: Callable,
      delta: float,
      mode: str,
      unpack_inputs: bool,
      use_gpu: Union[bool, str],
  ) -> None:
      """
      checks that 2 implementations of `InfluenceFunctionBase` return the same
      output, where the output is either self influence scores, or influence scores,
      as determined by the `mode` input. this is a helper used by other tests. the
      implementations are compared using the same data, but the model and saved
      checkpoints can be different, and is specified using the `model_type` argument.
      """
      with tempfile.TemporaryDirectory() as tmpdir:
          (
              net,
              train_dataset,
              hessian_samples,
              hessian_labels,
              test_samples,
              test_labels,
          ) = get_random_model_and_data(
              tmpdir,
              unpack_inputs,
              return_test_data=True,
              use_gpu=use_gpu,
              return_hessian_data=True,
              model_type=model_type,
          )
  
          train_dataset = DataLoader(train_dataset, batch_size=5)
  
          hessian_dataset = (
              ExplicitDataset(hessian_samples, hessian_labels, use_gpu)
              if not unpack_inputs
              else UnpackDataset(
                  hessian_samples, hessian_labels, use_gpu
              )
          )
          hessian_dataset = DataLoader(hessian_dataset, batch_size=5)
  
          criterion = nn.MSELoss(reduction="none")
          batch_size = None
  
          influence_1 = influence_constructor_1(
              net,
              train_dataset,
              tmpdir,
              batch_size,
              criterion,
              hessian_dataset=hessian_dataset,
          )
  
          influence_2 = influence_constructor_2(
              net,
              train_dataset,
              tmpdir,
              batch_size,
              criterion,
              hessian_dataset=hessian_dataset,
          )
  
          if mode == "self_influence":
              # compare self influence scores
              assertTensorAlmostEqual(
                  self,
                  influence_1.self_influence(train_dataset),
                  influence_2.self_influence(train_dataset),
                  delta=delta,
                  mode="sum",
              )
          elif mode == "intermediate_quantities":
              # compare intermediate quantities
              assertTensorAlmostEqual(
                  self,
                  influence_1.compute_intermediate_quantities(
                      train_dataset
                  ),
                  influence_2.compute_intermediate_quantities(
                      train_dataset
                  ),
                  delta=delta,
                  mode="max",
              )
          elif mode == "influence":
              # compare influence scores
              assertTensorAlmostEqual(
                  self,
                  influence_1.influence(
                      _format_batch_into_tuple(
                          test_samples, test_labels, unpack_inputs
                      )
                  ),
                  influence_2.influence(
                      _format_batch_into_tuple(
                          test_samples, test_labels, unpack_inputs
                      )
                  ),
                  delta=delta,
                  mode="max",
              )
          else:
              raise Exception("unknown test mode")
  
imports: import tempfile
  from typing import Callable, List, Tuple, Union
  import torch
  import torch.nn
  from captum.influence._core.arnoldi_influence_function import _parameter_arnoldi, _parameter_distill, ArnoldiInfluenceFunction
  from captum.influence._core.influence_function import NaiveInfluenceFunction
  from captum.influence._utils.common import _eig_helper, _flatten_params, _top_eigen, _unflatten_params_factory
  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, ExplicitDataset, generate_assymetric_matrix_given_eigenvalues, generate_symmetric_matrix_given_eigenvalues, get_random_model_and_data, UnpackDataset, USE_GPU_LIST
  from torch import Tensor
  from torch.utils.data import DataLoader
label_desc: Use image node_id 7 for calling the TestArnoldiInfluence obj's underlying member method code with example usage: obj._test_compare_implementations(model_type, influence_constructor_1, influence_constructor_2, delta, mode, unpack_inputs, use_gpu) without return types