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:
      model (torch.nn.Module): An instance of pytorch model. This model should
              define all of its layers as attributes of the model.
      train_dataset (torch.utils.data.Dataset or torch.utils.data.DataLoader):
              In the `influence` method, we either compute the influence score of
              training examples on examples in a test batch, or self influence
              scores for those training examples, depending on which mode is used.
              This argument represents the training dataset containing those
              training examples. In order to compute those influence scores, we
              will create a Pytorch DataLoader yielding batches of training
              examples that is then used for processing. If this argument is
              already a Pytorch Dataloader, that DataLoader can be directly
              used for processing. If it is instead a Pytorch Dataset, we will
              create a DataLoader using it, with batch size specified by
              `batch_size`. For efficiency purposes, the batch size of the
              DataLoader used for processing should be as large as possible, but
              not too large, so that certain intermediate quantities created
              from a batch still fit in memory. Therefore, if
              `train_dataset` is a Dataset, `batch_size` should be large.
              If `train_dataset` was already a DataLoader to begin with,
              it should have been constructed to have a large batch size. It is
              assumed that the Dataloader (regardless of whether it is created
              from a Pytorch Dataset or not) yields tuples. For a `batch` that is
              yielded, of length `L`, it is assumed that the forward function of
              `model` accepts `L-1` arguments, and the last element of `batch` is
              the label. In other words, `model(*batch[:-1])` gives the output of
              `model`, and `batch[-1]` are the labels for the batch.
      checkpoint (str): The path to the checkpoint used to compute influence
              scores.
      checkpoints_load_func (Callable, optional): The function to load a saved
              checkpoint into a model to update its parameters, and get the
              learning rate if it is saved. By default uses a utility to load a
              model saved as a state dict.
              Default: _load_flexible_state_dict
      layers (list[str] or None, optional): A list of layer names for which
              gradients should be computed. If `layers` is None, gradients will
              be computed for all layers. Otherwise, they will only be computed
              for the layers specified in `layers`.
              Default: None
      loss_fn (Callable, optional): The loss function applied to model. For now,
              we require it to be a "reduction='none'" loss function. For
              example, `BCELoss(reduction='none')` would be acceptable, but
              `BCELoss(reduction='sum')` would not.
      batch_size (int or None, optional): Batch size of the DataLoader created to
              iterate through `train_dataset` and `hessian_dataset`, if they are
              of type `Dataset`. `batch_size` should be chosen as large as
              possible so that a backwards pass on a batch still fits in memory.
              If `train_dataset` and `hessian_dataset`are both of type
              `DataLoader`, then `batch_size` is ignored as an argument.
              Default: 1
      hessian_dataset (Dataset or Dataloader, optional): The influence score and
              self-influence scores this implementation calculates are defined in
              terms of the Hessian, i.e. the second-derivative of the model
              parameters. This argument provides the dataset used for calculating
              the Hessian. It should be smaller than `train_dataset`, which
              is the dataset whose examples we want the influence of. If not
              provided or none, it will be assumed to be the same as
              `train_dataset`.
              Default: None
      test_loss_fn (Callable, optional): In some cases, one may want to use a
              separate loss functions for training examples, i.e. those in
              `train_dataset`, and for test examples, i.e. those
              represented by the `inputs` and `targets` arguments to the
              `influence` method. For example, if one wants to calculate the
              influence score of a training example on a test example's
              prediction for a fixed class, `test_loss_fn` could map from the
              logits for all classes to the logits for a fixed class.
              `test_loss_fn` needs satisfy the same constraints as `loss_fn`.
              Thus, the same checks that we apply to `loss_fn` are also applied
              to `test_loss_fn`, if the latter is provided. Note that the
              constraints on both `loss_fn` and `test_loss_fn` both depend on
              `sample_wise_grads_per_batch`. This means `loss_fn` and
              `test_loss_fn` must either both be "per-example"  loss functions,
              or both be "reduction" loss functions. If not provided, the loss
              function for test examples is assumed to be the same as the loss
              function for training examples, i.e. `loss_fn`.
              Default: None
      sample_wise_grads_per_batch (bool, optional): PyTorch's native gradient
              computations w.r.t. model parameters aggregates the results for a
              batch and does not allow to access sample-wise gradients w.r.t.
              model parameters. This forces us to iterate over each sample in
              the batch if we want sample-wise gradients which is computationally
              inefficient. We offer an implementation of batch-wise gradient
              computations w.r.t. to model parameters which is computationally
              more efficient. This implementation can be enabled by setting the
              `sample_wise_grad_per_batch` argument to `True`, and should be
              enabled if and only if the `loss_fn` argument is a "reduction" loss
              function. For example, `nn.BCELoss(reduction="sum")` would be a
              valid `loss_fn` if this implementation is enabled (see
              documentation for `loss_fn` for more details). Note that our
              current implementation enables batch-wise gradient computations
              only for a limited number of PyTorch nn.Modules: Conv2D and Linear.
              This list will be expanded in the near future.  Therefore, please
              do not enable this implementation if gradients will be computed
              for other kinds of layers.
              Default: False
      projection_dim (int, optional): This implementation produces a low-rank
              approximation of the (inverse) Hessian. This is the rank of that
              approximation, and also corresponds to the dimension of the
              "influence embeddings" produced by the
              `compute_intermediate_quantities` method.
              Default: 50
      seed (int, optional): This implementation has a source of randomness - the
              initialization basis to the Arnoldi iteration. This seed is used
              to make that randomness reproducible.
              Default: 42
      hessian_reg (float, optional): We add an entry to the hessian's diagonal
              entries before computing its eigenvalues / eigenvectors.
              This is that entry.
              Default: 1e-6
      hessian_inverse_tol: (float) The tolerance to use when computing the
              pseudo-inverse of the (square root of) hessian.
              Default: 1e-6
      projection_on_cpu (bool, optional): Whether to move the projection,
              i.e. low-rank approximation of the inverse Hessian, to cpu, to save
              gpu memory.
              Default: True
      show_progress (bool, optional): This implementation explicitly computes the
              Hessian over batches in `hessian_dataloader` (and sums them) which
              can take a long time. If `show_progress` is true, the number of
              batches for which the Hessian 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
docstr_tok: ["Args",":","model","(","torch.nn.Module",")",":","An","instance","of","pytorch","model",".","This","model","should","define","all","of","its","layers","as","attributes","of","the","model",".","train_dataset","(","torch.utils.data.Dataset","or","torch.utils.data.DataLoader",")",":","In","the","`","influence","`","method",",","we","either","compute","the","influence","score","of","training","examples","on","examples","in","a","test","batch",",","or","self","influence","scores","for","those","training","examples",",","depending","on","which","mode","is","used",".","This","argument","represents","the","training","dataset","containing","those","training","examples",".","In","order","to","compute","those","influence","scores",",","we","will","create","a","Pytorch","DataLoader","yielding","batches","of","training","examples","that","is","then","used","for","processing",".","If","this","argument","is","already","a","Pytorch","Dataloader",",","that","DataLoader","can","be","directly","used","for","processing",".","If","it","is","instead","a","Pytorch","Dataset",",","we","will","create","a","DataLoader","using","it",",","with","batch","size","specified","by","`","batch_size","`",".","For","efficiency","purposes",",","the","batch","size","of","the","DataLoader","used","for","processing","should","be","as","large","as","possible",",","but","not","too","large",",","so","that","certain","intermediate","quantities","created","from","a","batch","still","fit","in","memory",".","Therefore",",","if","`","train_dataset","`","is","a","Dataset",",","`","batch_size","`","should","be","large",".","If","`","train_dataset","`","was","already","a","DataLoader","to","begin","with",",","it","should","have","been","constructed","to","have","a","large","batch","size",".","It","is","assumed","that","the","Dataloader","(","regardless","of","whether","it","is","created","from","a","Pytorch","Dataset","or","not",")","yields","tuples",".","For","a","`","batch","`","that","is","yielded",",","of","length","`","L","`",",","it","is","assumed","that","the","forward","function","of","`","model","`","accepts","`","L-1","`","arguments",",","and","the","last","element","of","`","batch","`","is","the","label",".","In","other","words",",","`","model","(","*","batch","[",":","-1","]",")","`","gives","the","output","of","`","model","`",",","and","`","batch","[","-1","]","`","are","the","labels","for","the","batch",".","checkpoint","(","str",")",":","The","path","to","the","checkpoint","used","to","compute","influence","scores",".","checkpoints_load_func","(","Callable",",","optional",")",":","The","function","to","load","a","saved","checkpoint","into","a","model","to","update","its","parameters",",","and","get","the","learning","rate","if","it","is","saved",".","By","default","uses","a","utility","to","load","a","model","saved","as","a","state","dict",".","Default",":","_load_flexible_state_dict","layers","(","list","[","str","]","or","None",",","optional",")",":","A","list","of","layer","names","for","which","gradients","should","be","computed",".","If","`","layers","`","is","None",",","gradients","will","be","computed","for","all","layers",".","Otherwise",",","they","will","only","be","computed","for","the","layers","specified","in","`","layers","`",".","Default",":","None","loss_fn","(","Callable",",","optional",")",":","The","loss","function","applied","to","model",".","For","now",",","we","require","it","to","be","a","``","reduction='none","'","''","loss","function",".","For","example",",","`","BCELoss","(","reduction='none","'",")","`","would","be","acceptable",",","but","`","BCELoss","(","reduction='sum","'",")","`","would","not",".","batch_size","(","int","or","None",",","optional",")",":","Batch","size","of","the","DataLoader","created","to","iterate","through","`","train_dataset","`","and","`","hessian_dataset","`",",","if","they","are","of","type","`","Dataset","`",".","`","batch_size","`","should","be","chosen","as","large","as","possible","so","that","a","backwards","pass","on","a","batch","still","fits","in","memory",".","If","`","train_dataset","`","and","`","hessian_dataset","`","are","both","of","type","`","DataLoader","`",",","then","`","batch_size","`","is","ignored","as","an","argument",".","Default",":","1","hessian_dataset","(","Dataset","or","Dataloader",",","optional",")",":","The","influence","score","and","self-influence","scores","this","implementation","calculates","are","defined","in","terms","of","the","Hessian",",","i.e",".","the","second-derivative","of","the","model","parameters",".","This","argument","provides","the","dataset","used","for","calculating","the","Hessian",".","It","should","be","smaller","than","`","train_dataset","`",",","which","is","the","dataset","whose","examples","we","want","the","influence","of",".","If","not","provided","or","none",",","it","will","be","assumed","to","be","the","same","as","`","train_dataset","`",".","Default",":","None","test_loss_fn","(","Callable",",","optional",")",":","In","some","cases",",","one","may","want","to","use","a","separate","loss","functions","for","training","examples",",","i.e",".","those","in","`","train_dataset","`",",","and","for","test","examples",",","i.e",".","those","represented","by","the","`","inputs","`","and","`","targets","`","arguments","to","the","`","influence","`","method",".","For","example",",","if","one","wants","to","calculate","the","influence","score","of","a","training","example","on","a","test","example's","prediction","for","a","fixed","class",",","`","test_loss_fn","`","could","map","from","the","logits","for","all","classes","to","the","logits","for","a","fixed","class",".","`","test_loss_fn","`","needs","satisfy","the","same","constraints","as","`","loss_fn","`",".","Thus",",","the","same","checks","that","we","apply","to","`","loss_fn","`","are","also","applied","to","`","test_loss_fn","`",",","if","the","latter","is","provided",".","Note","that","the","constraints","on","both","`","loss_fn","`","and","`","test_loss_fn","`","both","depend","on","`","sample_wise_grads_per_batch","`",".","This","means","`","loss_fn","`","and","`","test_loss_fn","`","must","either","both","be","``","per-example","''","loss","functions",",","or","both","be","``","reduction","''","loss","functions",".","If","not","provided",",","the","loss","function","for","test","examples","is","assumed","to","be","the","same","as","the","loss","function","for","training","examples",",","i.e",".","`","loss_fn","`",".","Default",":","None","sample_wise_grads_per_batch","(","bool",",","optional",")",":","PyTorch","'s","native","gradient","computations","w.r.t",".","model","parameters","aggregates","the","results","for","a","batch","and","does","not","allow","to","access","sample-wise","gradients","w.r.t",".","model","parameters",".","This","forces","us","to","iterate","over","each","sample","in","the","batch","if","we","want","sample-wise","gradients","which","is","computationally","inefficient",".","We","offer","an","implementation","of","batch-wise","gradient","computations","w.r.t",".","to","model","parameters","which","is","computationally","more","efficient",".","This","implementation","can","be","enabled","by","setting","the","`","sample_wise_grad_per_batch","`","argument","to","`","True","`",",","and","should","be","enabled","if","and","only","if","the","`","loss_fn","`","argument","is","a","``","reduction","''","loss","function",".","For","example",",","`","nn.BCELoss","(","reduction=","''","sum","''",")","`","would","be","a","valid","`","loss_fn","`","if","this","implementation","is","enabled","(","see","documentation","for","`","loss_fn","`","for","more","details",")",".","Note","that","our","current","implementation","enables","batch-wise","gradient","computations","only","for","a","limited","number","of","PyTorch","nn.Modules",":","Conv2D","and","Linear",".","This","list","will","be","expanded","in","the","near","future",".","Therefore",",","please","do","not","enable","this","implementation","if","gradients","will","be","computed","for","other","kinds","of","layers",".","Default",":","False","projection_dim","(","int",",","optional",")",":","This","implementation","produces","a","low-rank","approximation","of","the","(","inverse",")","Hessian",".","This","is","the","rank","of","that","approximation",",","and","also","corresponds","to","the","dimension","of","the","``","influence","embeddings","''","produced","by","the","`","compute_intermediate_quantities","`","method",".","Default",":","50","seed","(","int",",","optional",")",":","This","implementation","has","a","source","of","randomness","-","the","initialization","basis","to","the","Arnoldi","iteration",".","This","seed","is","used","to","make","that","randomness","reproducible",".","Default",":","42","hessian_reg","(","float",",","optional",")",":","We","add","an","entry","to","the","hessian","'s","diagonal","entries","before","computing","its","eigenvalues","\/","eigenvectors",".","This","is","that","entry",".","Default",":","1e-6","hessian_inverse_tol",":","(","float",")","The","tolerance","to","use","when","computing","the","pseudo-inverse","of","the","(","square","root","of",")","hessian",".","Default",":","1e-6","projection_on_cpu","(","bool",",","optional",")",":","Whether","to","move","the","projection",",","i.e",".","low-rank","approximation","of","the","inverse","Hessian",",","to","cpu",",","to","save","gpu","memory",".","Default",":","True","show_progress","(","bool",",","optional",")",":","This","implementation","explicitly","computes","the","Hessian","over","batches","in","`","hessian_dataloader","`","(","and","sums","them",")","which","can","take","a","long","time",".","If","`","show_progress","`","is","true",",","the","number","of","batches","for","which","the","Hessian","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"]
code: def __init__(
      self,
      model: Module,
      train_dataset: Union[Dataset, DataLoader],
      checkpoint: str,
      checkpoints_load_func: Callable = _load_flexible_state_dict,
      layers: Optional[List[str]] = None,
      loss_fn: Optional[Union[Module, Callable]] = None,
      batch_size: Union[int, None] = 1,
      hessian_dataset: Optional[Union[Dataset, DataLoader]] = None,
      test_loss_fn: Optional[Union[Module, Callable]] = None,
      sample_wise_grads_per_batch: bool = False,
      projection_dim: int = 50,
      seed: int = 42,
      hessian_reg: float = 1e-6,
      hessian_inverse_tol: float = 1e-5,
      projection_on_cpu: bool = True,
      show_progress: bool = False,
  ) -> None:
      """
      Args:
          model (torch.nn.Module): An instance of pytorch model. This model should
                  define all of its layers as attributes of the model.
          train_dataset (torch.utils.data.Dataset or torch.utils.data.DataLoader):
                  In the `influence` method, we either compute the influence score of
                  training examples on examples in a test batch, or self influence
                  scores for those training examples, depending on which mode is used.
                  This argument represents the training dataset containing those
                  training examples. In order to compute those influence scores, we
                  will create a Pytorch DataLoader yielding batches of training
                  examples that is then used for processing. If this argument is
                  already a Pytorch Dataloader, that DataLoader can be directly
                  used for processing. If it is instead a Pytorch Dataset, we will
                  create a DataLoader using it, with batch size specified by
                  `batch_size`. For efficiency purposes, the batch size of the
                  DataLoader used for processing should be as large as possible, but
                  not too large, so that certain intermediate quantities created
                  from a batch still fit in memory. Therefore, if
                  `train_dataset` is a Dataset, `batch_size` should be large.
                  If `train_dataset` was already a DataLoader to begin with,
                  it should have been constructed to have a large batch size. It is
                  assumed that the Dataloader (regardless of whether it is created
                  from a Pytorch Dataset or not) yields tuples. For a `batch` that is
                  yielded, of length `L`, it is assumed that the forward function of
                  `model` accepts `L-1` arguments, and the last element of `batch` is
                  the label. In other words, `model(*batch[:-1])` gives the output of
                  `model`, and `batch[-1]` are the labels for the batch.
          checkpoint (str): The path to the checkpoint used to compute influence
                  scores.
          checkpoints_load_func (Callable, optional): The function to load a saved
                  checkpoint into a model to update its parameters, and get the
                  learning rate if it is saved. By default uses a utility to load a
                  model saved as a state dict.
                  Default: _load_flexible_state_dict
          layers (list[str] or None, optional): A list of layer names for which
                  gradients should be computed. If `layers` is None, gradients will
                  be computed for all layers. Otherwise, they will only be computed
                  for the layers specified in `layers`.
                  Default: None
          loss_fn (Callable, optional): The loss function applied to model. For now,
                  we require it to be a "reduction='none'" loss function. For
                  example, `BCELoss(reduction='none')` would be acceptable, but
                  `BCELoss(reduction='sum')` would not.
          batch_size (int or None, optional): Batch size of the DataLoader created to
                  iterate through `train_dataset` and `hessian_dataset`, if they are
                  of type `Dataset`. `batch_size` should be chosen as large as
                  possible so that a backwards pass on a batch still fits in memory.
                  If `train_dataset` and `hessian_dataset`are both of type
                  `DataLoader`, then `batch_size` is ignored as an argument.
                  Default: 1
          hessian_dataset (Dataset or Dataloader, optional): The influence score and
                  self-influence scores this implementation calculates are defined in
                  terms of the Hessian, i.e. the second-derivative of the model
                  parameters. This argument provides the dataset used for calculating
                  the Hessian. It should be smaller than `train_dataset`, which
                  is the dataset whose examples we want the influence of. If not
                  provided or none, it will be assumed to be the same as
                  `train_dataset`.
                  Default: None
          test_loss_fn (Callable, optional): In some cases, one may want to use a
                  separate loss functions for training examples, i.e. those in
                  `train_dataset`, and for test examples, i.e. those
                  represented by the `inputs` and `targets` arguments to the
                  `influence` method. For example, if one wants to calculate the
                  influence score of a training example on a test example's
                  prediction for a fixed class, `test_loss_fn` could map from the
                  logits for all classes to the logits for a fixed class.
                  `test_loss_fn` needs satisfy the same constraints as `loss_fn`.
                  Thus, the same checks that we apply to `loss_fn` are also applied
                  to `test_loss_fn`, if the latter is provided. Note that the
                  constraints on both `loss_fn` and `test_loss_fn` both depend on
                  `sample_wise_grads_per_batch`. This means `loss_fn` and
                  `test_loss_fn` must either both be "per-example"  loss functions,
                  or both be "reduction" loss functions. If not provided, the loss
                  function for test examples is assumed to be the same as the loss
                  function for training examples, i.e. `loss_fn`.
                  Default: None
          sample_wise_grads_per_batch (bool, optional): PyTorch's native gradient
                  computations w.r.t. model parameters aggregates the results for a
                  batch and does not allow to access sample-wise gradients w.r.t.
                  model parameters. This forces us to iterate over each sample in
                  the batch if we want sample-wise gradients which is computationally
                  inefficient. We offer an implementation of batch-wise gradient
                  computations w.r.t. to model parameters which is computationally
                  more efficient. This implementation can be enabled by setting the
                  `sample_wise_grad_per_batch` argument to `True`, and should be
                  enabled if and only if the `loss_fn` argument is a "reduction" loss
                  function. For example, `nn.BCELoss(reduction="sum")` would be a
                  valid `loss_fn` if this implementation is enabled (see
                  documentation for `loss_fn` for more details). Note that our
                  current implementation enables batch-wise gradient computations
                  only for a limited number of PyTorch nn.Modules: Conv2D and Linear.
                  This list will be expanded in the near future.  Therefore, please
                  do not enable this implementation if gradients will be computed
                  for other kinds of layers.
                  Default: False
          projection_dim (int, optional): This implementation produces a low-rank
                  approximation of the (inverse) Hessian. This is the rank of that
                  approximation, and also corresponds to the dimension of the
                  "influence embeddings" produced by the
                  `compute_intermediate_quantities` method.
                  Default: 50
          seed (int, optional): This implementation has a source of randomness - the
                  initialization basis to the Arnoldi iteration. This seed is used
                  to make that randomness reproducible.
                  Default: 42
          hessian_reg (float, optional): We add an entry to the hessian's diagonal
                  entries before computing its eigenvalues / eigenvectors.
                  This is that entry.
                  Default: 1e-6
          hessian_inverse_tol: (float) The tolerance to use when computing the
                  pseudo-inverse of the (square root of) hessian.
                  Default: 1e-6
          projection_on_cpu (bool, optional): Whether to move the projection,
                  i.e. low-rank approximation of the inverse Hessian, to cpu, to save
                  gpu memory.
                  Default: True
          show_progress (bool, optional): This implementation explicitly computes the
                  Hessian over batches in `hessian_dataloader` (and sums them) which
                  can take a long time. If `show_progress` is true, the number of
                  batches for which the Hessian 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
      """
      InfluenceFunctionBase.__init__(
          self,
          model,
          train_dataset,
          checkpoint,
          checkpoints_load_func,
          layers,
          loss_fn,
          batch_size,
          hessian_dataset,
          test_loss_fn,
          sample_wise_grads_per_batch,
      )
  
      self.projection_dim = projection_dim
      torch.manual_seed(seed)  # for reproducibility
  
      self.hessian_reg = hessian_reg
      self.hessian_inverse_tol = hessian_inverse_tol
  
      # infer the device the model is on.  all parameters are assumed to be on the
      # same device
      self.model_device = next(model.parameters()).device
  
      self.R = self._retrieve_projections_naive_influence_function(
          self.hessian_dataloader,
          projection_on_cpu,
          show_progress,
      )
  
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 1 to create a new NaiveInfluenceFunction object from inherited base classes: IntermediateQuantitiesInfluenceFunction with example: obj = NaiveInfluenceFunction(model, train_dataset, checkpoint, checkpoints_load_func, layers, loss_fn, batch_size, hessian_dataset, test_loss_fn, sample_wise_grads_per_batch, projection_dim, seed, hessian_reg, hessian_inverse_tol, projection_on_cpu, show_progress)