class_docstr: This is a computationally-inefficient implementation that computes the type of
  "infinitesimal" influence scores defined in the paper "Understanding Black-box
  Predictions via Influence Functions" by Koh et al
  (https://arxiv.org/pdf/1703.04730.pdf). The computational bottleneck in computing
  infinitesimal influence scores is computing inverse Hessian-vector products, as can
  be seen from its definition in `InfluenceFunctionBase`. This implementation is
  inefficient / naive in that it explicitly forms the Hessian :math`H`, unlike other
  implementations which compute inverse Hessian-vector products without explicitly
  forming the Hessian. The purpose of this implementation is to have a way to
  generate the "ground-truth" influence scores, to which other implementations,
  which are more efficient but return only approximations of the influence score, can
  be compared.
  
  This implementation computes a low-rank approximation of the inverse Hessian, i.e.
  a tall and skinny (with width k) matrix :math`R` such that
  :math`H^{-1} \approx RR'`, where k is small. In particular, let :math`L` be the
  matrix of width k whose columns contain the top-k eigenvectors of :math`H`, and let
  :math`V` be the k by k matrix whose diagonals contain the corresponding eigenvalues.
  This implementation lets :math`R=LV^{-1}L'`. Thus, the core computational step is
  computing the top-k eigenvalues / eigenvectors.
  
  This low-rank approximation is useful for several reasons:
  - It avoids numerical issues associated with inverting small eigenvalues.
  - Since the influence score is given by
    :math`\nabla_\theta L(x)' H^{-1} \nabla_\theta L(z)`, which is approximated by
    :math`(\nabla_\theta L(x)' R) (\nabla_\theta L(z)' R)`, we can compute an
    "influence embedding" for a given example :math`x`, :math`\nabla_\theta L(x)' R`,
    such that the influence score of one example on another is approximately the
    dot-product of their respective embeddings.
  
  This implementation is "naive" in that it computes the top-k eigenvalues /
  eigenvectors by explicitly forming the Hessian, converting it to a 2D tensor,
  computing its eigenvectors / eigenvalues, and then sorting. See documentation of the
  `_retrieve_projections_naive_influence_function` method for more details.
docstr: Args:
  
      inputs (tuple): `inputs` is the test batch and is a tuple of
              any, 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 `batch[-1]` are the labels, if any. This is the same
              assumption made for each batch yielded by training dataset
              `train_dataset` - please see its documentation in `__init__` for
              more details on the assumed structure of a batch.
      k (int, optional): The number of proponents or opponents to return per test
              example.
              Default: 5
      proponents (bool, optional): Whether seeking proponents (`proponents=True`)
              or opponents (`proponents=False`)
              Default: True
      show_progress (bool, optional): To compute the proponents (or opponents)
              for the batch of examples, we perform computation for each batch in
              training dataset `train_dataset`, If `show_progress` is
              true, the progress of this computation will be displayed. In
              particular, the number of batches for which the computation has
              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
  
  Returns:
      (indices, influence_scores) (namedtuple): `indices` is a torch.long Tensor
              that contains the indices of the proponents (or opponents) for each
              test example. Its dimension is `(inputs_batch_size, k)`, where
              `inputs_batch_size` is the number of examples in `inputs`. For
              example, if `proponents==True`, `indices[i][j]` is the index of the
              example in training dataset `train_dataset` with the
              k-th highest influence score for the j-th example in `inputs`.
              `indices` is a `torch.long` tensor so that it can directly be used
              to index other tensors. Each row of `influence_scores` contains the
              influence scores for a different test example, in sorted order. In
              particular, `influence_scores[i][j]` is the influence score of
              example `indices[i][j]` in training dataset `train_dataset`
              on example `i` in the test dataset represented by `inputs`.
docstr_tok: ["Args",":","inputs","(","tuple",")",":","`","inputs","`","is","the","test","batch","and","is","a","tuple","of","any",",","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","`","batch","[","-1","]","`","are","the","labels",",","if","any",".","This","is","the","same","assumption","made","for","each","batch","yielded","by","training","dataset","`","train_dataset","`","-","please","see","its","documentation","in","`","__init__","`","for","more","details","on","the","assumed","structure","of","a","batch",".","k","(","int",",","optional",")",":","The","number","of","proponents","or","opponents","to","return","per","test","example",".","Default",":","5","proponents","(","bool",",","optional",")",":","Whether","seeking","proponents","(","`","proponents=True","`",")","or","opponents","(","`","proponents=False","`",")","Default",":","True","show_progress","(","bool",",","optional",")",":","To","compute","the","proponents","(","or","opponents",")","for","the","batch","of","examples",",","we","perform","computation","for","each","batch","in","training","dataset","`","train_dataset","`",",","If","`","show_progress","`","is","true",",","the","progress","of","this","computation","will","be","displayed",".","In","particular",",","the","number","of","batches","for","which","the","computation","has","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","Returns",":","(","indices",",","influence_scores",")","(","namedtuple",")",":","`","indices","`","is","a","torch.long","Tensor","that","contains","the","indices","of","the","proponents","(","or","opponents",")","for","each","test","example",".","Its","dimension","is","`","(","inputs_batch_size",",","k",")","`",",","where","`","inputs_batch_size","`","is","the","number","of","examples","in","`","inputs","`",".","For","example",",","if","`","proponents==True","`",",","`","indices","[","i","]","[","j","]","`","is","the","index","of","the","example","in","training","dataset","`","train_dataset","`","with","the","k-th","highest","influence","score","for","the","j-th","example","in","`","inputs","`",".","`","indices","`","is","a","`","torch.long","`","tensor","so","that","it","can","directly","be","used","to","index","other","tensors",".","Each","row","of","`","influence_scores","`","contains","the","influence","scores","for","a","different","test","example",",","in","sorted","order",".","In","particular",",","`","influence_scores","[","i","]","[","j","]","`","is","the","influence","score","of","example","`","indices","[","i","]","[","j","]","`","in","training","dataset","`","train_dataset","`","on","example","`","i","`","in","the","test","dataset","represented","by","`","inputs","`","."]
code: def _get_k_most_influential(
      self,
      inputs: Union[Tuple[Any, ...], DataLoader],
      k: int = 5,
      proponents: bool = True,
      show_progress: bool = False,
  ) -> KMostInfluentialResults:
      r"""
      Args:
  
          inputs (tuple): `inputs` is the test batch and is a tuple of
                  any, 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 `batch[-1]` are the labels, if any. This is the same
                  assumption made for each batch yielded by training dataset
                  `train_dataset` - please see its documentation in `__init__` for
                  more details on the assumed structure of a batch.
          k (int, optional): The number of proponents or opponents to return per test
                  example.
                  Default: 5
          proponents (bool, optional): Whether seeking proponents (`proponents=True`)
                  or opponents (`proponents=False`)
                  Default: True
          show_progress (bool, optional): To compute the proponents (or opponents)
                  for the batch of examples, we perform computation for each batch in
                  training dataset `train_dataset`, If `show_progress` is
                  true, the progress of this computation will be displayed. In
                  particular, the number of batches for which the computation has
                  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
  
      Returns:
          (indices, influence_scores) (namedtuple): `indices` is a torch.long Tensor
                  that contains the indices of the proponents (or opponents) for each
                  test example. Its dimension is `(inputs_batch_size, k)`, where
                  `inputs_batch_size` is the number of examples in `inputs`. For
                  example, if `proponents==True`, `indices[i][j]` is the index of the
                  example in training dataset `train_dataset` with the
                  k-th highest influence score for the j-th example in `inputs`.
                  `indices` is a `torch.long` tensor so that it can directly be used
                  to index other tensors. Each row of `influence_scores` contains the
                  influence scores for a different test example, in sorted order. In
                  particular, `influence_scores[i][j]` is the influence score of
                  example `indices[i][j]` in training dataset `train_dataset`
                  on example `i` in the test dataset represented by `inputs`.
      """
      desc = (
          None
          if not show_progress
          else (
              (
                  f"Using {self.get_name()} to perform computation for "
                  f'getting {"proponents" if proponents else "opponents"}. '
                  "Processing training batches"
              )
          )
      )
      return KMostInfluentialResults(
          *_get_k_most_influential_helper(
              self.train_dataloader,
              functools.partial(
                  _influence_batch_intermediate_quantities_influence_function,
                  self,
              ),
              inputs,
              k,
              proponents,
              show_progress,
              desc,
          )
      )
  
imports: import functools
  from abc import abstractmethod
  from operator import add
  from typing import Any, Callable, List, Optional, Tuple, Union
  import torch
  import torch.nn
  from captum._utils.gradient import _extract_parameters_from_layers
  from captum.influence._core.influence import DataInfluence
  from captum.influence._utils.common import _check_loss_fn, _compute_batch_loss_influence_function_base, _compute_jacobian_sample_wise_grads_per_batch, _dataset_fn, _flatten_params, _format_inputs_dataset, _functional_call, _get_k_most_influential_helper, _influence_batch_intermediate_quantities_influence_function, _influence_helper_intermediate_quantities_influence_function, _influence_route_to_helpers, _load_flexible_state_dict, _params_to_names, _progress_bar_constructor, _self_influence_helper_intermediate_quantities_influence_function, _set_active_parameters, _top_eigen, _unflatten_params_factory, KMostInfluentialResults
  from captum.log import log_usage
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.data import DataLoader, Dataset
  from tqdm import tqdm
label_desc: Use image node_id 5 for calling the NaiveInfluenceFunction obj's underlying member method code with example usage: obj._get_k_most_influential(inputs, k, proponents, show_progress) and returns: KMostInfluentialResults