class_docstr: Tests for compatibility with FX.
class_docstr_tok: ["Tests","for","compatibility","with","FX","."]
code: def test_package_fx_package(self):
      from package_a.test_module import SimpleTest
  
      model = SimpleTest()
      f = BytesIO()
      with PackageExporter(f) as pe:
          pe.intern("**")
          pe.save_pickle("model", "model.pkl", model)
  
      f.seek(0)
      pi = PackageImporter(f)
      loaded = pi.load_pickle("model", "model.pkl")
      traced = symbolic_trace(loaded)
  
      # re-save the package exporter
      f2 = BytesIO()
      # This should fail, because we are referencing some globals that are
      # only in the package.
      with self.assertRaises(ObjMismatchError):
          with PackageExporter(f2) as pe:
              pe.intern("**")
              pe.save_pickle("model", "model.pkl", traced)
  
      f2.seek(0)
      with PackageExporter(f2, importer=(pi, sys_importer)) as pe:
          # Make the package available to the exporter's environment.
          pe.intern("**")
          pe.save_pickle("model", "model.pkl", traced)
      f2.seek(0)
      pi2 = PackageImporter(f2)
      loaded2 = pi2.load_pickle("model", "model.pkl")
  
      input = torch.rand(2, 3)
      self.assertEqual(loaded(input), loaded2(input))
  
file_path: pytorch/test/package/test_package_fx.py
imports: from io import BytesIO
  import torch
  from torch.fx import Graph, GraphModule, symbolic_trace
  from torch.package import ObjMismatchError, PackageExporter, PackageImporter, sys_importer
  from torch.testing._internal.common_utils import run_tests
label_desc: Use image node_id 3 for calling the TestPackageFX obj's underlying member method code with example usage: obj.test_package_fx_package() without return types