class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test to verify saving multiple different modules and
  repeats of same scriptmodule in package works. Also tests that
  PyTorchStreamReader isn't having code hidden from
  PyTorchStreamWriter writing ScriptModule code files multiple times.
docstr_tok: ["Test","to","verify","saving","multiple","different","modules","and","repeats","of","same","scriptmodule","in","package","works",".","Also","tests","that","PyTorchStreamReader","is","n't","having","code","hidden","from","PyTorchStreamWriter","writing","ScriptModule","code","files","multiple","times","."]
code: def test_save_repeat_scriptmodules(self):
      """
      Test to verify saving multiple different modules and
      repeats of same scriptmodule in package works. Also tests that
      PyTorchStreamReader isn't having code hidden from
      PyTorchStreamWriter writing ScriptModule code files multiple times.
      """
      from package_a.test_module import (
          ModWithSubmodAndTensor,
          ModWithTensor,
          SimpleTest,
      )
  
      scripted_mod_0 = torch.jit.script(SimpleTest())
      scripted_mod_1 = torch.jit.script(
          ModWithTensor(torch.rand(1, 2, 3))
      )
      scripted_mod_2 = torch.jit.script(
          ModWithSubmodAndTensor(
              torch.rand(1, 2, 3), ModWithTensor(torch.rand(1, 2, 3))
          )
      )
  
      buffer = BytesIO()
      with PackageExporter(buffer) as e:
          e.save_pickle("res", "mod0.pkl", scripted_mod_0)
          e.save_pickle("res", "mod1.pkl", scripted_mod_1)
          e.save_pickle("res", "mod2.pkl", scripted_mod_0)
          e.save_pickle("res", "mod3.pkl", scripted_mod_1)
          e.save_pickle("res", "mod4.pkl", scripted_mod_2)
  
      buffer.seek(0)
      importer = PackageImporter(buffer)
      loaded_mod_0 = importer.load_pickle("res", "mod0.pkl")
      loaded_mod_1 = importer.load_pickle("res", "mod3.pkl")
      loaded_mod_2 = importer.load_pickle("res", "mod4.pkl")
      input = torch.rand(1, 2, 3)
      self.assertEqual(loaded_mod_0(input), scripted_mod_0(input))
      self.assertEqual(loaded_mod_1(input), scripted_mod_1(input))
      self.assertEqual(loaded_mod_2(input), scripted_mod_2(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 11 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_save_repeat_scriptmodules() without return types