code: def test_average_checkpoints_with_shared_parameters(self):
      def _construct_model_with_shared_parameters(path, value):
          m = ModelWithSharedParameter()
          nn.init.constant_(m.FC1.weight, value)
          torch.save({"model": m.state_dict()}, path)
          return m
  
      tmpdir = tempfile.mkdtemp()
      paths = []
      path = os.path.join(tmpdir, "m1.pt")
      m1 = _construct_model_with_shared_parameters(path, 1.0)
      paths.append(path)
  
      path = os.path.join(tmpdir, "m2.pt")
      m2 = _construct_model_with_shared_parameters(path, 2.0)
      paths.append(path)
  
      path = os.path.join(tmpdir, "m3.pt")
      m3 = _construct_model_with_shared_parameters(path, 3.0)
      paths.append(path)
  
      new_model = average_checkpoints(paths)
      self.assertTrue(
          torch.equal(
              new_model["model"]["embedding.weight"],
              (
                  m1.embedding.weight
                  + m2.embedding.weight
                  + m3.embedding.weight
              )
              / 3.0,
          )
      )
  
      self.assertTrue(
          torch.equal(
              new_model["model"]["FC1.weight"],
              (m1.FC1.weight + m2.FC1.weight + m3.FC1.weight) / 3.0,
          )
      )
  
      self.assertTrue(
          torch.equal(
              new_model["model"]["FC2.weight"],
              (m1.FC2.weight + m2.FC2.weight + m3.FC2.weight) / 3.0,
          )
      )
      shutil.rmtree(tmpdir)
  
file_path: fairseq/tests/test_average_checkpoints.py
imports: import collections
  import os
  import shutil
  import tempfile
  import unittest
  import numpy
  import torch
  from scripts.average_checkpoints import average_checkpoints
  from torch import nn
label_desc: Use image node_id 2 for calling the TestAverageCheckpoints obj's underlying member method code with example usage: obj.test_average_checkpoints_with_shared_parameters() and returns: m