class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test that saving a ScriptModule and a separately saving a tensor
  object causes no issues.
docstr_tok: ["Test","that","saving","a","ScriptModule","and","a","separately","saving","a","tensor","object","causes","no","issues","."]
code: def test_tensor_sharing_pickle(self):
      """Test that saving a ScriptModule and a separately saving a tensor
      object causes no issues.
      """
  
      class M(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.foo = torch.ones(2, 3)
  
          def forward(self):
              return self.foo
  
      scripted_m = torch.jit.script(M())
      original_tensor = torch.ones(0)
  
      f = BytesIO()
      with torch.package.PackageExporter(f) as exporter:
          exporter.save_pickle("model", "model.pkl", scripted_m)
          exporter.save_pickle("model", "input.pkl", original_tensor)
  
      f.seek(0)
      # Should be able to load correctly
      importer = PackageImporter(f)
      loaded_m = importer.load_pickle("model", "model.pkl")
      loaded_tensor = importer.load_pickle("model", "input.pkl")
  
      self.assertEqual(scripted_m.foo, loaded_m.foo)
      self.assertEqual(original_tensor, loaded_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 23 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_tensor_sharing_pickle() and returns: self