class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test to verify saving and loading same ScriptModule object works
  across multiple packages.
docstr_tok: ["Test","to","verify","saving","and","loading","same","ScriptModule","object","works","across","multiple","packages","."]
code: def test_scriptmodules_repeat_save(self):
      """
      Test to verify saving and loading same ScriptModule object works
      across multiple packages.
      """
      from package_a.test_module import (
          ModWithSubmodAndTensor,
          ModWithTensor,
      )
  
      scripted_mod_0 = torch.jit.script(
          ModWithTensor(torch.rand(1, 2, 3))
      )
      scripted_mod_1 = torch.jit.script(
          ModWithSubmodAndTensor(
              torch.rand(1, 2, 3), ModWithTensor(torch.rand(1, 2, 3))
          )
      )
  
      buffer_0 = BytesIO()
      with PackageExporter(buffer_0) as e:
          e.save_pickle("res", "mod1.pkl", scripted_mod_0)
  
      buffer_0.seek(0)
      importer_0 = PackageImporter(buffer_0)
      loaded_module_0 = importer_0.load_pickle("res", "mod1.pkl")
  
      buffer_1 = BytesIO()
      with PackageExporter(buffer_1) as e:
          e.save_pickle("res", "mod1.pkl", scripted_mod_1)
          e.save_pickle("res", "mod2.pkl", loaded_module_0)
  
      buffer_1.seek(0)
      importer_1 = PackageImporter(buffer_1)
      loaded_module_1 = importer_1.load_pickle("res", "mod1.pkl")
      reloaded_module_0 = importer_1.load_pickle("res", "mod2.pkl")
  
      input = torch.rand(1, 2, 3)
      self.assertEqual(loaded_module_0(input), scripted_mod_0(input))
      self.assertEqual(loaded_module_0(input), reloaded_module_0(input))
      self.assertEqual(loaded_module_1(input), scripted_mod_1(input))
  
imports: from io import BytesIO
  from textwrap import dedent
  from unittest import skipIf
  import torch
  from torch.package import PackageExporter, PackageImporter
  from torch.testing._internal.common_utils import IS_FBCODE, IS_SANDCASTLE, run_tests
label_desc: Use image node_id 12 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_scriptmodules_repeat_save() without return types