docstr: This is the key method of this class, and can be run in 2 different modes,
  where the mode that is run depends on the arguments passed to this method.
  Below, we describe the 2 modes, when `aggregate` is false:
  
  - influence score mode: This mode is used if `k` is None. This mode computes
    the influence score of every example in training dataset `train_dataset`
    on every example in the test dataset represented by `inputs`.
  - k-most influential mode: This mode is used if `k` is not None, and an int.
    This mode computes the proponents or opponents of every example in the
    test dataset represented by `inputs`. In particular, for each test example in
    the test dataset, this mode computes its proponents (resp. opponents),
    which are the indices in the training dataset `train_dataset` of the
    training examples with the `k` highest (resp. lowest) influence scores on the
    test example. Proponents are computed if `proponents` is True. Otherwise,
    opponents are computed. For each test example, this method also returns the
    actual influence score of each proponent (resp. opponent) on the test
    example.
  
  When `aggregate` is True, this method computes "aggregate" influence scores,
  which for a given training example, is the *sum* of its influence scores over
  all examples in the test dataset. Below, we describe the 2 modes, when
  `aggregate` is True:
  
  - influence score mode: This mode is used if `k` is None. This mode computes
    the aggregate influence score of each example in training dataset
    `train_dataset` on the test dataset.
  - k-most influential mode: This mode is used if `k` is not None, and an int.
    This mode computes the "aggregate" proponents (resp. opponents), which are
    the indices in the training dataset `train_dataset` of the examples with the
    `k` highest (resp. lowest) aggregate influence scores on the test dataset.
    Proponents are computed if `proponents` is True. Otherwise, opponents are
    computed. This method also returns the actual aggregate influence scores
    of each proponent (resp. opponent) on the test dataset.
  
  Args:
  
      inputs (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`. Please see
              documentation for the `train_dataset` argument to
              `TracInCPFastRandProj.__init__` for more details on the assumed
              structure of a batch.
      k (int, optional): If not provided or `None`, the influence score mode will
              be run. Otherwise, the k-most influential mode will be run,
              and `k` is the number of proponents / opponents to return per
              example in the test batch.
              Default: None
      proponents (bool, optional): Whether seeking proponents (`proponents=True`)
              or opponents (`proponents=False`), if running in k-most influential
              mode.
              Default: True
      show_progress (bool, optional): For all modes, computation of results
              requires "training dataset computations": computations for each
              batch in the training dataset `train_dataset`, which may
              take a long time. If `show_progress` is true, the progress of
              "training dataset computations" will be displayed. In particular,
              the number of batches for which computations have been performed
              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, optional): If true, return "aggregate" influence scores or
              examples with the highest / lowest aggregate influence scores on
              the test dataset, depending on the mode.
  
  Returns:
      The return value of this method depends on which mode is run, and whether
      `aggregate` is True of False.
  
      Below are the return values for the 2 modes, when `aggregate` is False:
  
      - influence score mode: if this mode is run (`k` is None), returns a 2D
        tensor `influence_scores` of shape `(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`. In other words, `influence_scores[i][j]` is the
        influence score of the `j`-th example in `train_dataset` on the `i`-th
        example in the test dataset.
      - k-most influential mode: if this mode is run (`k` is an int), returns
        a namedtuple `(indices, influence_scores)`. `indices` is a 2D tensor of
        shape `(input_size, k)`, where `input_size` is the number of examples in
        the test dataset. If computing proponents (resp. opponents),
        `indices[i][j]` is the index in training dataset `train_dataset` of the
        example with the `j`-th highest (resp. lowest) influence score (out of
        the examples in `train_dataset`) on the `i`-th example in the test
        dataset. `influence_scores` contains the corresponding influence scores.
        In particular, `influence_scores[i][j]` is the influence score of example
        `indices[i][j]` in `train_dataset` on example `i` in the test dataset
        represented by `inputs`.
  
      Below are the return values for the 2 modes, when `aggregate` is True:
  
      - influence score mode: if this mode is run (`k` is None), returns a 2D
        tensor `influence_scores` of shape `(1, train_dataset_size)`, where
        `influence_scores[0][j] is the aggregate influence score of the `j`-th
        example in `train_dataset` on the test dataset.
      - k-most influential mode: if this mode is run (`k` is an int), returns a
        namedtuple `(indices, influence_scores)`. `indices` is a 2D tensor of
        shape `(1, k)`. If computing proponents (resp. opponents),
        `indices[0][j]` is the index in training dataset `train_dataset` of the
        example with the `j`-th highest (resp. lowest) aggregate influence score
        on the test dataset. `influence_scores` contains the corresponding
        aggregate influence scores. In particular, `influence_scores[0][j]` is
        the aggregate influence score of example `indices[0][j]` on the test
        dataset.
docstr_tok: ["This","is","the","key","method","of","this","class",",","and","can","be","run","in","2","different","modes",",","where","the","mode","that","is","run","depends","on","the","arguments","passed","to","this","method",".","Below",",","we","describe","the","2","modes",",","when","`","aggregate","`","is","false",":","-","influence","score","mode",":","This","mode","is","used","if","`","k","`","is","None",".","This","mode","computes","the","influence","score","of","every","example","in","training","dataset","`","train_dataset","`","on","every","example","in","the","test","dataset","represented","by","`","inputs","`",".","-","k-most","influential","mode",":","This","mode","is","used","if","`","k","`","is","not","None",",","and","an","int",".","This","mode","computes","the","proponents","or","opponents","of","every","example","in","the","test","dataset","represented","by","`","inputs","`",".","In","particular",",","for","each","test","example","in","the","test","dataset",",","this","mode","computes","its","proponents","(","resp",".","opponents",")",",","which","are","the","indices","in","the","training","dataset","`","train_dataset","`","of","the","training","examples","with","the","`","k","`","highest","(","resp",".","lowest",")","influence","scores","on","the","test","example",".","Proponents","are","computed","if","`","proponents","`","is","True",".","Otherwise",",","opponents","are","computed",".","For","each","test","example",",","this","method","also","returns","the","actual","influence","score","of","each","proponent","(","resp",".","opponent",")","on","the","test","example",".","When","`","aggregate","`","is","True",",","this","method","computes","``","aggregate","''","influence","scores",",","which","for","a","given","training","example",",","is","the","*","sum","*","of","its","influence","scores","over","all","examples","in","the","test","dataset",".","Below",",","we","describe","the","2","modes",",","when","`","aggregate","`","is","True",":","-","influence","score","mode",":","This","mode","is","used","if","`","k","`","is","None",".","This","mode","computes","the","aggregate","influence","score","of","each","example","in","training","dataset","`","train_dataset","`","on","the","test","dataset",".","-","k-most","influential","mode",":","This","mode","is","used","if","`","k","`","is","not","None",",","and","an","int",".","This","mode","computes","the","``","aggregate","''","proponents","(","resp",".","opponents",")",",","which","are","the","indices","in","the","training","dataset","`","train_dataset","`","of","the","examples","with","the","`","k","`","highest","(","resp",".","lowest",")","aggregate","influence","scores","on","the","test","dataset",".","Proponents","are","computed","if","`","proponents","`","is","True",".","Otherwise",",","opponents","are","computed",".","This","method","also","returns","the","actual","aggregate","influence","scores","of","each","proponent","(","resp",".","opponent",")","on","the","test","dataset",".","Args",":","inputs","(","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","`",".","Please","see","documentation","for","the","`","train_dataset","`","argument","to","`","TracInCPFastRandProj.__init__","`","for","more","details","on","the","assumed","structure","of","a","batch",".","k","(","int",",","optional",")",":","If","not","provided","or","`","None","`",",","the","influence","score","mode","will","be","run",".","Otherwise",",","the","k-most","influential","mode","will","be","run",",","and","`","k","`","is","the","number","of","proponents","\/","opponents","to","return","per","example","in","the","test","batch",".","Default",":","None","proponents","(","bool",",","optional",")",":","Whether","seeking","proponents","(","`","proponents=True","`",")","or","opponents","(","`","proponents=False","`",")",",","if","running","in","k-most","influential","mode",".","Default",":","True","show_progress","(","bool",",","optional",")",":","For","all","modes",",","computation","of","results","requires","``","training","dataset","computations","''",":","computations","for","each","batch","in","the","training","dataset","`","train_dataset","`",",","which","may","take","a","long","time",".","If","`","show_progress","`","is","true",",","the","progress","of","``","training","dataset","computations","''","will","be","displayed",".","In","particular",",","the","number","of","batches","for","which","computations","have","been","performed","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",",","optional",")",":","If","true",",","return","``","aggregate","''","influence","scores","or","examples","with","the","highest","\/","lowest","aggregate","influence","scores","on","the","test","dataset",",","depending","on","the","mode",".","Returns",":","The","return","value","of","this","method","depends","on","which","mode","is","run",",","and","whether","`","aggregate","`","is","True","of","False",".","Below","are","the","return","values","for","the","2","modes",",","when","`","aggregate","`","is","False",":","-","influence","score","mode",":","if","this","mode","is","run","(","`","k","`","is","None",")",",","returns","a","2D","tensor","`","influence_scores","`","of","shape","`","(","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","`",".","In","other","words",",","`","influence_scores","[","i","]","[","j","]","`","is","the","influence","score","of","the","`","j","`","-th","example","in","`","train_dataset","`","on","the","`","i","`","-th","example","in","the","test","dataset",".","-","k-most","influential","mode",":","if","this","mode","is","run","(","`","k","`","is","an","int",")",",","returns","a","namedtuple","`","(","indices",",","influence_scores",")","`",".","`","indices","`","is","a","2D","tensor","of","shape","`","(","input_size",",","k",")","`",",","where","`","input_size","`","is","the","number","of","examples","in","the","test","dataset",".","If","computing","proponents","(","resp",".","opponents",")",",","`","indices","[","i","]","[","j","]","`","is","the","index","in","training","dataset","`","train_dataset","`","of","the","example","with","the","`","j","`","-th","highest","(","resp",".","lowest",")","influence","score","(","out","of","the","examples","in","`","train_dataset","`",")","on","the","`","i","`","-th","example","in","the","test","dataset",".","`","influence_scores","`","contains","the","corresponding","influence","scores",".","In","particular",",","`","influence_scores","[","i","]","[","j","]","`","is","the","influence","score","of","example","`","indices","[","i","]","[","j","]","`","in","`","train_dataset","`","on","example","`","i","`","in","the","test","dataset","represented","by","`","inputs","`",".","Below","are","the","return","values","for","the","2","modes",",","when","`","aggregate","`","is","True",":","-","influence","score","mode",":","if","this","mode","is","run","(","`","k","`","is","None",")",",","returns","a","2D","tensor","`","influence_scores","`","of","shape","`","(","1",",","train_dataset_size",")","`",",","where","`","influence_scores","[","0","]","[","j","]","is","the","aggregate","influence","score","of","the","`","j","`","-th","example","in","`","train_dataset","`","on","the","test","dataset",".","-","k-most","influential","mode",":","if","this","mode","is","run","(","`","k","`","is","an","int",")",",","returns","a","namedtuple","`","(","indices",",","influence_scores",")","`",".","`","indices","`","is","a","2D","tensor","of","shape","`","(","1",",","k",")","`",".","If","computing","proponents","(","resp",".","opponents",")",",","`","indices","[","0","]","[","j","]","`","is","the","index","in","training","dataset","`","train_dataset","`","of","the","example","with","the","`","j","`","-th","highest","(","resp",".","lowest",")","aggregate","influence","score","on","the","test","dataset",".","`","influence_scores","`","contains","the","corresponding","aggregate","influence","scores",".","In","particular",",","`","influence_scores","[","0","]","[","j","]","`","is","the","aggregate","influence","score","of","example","`","indices","[","0","]","[","j","]","`","on","the","test","dataset","."]
code: def influence(  # type: ignore[override]
      self,
      inputs: Union[Tuple[Any, ...], DataLoader],
      k: Optional[int] = None,
      proponents: bool = True,
      show_progress: bool = False,
      aggregate: bool = False,
  ) -> Union[Tensor, KMostInfluentialResults]:
      r"""
      This is the key method of this class, and can be run in 2 different modes,
      where the mode that is run depends on the arguments passed to this method.
      Below, we describe the 2 modes, when `aggregate` is false:
  
      - influence score mode: This mode is used if `k` is None. This mode computes
        the influence score of every example in training dataset `train_dataset`
        on every example in the test dataset represented by `inputs`.
      - k-most influential mode: This mode is used if `k` is not None, and an int.
        This mode computes the proponents or opponents of every example in the
        test dataset represented by `inputs`. In particular, for each test example in
        the test dataset, this mode computes its proponents (resp. opponents),
        which are the indices in the training dataset `train_dataset` of the
        training examples with the `k` highest (resp. lowest) influence scores on the
        test example. Proponents are computed if `proponents` is True. Otherwise,
        opponents are computed. For each test example, this method also returns the
        actual influence score of each proponent (resp. opponent) on the test
        example.
  
      When `aggregate` is True, this method computes "aggregate" influence scores,
      which for a given training example, is the *sum* of its influence scores over
      all examples in the test dataset. Below, we describe the 2 modes, when
      `aggregate` is True:
  
      - influence score mode: This mode is used if `k` is None. This mode computes
        the aggregate influence score of each example in training dataset
        `train_dataset` on the test dataset.
      - k-most influential mode: This mode is used if `k` is not None, and an int.
        This mode computes the "aggregate" proponents (resp. opponents), which are
        the indices in the training dataset `train_dataset` of the examples with the
        `k` highest (resp. lowest) aggregate influence scores on the test dataset.
        Proponents are computed if `proponents` is True. Otherwise, opponents are
        computed. This method also returns the actual aggregate influence scores
        of each proponent (resp. opponent) on the test dataset.
  
      Args:
  
          inputs (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`. Please see
                  documentation for the `train_dataset` argument to
                  `TracInCPFastRandProj.__init__` for more details on the assumed
                  structure of a batch.
          k (int, optional): If not provided or `None`, the influence score mode will
                  be run. Otherwise, the k-most influential mode will be run,
                  and `k` is the number of proponents / opponents to return per
                  example in the test batch.
                  Default: None
          proponents (bool, optional): Whether seeking proponents (`proponents=True`)
                  or opponents (`proponents=False`), if running in k-most influential
                  mode.
                  Default: True
          show_progress (bool, optional): For all modes, computation of results
                  requires "training dataset computations": computations for each
                  batch in the training dataset `train_dataset`, which may
                  take a long time. If `show_progress` is true, the progress of
                  "training dataset computations" will be displayed. In particular,
                  the number of batches for which computations have been performed
                  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, optional): If true, return "aggregate" influence scores or
                  examples with the highest / lowest aggregate influence scores on
                  the test dataset, depending on the mode.
  
      Returns:
          The return value of this method depends on which mode is run, and whether
          `aggregate` is True of False.
  
          Below are the return values for the 2 modes, when `aggregate` is False:
  
          - influence score mode: if this mode is run (`k` is None), returns a 2D
            tensor `influence_scores` of shape `(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`. In other words, `influence_scores[i][j]` is the
            influence score of the `j`-th example in `train_dataset` on the `i`-th
            example in the test dataset.
          - k-most influential mode: if this mode is run (`k` is an int), returns
            a namedtuple `(indices, influence_scores)`. `indices` is a 2D tensor of
            shape `(input_size, k)`, where `input_size` is the number of examples in
            the test dataset. If computing proponents (resp. opponents),
            `indices[i][j]` is the index in training dataset `train_dataset` of the
            example with the `j`-th highest (resp. lowest) influence score (out of
            the examples in `train_dataset`) on the `i`-th example in the test
            dataset. `influence_scores` contains the corresponding influence scores.
            In particular, `influence_scores[i][j]` is the influence score of example
            `indices[i][j]` in `train_dataset` on example `i` in the test dataset
            represented by `inputs`.
  
          Below are the return values for the 2 modes, when `aggregate` is True:
  
          - influence score mode: if this mode is run (`k` is None), returns a 2D
            tensor `influence_scores` of shape `(1, train_dataset_size)`, where
            `influence_scores[0][j] is the aggregate influence score of the `j`-th
            example in `train_dataset` on the test dataset.
          - k-most influential mode: if this mode is run (`k` is an int), returns a
            namedtuple `(indices, influence_scores)`. `indices` is a 2D tensor of
            shape `(1, k)`. If computing proponents (resp. opponents),
            `indices[0][j]` is the index in training dataset `train_dataset` of the
            example with the `j`-th highest (resp. lowest) aggregate influence score
            on the test dataset. `influence_scores` contains the corresponding
            aggregate influence scores. In particular, `influence_scores[0][j]` is
            the aggregate influence score of example `indices[0][j]` on the test
            dataset.
      """
  
      assert inputs is not None, (
          "`inputs` argument is required."
          "If you wish to calculate self influence scores,"
          " please use the `self_influence` method instead."
      )
      return _influence_route_to_helpers(
          self,
          inputs,
          k,
          proponents,
          show_progress=show_progress,
          aggregate=aggregate,
      )
  
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 2 for calling the TracInCP obj's underlying member method code with example usage: obj.influence(inputs, k, proponents, show_progress, aggregate) and returns: _influence_route_to_helpers