docstr: Computes the influence of examples in training dataset `train_dataset`
  on the examples in the test dataset represented by `inputs`.
  This implementation does not require knowing the number of training examples
  in advance. Instead, the number of training examples is inferred from the
  output of `self._basic_computation_tracincp`.
  
  Args:
  
      inputs_dataset (Tuple, or DataLoader): Either a single tuple of any, or a
              `DataLoader`, where each batch yielded is a tuple of any. In
              either case, the tuple represents a single batch, where the last
              element is assumed to be the labels for the batch. That is,
              `model(*batch[0:-1])` produces the output for `model`, and
              and `batch[-1]` are the labels, if any. Here, `model` is model
              provided in initialization. This is the same assumption made for
              each batch yielded by training dataset `train_dataset`.
      show_progress (bool, optional): To compute the influence of examples in
              training dataset `train_dataset`, we compute the influence
              of each batch. If `show_progress` is true, the progress of this
              computation will be displayed. In particular, the number of batches
              for which influence has been computed will be displayed. It will
              try to use tqdm if available for advanced features (e.g. time
              estimation). Otherwise, it will fallback to a simple output of
              progress.
              Default: False
      aggregate (bool): Whether to return "aggregate" influence scores (see their
              definition in `influence`).
              Default: False
  
  Returns:
      influence_scores (Tensor): If `aggregate` is False, influence scores are
      returned as a 2D tensor whose shape is `(input_size, train_dataset_size)`,
      where `input_size` is the number of examples in the test dataset, and
      `train_dataset_size` is the number of examples in
      training dataset `train_dataset`. For example:
      `influence_scores[i][j]` is the influence score for the j-th training
      example to the i-th example in the test dataset. If `aggregate` is True,
      "aggregate" influence scores are returned as a 2D tensor whose shape is
      `(1, train_dataset_size)`. For example: `influence_scores[0][j]` is the
      aggregate influence score of the j-th training example on the test dataset.
docstr_tok: ["Computes","the","influence","of","examples","in","training","dataset","`","train_dataset","`","on","the","examples","in","the","test","dataset","represented","by","`","inputs","`",".","This","implementation","does","not","require","knowing","the","number","of","training","examples","in","advance",".","Instead",",","the","number","of","training","examples","is","inferred","from","the","output","of","`","self._basic_computation_tracincp","`",".","Args",":","inputs_dataset","(","Tuple",",","or","DataLoader",")",":","Either","a","single","tuple","of","any",",","or","a","`","DataLoader","`",",","where","each","batch","yielded","is","a","tuple","of","any",".","In","either","case",",","the","tuple","represents","a","single","batch",",","where","the","last","element","is","assumed","to","be","the","labels","for","the","batch",".","That","is",",","`","model","(","*","batch","[","0",":","-1","]",")","`","produces","the","output","for","`","model","`",",","and","and","`","batch","[","-1","]","`","are","the","labels",",","if","any",".","Here",",","`","model","`","is","model","provided","in","initialization",".","This","is","the","same","assumption","made","for","each","batch","yielded","by","training","dataset","`","train_dataset","`",".","show_progress","(","bool",",","optional",")",":","To","compute","the","influence","of","examples","in","training","dataset","`","train_dataset","`",",","we","compute","the","influence","of","each","batch",".","If","`","show_progress","`","is","true",",","the","progress","of","this","computation","will","be","displayed",".","In","particular",",","the","number","of","batches","for","which","influence","has","been","computed","will","be","displayed",".","It","will","try","to","use","tqdm","if","available","for","advanced","features","(","e.g",".","time","estimation",")",".","Otherwise",",","it","will","fallback","to","a","simple","output","of","progress",".","Default",":","False","aggregate","(","bool",")",":","Whether","to","return","``","aggregate","''","influence","scores","(","see","their","definition","in","`","influence","`",")",".","Default",":","False","Returns",":","influence_scores","(","Tensor",")",":","If","`","aggregate","`","is","False",",","influence","scores","are","returned","as","a","2D","tensor","whose","shape","is","`","(","input_size",",","train_dataset_size",")","`",",","where","`","input_size","`","is","the","number","of","examples","in","the","test","dataset",",","and","`","train_dataset_size","`","is","the","number","of","examples","in","training","dataset","`","train_dataset","`",".","For","example",":","`","influence_scores","[","i","]","[","j","]","`","is","the","influence","score","for","the","j-th","training","example","to","the","i-th","example","in","the","test","dataset",".","If","`","aggregate","`","is","True",",","``","aggregate","''","influence","scores","are","returned","as","a","2D","tensor","whose","shape","is","`","(","1",",","train_dataset_size",")","`",".","For","example",":","`","influence_scores","[","0","]","[","j","]","`","is","the","aggregate","influence","score","of","the","j-th","training","example","on","the","test","dataset","."]
code: def _influence(
      self,
      inputs: Union[Tuple[Any, ...], DataLoader],
      show_progress: bool = False,
      aggregate: bool = False,
  ) -> Tensor:
      r"""
      Computes the influence of examples in training dataset `train_dataset`
      on the examples in the test dataset represented by `inputs`.
      This implementation does not require knowing the number of training examples
      in advance. Instead, the number of training examples is inferred from the
      output of `self._basic_computation_tracincp`.
  
      Args:
  
          inputs_dataset (Tuple, or DataLoader): Either a single tuple of any, or a
                  `DataLoader`, where each batch yielded is a tuple of any. In
                  either case, the tuple represents a single batch, where the last
                  element is assumed to be the labels for the batch. That is,
                  `model(*batch[0:-1])` produces the output for `model`, and
                  and `batch[-1]` are the labels, if any. Here, `model` is model
                  provided in initialization. This is the same assumption made for
                  each batch yielded by training dataset `train_dataset`.
          show_progress (bool, optional): To compute the influence of examples in
                  training dataset `train_dataset`, we compute the influence
                  of each batch. If `show_progress` is true, the progress of this
                  computation will be displayed. In particular, the number of batches
                  for which influence has been computed will be displayed. It will
                  try to use tqdm if available for advanced features (e.g. time
                  estimation). Otherwise, it will fallback to a simple output of
                  progress.
                  Default: False
          aggregate (bool): Whether to return "aggregate" influence scores (see their
                  definition in `influence`).
                  Default: False
  
      Returns:
          influence_scores (Tensor): If `aggregate` is False, influence scores are
          returned as a 2D tensor whose shape is `(input_size, train_dataset_size)`,
          where `input_size` is the number of examples in the test dataset, and
          `train_dataset_size` is the number of examples in
          training dataset `train_dataset`. For example:
          `influence_scores[i][j]` is the influence score for the j-th training
          example to the i-th example in the test dataset. If `aggregate` is True,
          "aggregate" influence scores are returned as a 2D tensor whose shape is
          `(1, train_dataset_size)`. For example: `influence_scores[0][j]` is the
          aggregate influence score of the j-th training example on the test dataset.
      """
      # If `inputs` is not a `DataLoader`, turn it into one.
      inputs = _format_inputs_dataset(inputs)
  
      train_dataloader = self.train_dataloader
  
      if show_progress:
          train_dataloader = progress(
              train_dataloader,
              desc=(
                  f"Using {self.get_name()} to compute "
                  "influence for training batches"
              ),
              total=self.train_dataloader_len,
          )
  
      # create list of the outputs of `_basic_computation_tracincp`, for each
      # checkpoint, which are jacobians
      inputs_checkpoint_jacobians = self._get_checkpoint_jacobians(
          inputs, aggregate, self.test_loss_fn
      )
  
      return torch.cat(
          [
              self._influence_batch_tracincp(
                  inputs_checkpoint_jacobians, batch
              )
              for batch in train_dataloader
          ],
          dim=1,
      )
  
imports: import glob
  import warnings
  from abc import abstractmethod
  from os.path import join
  from typing import Any, Callable, Iterator, List, Optional, Tuple, Type, Union
  import torch
  from captum._utils.av import AV
  from captum._utils.common import _parse_version
  from captum._utils.progress import NullProgress, progress
  from captum.influence._core.influence import DataInfluence
  from captum.influence._utils.common import _check_loss_fn, _compute_jacobian_sample_wise_grads_per_batch, _format_inputs_dataset, _get_k_most_influential_helper, _gradient_dot_product, _influence_route_to_helpers, _load_flexible_state_dict, _self_influence_by_batches_helper, _set_active_parameters, KMostInfluentialResults
  from captum.log import log_usage
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.data import DataLoader, Dataset
label_desc: Use image node_id 8 for calling the TracInCP obj's underlying member method code with example usage: obj._influence(inputs, show_progress, aggregate) and returns: torch