class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test saving inline and imported modules in same package that
  share code.
docstr_tok: ["Test","saving","inline","and","imported","modules","in","same","package","that","share","code","."]
code: def test_mixing_packaged_and_inline_modules_shared_code(self):
      """
      Test saving inline and imported modules in same package that
      share code.
      """
  
      class TorchVisionTestInline(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.tvmod = resnet18()
  
          def forward(self, x):
              x = a_non_torch_leaf(x, x)
              return torch.relu(x + 3.0)
  
      def a_non_torch_leaf(a, b):
          return a + b
  
      inline_mod = TorchVisionTestInline()
      scripted_inline = torch.jit.script(inline_mod)
  
      from package_c.test_module import TorchVisionTest
  
      imported_mod = TorchVisionTest()
      scripted_imported = torch.jit.script(imported_mod)
  
      buffer = BytesIO()
      with PackageExporter(buffer) as e:
          e.save_pickle("model", "inline.pkl", scripted_inline)
          e.save_pickle("model", "imported.pkl", scripted_imported)
  
      buffer.seek(0)
      importer = PackageImporter(buffer)
      loaded_inline = importer.load_pickle("model", "inline.pkl")
      loaded_imported = importer.load_pickle("model", "imported.pkl")
  
      input = torch.rand(2, 3)
      self.assertEqual(loaded_imported(input), imported_mod(input))
      self.assertEqual(loaded_inline(input), inline_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 22 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_mixing_packaged_and_inline_modules_shared_code() and returns: unknown, torch