class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test saving of ScriptModules inside of container. Checks that relations
  between shared modules are upheld.
docstr_tok: ["Test","saving","of","ScriptModules","inside","of","container",".","Checks","that","relations","between","shared","modules","are","upheld","."]
code: def test_save_scriptmodules_in_container(self):
      """
      Test saving of ScriptModules inside of container. Checks that relations
      between shared modules are upheld.
      """
      from package_a.test_module import (
          ModWithSubmodAndTensor,
          ModWithTensor,
      )
  
      scripted_mod_a = torch.jit.script(
          ModWithTensor(torch.rand(1, 2, 3))
      )
      scripted_mod_b = torch.jit.script(
          ModWithSubmodAndTensor(torch.rand(1, 2, 3), scripted_mod_a)
      )
      script_mods_list = [scripted_mod_a, scripted_mod_b]
  
      buffer = BytesIO()
      with PackageExporter(buffer) as e:
          e.save_pickle("res", "list.pkl", script_mods_list)
  
      buffer.seek(0)
      importer = PackageImporter(buffer)
      loaded_mod_list = importer.load_pickle("res", "list.pkl")
      input = torch.rand(1, 2, 3)
      self.assertEqual(loaded_mod_list[0](input), scripted_mod_a(input))
      self.assertEqual(loaded_mod_list[1](input), scripted_mod_b(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 14 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_save_scriptmodules_in_container() without return types