class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test scripting a module loaded from a package
  and saving it in a new package as a script object.
docstr_tok: ["Test","scripting","a","module","loaded","from","a","package","and","saving","it","in","a","new","package","as","a","script","object","."]
code: def test_saving_and_scripting_packaged_mod(self):
      """
      Test scripting a module loaded from a package
      and saving it in a new package as a script object.
      """
      from package_a.test_module import SimpleTest
  
      orig_mod = SimpleTest()
  
      buffer_0 = BytesIO()
      with PackageExporter(buffer_0) as e:
          e.intern("**")
          e.save_pickle("model", "model.pkl", orig_mod)
  
      buffer_0.seek(0)
      importer_0 = PackageImporter(buffer_0)
      loaded_mod = importer_0.load_pickle("model", "model.pkl")
  
      input = torch.rand(2, 3)
      self.assertEqual(loaded_mod(input), orig_mod(input))
  
      scripted_mod = torch.jit.script(loaded_mod)
  
      buffer_1 = BytesIO()
      with PackageExporter(buffer_1, importer=importer_0) as e:
          e.intern("**")
          e.save_pickle("res", "scripted_mod.pkl", scripted_mod)
  
      buffer_1.seek(0)
      importer_1 = PackageImporter(buffer_1)
      loaded_mod_scripted = importer_1.load_pickle(
          "res", "scripted_mod.pkl"
      )
  
      self.assertEqual(loaded_mod_scripted(input), orig_mod(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 20 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_saving_and_scripting_packaged_mod() without return types