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 across multiple package saves and loads. This is
  an important test because not all of the tensor information is restored
  in python between packages. The python identity is not maintained, but
  the backing cpp TensorImpl is. We load/save storages based off of this
  cpp TensorImpl and not the python identity.
docstr_tok: ["Test","tensors","shared","across","eager","and","ScriptModules","on","load","are","the","same","across","multiple","package","saves","and","loads",".","This","is","an","important","test","because","not","all","of","the","tensor","information","is","restored","in","python","between","packages",".","The","python","identity","is","not","maintained",",","but","the","backing","cpp","TensorImpl","is",".","We","load\/save","storages","based","off","of","this","cpp","TensorImpl","and","not","the","python","identity","."]
code: def test_load_shared_tensors_repackaged(self):
      """
      Test tensors shared across eager and ScriptModules on load
      are the same across multiple package saves and loads. This is
      an important test because not all of the tensor information is restored
      in python between packages. The python identity is not maintained, but
      the backing cpp TensorImpl is. We load/save storages based off of this
      cpp TensorImpl and not the python identity.
      """
      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
      )
  
      buffer_0 = BytesIO()
      with PackageExporter(buffer_0) as e:
          e.intern("**")
          e.save_pickle("res", "mod1.pkl", mod1)
  
      buffer_0.seek(0)
      importer_0 = PackageImporter(buffer_0)
      loaded_mod_0 = importer_0.load_pickle("res", "mod1.pkl")
  
      buffer_1 = BytesIO()
      with PackageExporter(buffer_1, importer=importer_0) as e:
          e.intern("**")
          e.save_pickle("res", "mod1.pkl", loaded_mod_0)
  
      buffer_1.seek(0)
      importer = PackageImporter(buffer_1)
      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)
      )  # all tensors should reflect this change
  
      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 19 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_load_shared_tensors_repackaged() without return types