class_docstr: This class provides functionality to store and load activation vectors
  generated for pre-defined neural network layers.
  It also provides functionality to check if activation vectors already
  exist in the manifold and other auxiliary functions.
  
  This class also defines a torch `Dataset`, representing Activation Vectors,
  which enables lazy access to activation vectors and layer stored in the manifold.
class_docstr_tok: ["This","class","provides","functionality","to","store","and","load","activation","vectors","generated","for","pre-defined","neural","network","layers",".","It","also","provides","functionality","to","check","if","activation","vectors","already","exist","in","the","manifold","and","other","auxiliary","functions",".","This","class","also","defines","a","torch","`","Dataset","`",",","representing","Activation","Vectors",",","which","enables","lazy","access","to","activation","vectors","and","layer","stored","in","the","manifold","."]
docstr: Computes layer activations for a source dataset and specified `layers`. Assumes
  that the dataset returns a single value, or a tuple containing two elements
  (see AV._unpack_data).
  
  Args:
      path (str): The path where the activation vectors
              for the `layer` are stored.
      module (torch.nn.Module): An instance of pytorch model. This model should
              define all of its layers as attributes of the model.
      model_id (str): The name/version of the model for which layer activations
              are being computed and stored.
      layers (str or list[str]): The layer(s) for which the activation vectors
              are computed.
      dataloader (torch.utils.data.DataLoader): DataLoader that yields Dataset
              for which influential instances are computed. They are passed to
              input `model`.
      identifier (str or None): An identifier for the layer
              activations. Can be used to distinguish between activations for
              different training batches.
              Default: "default"
      load_from_disk (bool): Forces function to regenerate activations if False.
              Default: True
      return_activations (bool, optional): Whether to return the activations.
              Default: False
  Returns: If `return_activations == True`, returns a single `AVDataset` if
              `layers` is a str, otherwise, a list of `AVDataset`s of the length
              of `layers`, where each element corresponds to a layer.  In either
              case, `AVDataset`'s represent the activations for a single layer,
              over the entire `dataloader`.  If `return_activations == False`,
              does not return anything.
docstr_tok: ["Computes","layer","activations","for","a","source","dataset","and","specified","`","layers","`",".","Assumes","that","the","dataset","returns","a","single","value",",","or","a","tuple","containing","two","elements","(","see","AV._unpack_data",")",".","Args",":","path","(","str",")",":","The","path","where","the","activation","vectors","for","the","`","layer","`","are","stored",".","module","(","torch.nn.Module",")",":","An","instance","of","pytorch","model",".","This","model","should","define","all","of","its","layers","as","attributes","of","the","model",".","model_id","(","str",")",":","The","name\/version","of","the","model","for","which","layer","activations","are","being","computed","and","stored",".","layers","(","str","or","list","[","str","]",")",":","The","layer","(","s",")","for","which","the","activation","vectors","are","computed",".","dataloader","(","torch.utils.data.DataLoader",")",":","DataLoader","that","yields","Dataset","for","which","influential","instances","are","computed",".","They","are","passed","to","input","`","model","`",".","identifier","(","str","or","None",")",":","An","identifier","for","the","layer","activations",".","Can","be","used","to","distinguish","between","activations","for","different","training","batches",".","Default",":","``","default","''","load_from_disk","(","bool",")",":","Forces","function","to","regenerate","activations","if","False",".","Default",":","True","return_activations","(","bool",",","optional",")",":","Whether","to","return","the","activations",".","Default",":","False","Returns",":","If","`","return_activations","==","True","`",",","returns","a","single","`","AVDataset","`","if","`","layers","`","is","a","str",",","otherwise",",","a","list","of","`","AVDataset","`","s","of","the","length","of","`","layers","`",",","where","each","element","corresponds","to","a","layer",".","In","either","case",",","`","AVDataset","`","'s","represent","the","activations","for","a","single","layer",",","over","the","entire","`","dataloader","`",".","If","`","return_activations","==","False","`",",","does","not","return","anything","."]
code: def generate_dataset_activations(
      path: str,
      model: Module,
      model_id: str,
      layers: Union[str, List[str]],
      dataloader: DataLoader,
      identifier: str = "default",
      load_from_disk: bool = True,
      return_activations: bool = False,
  ) -> Optional[Union[AVDataset, List[AVDataset]]]:
      r"""
      Computes layer activations for a source dataset and specified `layers`. Assumes
      that the dataset returns a single value, or a tuple containing two elements
      (see AV._unpack_data).
  
      Args:
          path (str): The path where the activation vectors
                  for the `layer` are stored.
          module (torch.nn.Module): An instance of pytorch model. This model should
                  define all of its layers as attributes of the model.
          model_id (str): The name/version of the model for which layer activations
                  are being computed and stored.
          layers (str or list[str]): The layer(s) for which the activation vectors
                  are computed.
          dataloader (torch.utils.data.DataLoader): DataLoader that yields Dataset
                  for which influential instances are computed. They are passed to
                  input `model`.
          identifier (str or None): An identifier for the layer
                  activations. Can be used to distinguish between activations for
                  different training batches.
                  Default: "default"
          load_from_disk (bool): Forces function to regenerate activations if False.
                  Default: True
          return_activations (bool, optional): Whether to return the activations.
                  Default: False
      Returns: If `return_activations == True`, returns a single `AVDataset` if
                  `layers` is a str, otherwise, a list of `AVDataset`s of the length
                  of `layers`, where each element corresponds to a layer.  In either
                  case, `AVDataset`'s represent the activations for a single layer,
                  over the entire `dataloader`.  If `return_activations == False`,
                  does not return anything.
  
      """
  
      unsaved_layers = AV._manage_loading_layers(
          path,
          model_id,
          layers,
          load_from_disk,
          identifier,
      )
      if len(unsaved_layers) > 0:
          for i, data in enumerate(dataloader):
              AV._compute_and_save_activations(
                  path,
                  model,
                  model_id,
                  layers,
                  AV._unpack_data(data),
                  identifier,
                  str(i),
              )
  
      if not return_activations:
          return None
      if isinstance(layers, str):
          return AV.load(path, model_id, identifier, layers)
      else:
          return [
              AV.load(path, model_id, identifier, layer)
              for layer in layers
          ]
  
imports: import glob
  import os
  import re
  import warnings
  from typing import Any, List, Optional, Tuple, Union
  import captum._utils.common
  import torch
  from captum.attr import LayerActivation
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.data import DataLoader, Dataset
label_desc: Use image node_id 11 for calling the AV obj's underlying member method code with example usage: obj.generate_dataset_activations(path, model, model_id, layers, dataloader, identifier, load_from_disk, return_activations) and returns: None, AV, unknown