class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test tensors shared across eager and ScriptModules on load
  are the same.
docstr_tok: ["Test","tensors","shared","across","eager","and","ScriptModules","on","load","are","the","same","."]
code: def test_load_shared_tensors(self):
      """
      Test tensors shared across eager and ScriptModules on load
      are the same.
      """
      from package_a.test_module import (
          ModWithTensor,
          ModWithTwoSubmodsAndTensor,
      )
  
      shared_tensor = torch.ones(3, 3)
  
      scripted_mod_0 = torch.jit.script(ModWithTensor(shared_tensor))
      scripted_mod_1 = torch.jit.script(ModWithTensor(shared_tensor))
  
      mod1 = ModWithTwoSubmodsAndTensor(
          shared_tensor, scripted_mod_0, scripted_mod_1
      )
  
      self.assertEqual(
          shared_tensor.storage()._cdata,
          scripted_mod_0.tensor.storage()._cdata,
      )
      self.assertEqual(
          shared_tensor.storage()._cdata,
          scripted_mod_1.tensor.storage()._cdata,
      )
  
      buffer = BytesIO()
      with PackageExporter(buffer) as e:
          e.intern("**")
          e.save_pickle("res", "mod1.pkl", mod1)
  
      buffer.seek(0)
      importer = PackageImporter(buffer)
      loaded_mod_1 = importer.load_pickle("res", "mod1.pkl")
  
      self.assertEqual(
          loaded_mod_1.tensor.storage()._cdata,
          loaded_mod_1.sub_mod_0.tensor.storage()._cdata,
      )
      self.assertEqual(
          loaded_mod_1.tensor.storage()._cdata,
          loaded_mod_1.sub_mod_1.tensor.storage()._cdata,
      )
  
      loaded_mod_1.tensor.add_(torch.ones(3, 3))
  
      self.assertTrue(
          torch.allclose(
              loaded_mod_1.tensor, loaded_mod_1.sub_mod_0.tensor
          )
      )
      self.assertTrue(
          torch.allclose(
              loaded_mod_1.tensor, loaded_mod_1.sub_mod_1.tensor
          )
      )
  
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 18 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_load_shared_tensors() without return types