code: def test_named_tensors(self):
      model = nn.BatchNorm1d(4)
      named_tensors = named_module_tensors(model)
      self.assertListEqual(
          [name for name, _ in named_tensors],
          [
              "weight",
              "bias",
              "running_mean",
              "running_var",
              "num_batches_tracked",
          ],
      )
  
      named_tensors = named_module_tensors(model, include_buffers=False)
      self.assertListEqual(
          [name for name, _ in named_tensors], ["weight", "bias"]
      )
  
      model = ModelForTest()
      named_tensors = named_module_tensors(model)
      self.assertListEqual([name for name, _ in named_tensors], [])
  
      named_tensors = named_module_tensors(model, recurse=True)
      self.assertListEqual(
          [name for name, _ in named_tensors],
          [
              "linear1.weight",
              "linear1.bias",
              "batchnorm.weight",
              "batchnorm.bias",
              "linear2.weight",
              "linear2.bias",
              "batchnorm.running_mean",
              "batchnorm.running_var",
              "batchnorm.num_batches_tracked",
          ],
      )
  
      named_tensors = named_module_tensors(
          model, include_buffers=False, recurse=True
      )
      self.assertListEqual(
          [name for name, _ in named_tensors],
          [
              "linear1.weight",
              "linear1.bias",
              "batchnorm.weight",
              "batchnorm.bias",
              "linear2.weight",
              "linear2.bias",
          ],
      )
  
      model = LinearWithNonPersistentBuffers(10, 10)
  
      named_tensors = named_module_tensors(
          model, include_buffers=True, remove_non_persistent=False
      )
      self.assertListEqual(
          [name for name, _ in named_tensors], ["weight", "bias"]
      )
  
      named_tensors = named_module_tensors(
          model, include_buffers=True, remove_non_persistent=True
      )
      self.assertListEqual(
          [name for name, _ in named_tensors], ["weight"]
      )
  
imports: import json
  import os
  import tempfile
  import unittest
  from collections import OrderedDict
  import torch
  import torch.nn
  from safetensors.torch import save_file
  from accelerate import init_empty_weights
  from accelerate.test_utils import require_cuda, require_huggingface_suite, require_multi_gpu
  from accelerate.utils.modeling import check_device_map, clean_device_map, compute_module_sizes, convert_file_size_to_int, find_tied_parameters, get_balanced_memory, infer_auto_device_map, load_checkpoint_in_model, load_state_dict, named_module_tensors, retie_parameters, set_module_tensor_to_device
label_desc: Use image node_id 8 for calling the ModelingUtilsTester obj's underlying member method code with example usage: obj.test_named_tensors() without return types