class_docstr: `InfluenceFunctionBase` is a base class for implementations which compute the
  influence score as defined in the paper "Understanding Black-box Predictions via
  Influence Functions" (https://arxiv.org/pdf/1703.04730.pdf). This "infinitesimal"
  influence score approximately answers the question if a given training example
  were infinitesimally down-weighted and the model re-trained to optimality, how much
  would the loss on a given test example change. Mathematically, the aforementioned
  influence score is given by :math`\nabla_\theta L(x)' H^{-1} \nabla_\theta L(z)`,
  where :math`\nabla_\theta L(x)` is the gradient of the loss, considering only
  training example :math`x` with respect to (a subset of) model parameters
  :math`\theta`, :math`\nabla_\theta L(z)` is the analogous quantity for a test
  example :math`z`, and :math`H` is the Hessian of the (subset of) model parameters
  at a given model checkpoint. "Subset of model parameters" refers to the parameters
  specified by the `layers` initialization argument; for computational purposes,
  we may only consider the gradients / Hessian involving parameters in a subset of
  the model's layers. This is a commonly-taken approach in the research literature.
  
  There can be multiple implementations of this class, because although the paper
  defines a particular "infinitesimal" kind of influence score, there can be multiple
  ways to compute it, each with different levels of accuracy / scalability.
docstr: Computes self influence scores for the examples in `inputs_dataset`, which is
  either a single batch or a Pytorch `DataLoader` that yields batches. Therefore,
  the computed self influence scores are *not* for the examples in training
  dataset `train_dataset` (unlike when computing self influence scores using the
  `influence` method). Note that if `inputs_dataset` is a single batch, this
  will call `model` on that single batch, and if `inputs_dataset` yields
  batches, this will call `model` on each batch that is yielded. Therefore,
  please ensure that for both cases, the batch(es) that `model` is called
  with are not too large, so that there will not be an out-of-memory error.
  
  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 `batch[-1]` are the labels, if any. This is the same
              assumption made for each batch yielded by training dataset
              `train_dataset`.
      show_progress (bool, optional): Computation of self influence scores can
              take a long time if `inputs_dataset` represents many examples. If
              `show_progress` is true, the progress of this computation will be
              displayed. In more detail, this computation will iterate over all
              checkpoints (provided as the `checkpoints` initialization argument)
              in an outer loop, and iterate over all batches that
              `inputs_dataset` represents in an inner loop. Therefore, the
              total number of (checkpoint, batch) combinations that need to be
              iterated over is
              (# of checkpoints x # of batches that `inputs_dataset` represents).
              If `show_progress` is True, the total progress of both the outer
              iteration over checkpoints and the inner iteration over batches is
              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:
      self_influence_scores (Tensor): This is a 1D tensor containing the self
              influence scores of all examples in `inputs_dataset`, regardless of
              whether it represents a single batch or a `DataLoader` that yields
              batches.
docstr_tok: ["Computes","self","influence","scores","for","the","examples","in","`","inputs_dataset","`",",","which","is","either","a","single","batch","or","a","Pytorch","`","DataLoader","`","that","yields","batches",".","Therefore",",","the","computed","self","influence","scores","are","*","not","*","for","the","examples","in","training","dataset","`","train_dataset","`","(","unlike","when","computing","self","influence","scores","using","the","`","influence","`","method",")",".","Note","that","if","`","inputs_dataset","`","is","a","single","batch",",","this","will","call","`","model","`","on","that","single","batch",",","and","if","`","inputs_dataset","`","yields","batches",",","this","will","call","`","model","`","on","each","batch","that","is","yielded",".","Therefore",",","please","ensure","that","for","both","cases",",","the","batch","(","es",")","that","`","model","`","is","called","with","are","not","too","large",",","so","that","there","will","not","be","an","out-of-memory","error",".","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","`","batch","[","-1","]","`","are","the","labels",",","if","any",".","This","is","the","same","assumption","made","for","each","batch","yielded","by","training","dataset","`","train_dataset","`",".","show_progress","(","bool",",","optional",")",":","Computation","of","self","influence","scores","can","take","a","long","time","if","`","inputs_dataset","`","represents","many","examples",".","If","`","show_progress","`","is","true",",","the","progress","of","this","computation","will","be","displayed",".","In","more","detail",",","this","computation","will","iterate","over","all","checkpoints","(","provided","as","the","`","checkpoints","`","initialization","argument",")","in","an","outer","loop",",","and","iterate","over","all","batches","that","`","inputs_dataset","`","represents","in","an","inner","loop",".","Therefore",",","the","total","number","of","(","checkpoint",",","batch",")","combinations","that","need","to","be","iterated","over","is","(","#","of","checkpoints","x","#","of","batches","that","`","inputs_dataset","`","represents",")",".","If","`","show_progress","`","is","True",",","the","total","progress","of","both","the","outer","iteration","over","checkpoints","and","the","inner","iteration","over","batches","is","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",":","self_influence_scores","(","Tensor",")",":","This","is","a","1D","tensor","containing","the","self","influence","scores","of","all","examples","in","`","inputs_dataset","`",",","regardless","of","whether","it","represents","a","single","batch","or","a","`","DataLoader","`","that","yields","batches","."]
code: def self_influence(
      self,
      inputs_dataset: Optional[
          Union[Tuple[Any, ...], DataLoader]
      ] = None,
      show_progress: bool = False,
  ) -> Tensor:
      """
      Computes self influence scores for the examples in `inputs_dataset`, which is
      either a single batch or a Pytorch `DataLoader` that yields batches. Therefore,
      the computed self influence scores are *not* for the examples in training
      dataset `train_dataset` (unlike when computing self influence scores using the
      `influence` method). Note that if `inputs_dataset` is a single batch, this
      will call `model` on that single batch, and if `inputs_dataset` yields
      batches, this will call `model` on each batch that is yielded. Therefore,
      please ensure that for both cases, the batch(es) that `model` is called
      with are not too large, so that there will not be an out-of-memory error.
  
      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 `batch[-1]` are the labels, if any. This is the same
                  assumption made for each batch yielded by training dataset
                  `train_dataset`.
          show_progress (bool, optional): Computation of self influence scores can
                  take a long time if `inputs_dataset` represents many examples. If
                  `show_progress` is true, the progress of this computation will be
                  displayed. In more detail, this computation will iterate over all
                  checkpoints (provided as the `checkpoints` initialization argument)
                  in an outer loop, and iterate over all batches that
                  `inputs_dataset` represents in an inner loop. Therefore, the
                  total number of (checkpoint, batch) combinations that need to be
                  iterated over is
                  (# of checkpoints x # of batches that `inputs_dataset` represents).
                  If `show_progress` is True, the total progress of both the outer
                  iteration over checkpoints and the inner iteration over batches is
                  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:
          self_influence_scores (Tensor): This is a 1D tensor containing the self
                  influence scores of all examples in `inputs_dataset`, regardless of
                  whether it represents a single batch or a `DataLoader` that yields
                  batches.
      """
      pass
  
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 2 for calling the InfluenceFunctionBase obj's underlying member method code with example usage: obj.self_influence(inputs_dataset, show_progress) without return types