code: def test_generate_dataset_activations(self) -> None:
      with tempfile.TemporaryDirectory() as tmpdir:
          num_features = 4
          low, high = 0, 16
          batch_size = high // 2
          mymodel = BasicLinearReLULinear(num_features)
          mydata = RangeDataset(low, high, num_features)
          layers: List[str] = [
              value[0] for value in mymodel.named_modules() if value[0]
          ]
  
          # First AV generation on last 2 layers
          layer_AVDatasets = AV.generate_dataset_activations(
              tmpdir,
              mymodel,
              "model_id1",
              layers[1:],
              DataLoader(mydata, batch_size, shuffle=False),
              "src",
              return_activations=True,
          )
  
          av_src = AV._construct_file_search(
              tmpdir, model_id="model_id1", identifier="src"
          )
          av_src = glob.glob(av_src)
          self.assertEqual(
              len(av_src), high / batch_size * len(layers[1:])
          )
  
          self.assertTrue(isinstance(layer_AVDatasets, list))
          layer_AVDatasets = cast(list, layer_AVDatasets)
          self.assertEqual(len(layer_AVDatasets), len(layers[1:]))
          for layer_AVDataset in layer_AVDatasets:
              self.assertEqual(len(layer_AVDataset), high / batch_size)
  
          # Second AV generation on first 2 layers.
          # Second layer overlaps with existing activations, should be loaded.
          layer_AVDatasets = AV.generate_dataset_activations(
              tmpdir,
              mymodel,
              "model_id1",
              layers[:2],
              DataLoader(mydata, batch_size, shuffle=False),
              "src",
              return_activations=True,
          )
  
          av_src = AV._construct_file_search(
              tmpdir, model_id="model_id1", identifier="src"
          )
          av_src = glob.glob(av_src)
          self.assertEqual(len(av_src), high / batch_size * len(layers))
  
          self.assertTrue(isinstance(layer_AVDatasets, list))
          layer_AVDatasets = cast(list, layer_AVDatasets)
          self.assertEqual(len(layer_AVDatasets), len(layers[:2]))
          for layer_AVDataset in layer_AVDatasets:
              self.assertEqual(len(layer_AVDataset), high / batch_size)
  
          # check that if return_activations is False, None is returned
          self.assertIsNone(
              AV.generate_dataset_activations(
                  tmpdir,
                  mymodel,
                  "model_id1",
                  layers[:2],
                  DataLoader(mydata, batch_size, shuffle=False),
                  "src",
                  return_activations=False,
              )
          )
  
imports: import glob
  import tempfile
  from datetime import datetime
  from typing import cast, List
  import torch
  from captum._utils.av import AV
  from tests.helpers.basic import assertTensorAlmostEqual, BaseTest
  from tests.helpers.basic_models import BasicLinearReLULinear
  from torch.utils.data import DataLoader, Dataset
label_desc: Use image node_id 13 for calling the Test obj's underlying member method code with example usage: obj.test_generate_dataset_activations() without return types