class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test to verify saving multiple ScriptModules with same top module
  but different submodules works. Submodule is redefined to between
  the defintion of the top module to check that the different concrete
  types of the modules are thoroughly recognized by serializaiton code.
docstr_tok: ["Test","to","verify","saving","multiple","ScriptModules","with","same","top","module","but","different","submodules","works",".","Submodule","is","redefined","to","between","the","defintion","of","the","top","module","to","check","that","the","different","concrete","types","of","the","modules","are","thoroughly","recognized","by","serializaiton","code","."]
code: def test_save_scriptmodules_submod_redefinition(self):
      """
      Test to verify saving multiple ScriptModules with same top module
      but different submodules works. Submodule is redefined to between
      the defintion of the top module to check that the different concrete
      types of the modules are thoroughly recognized by serializaiton code.
      """
  
      class Submod(torch.nn.Module):
          def forward(self, input: str):
              input = input + "_submod"
              return input
  
      class TopMod(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.modB = Submod()
  
          def forward(self, input: str):
              return self.modB(input)
  
      scripted_mod_0 = torch.jit.script(TopMod())
  
      # redefinition is intentional, change single inner string
      # string attribute, should trigger new module type
      class Submod(torch.nn.Module):  # noqa: F811
          def forward(self, input: str):
              input = input + "_submod(changed)"
              return input
  
      scripted_mod_1 = torch.jit.script(TopMod())
  
      buffer = BytesIO()
      with PackageExporter(buffer) as e:
          e.save_pickle("res", "mod1.pkl", scripted_mod_0)
          e.save_pickle("res", "mod2.pkl", scripted_mod_1)
  
      buffer.seek(0)
      importer = PackageImporter(buffer)
      loaded_mod_0 = importer.load_pickle("res", "mod1.pkl")
      loaded_mod_1 = importer.load_pickle("res", "mod2.pkl")
      self.assertEqual(loaded_mod_0("input"), scripted_mod_0("input"))
      self.assertEqual(loaded_mod_1("input"), scripted_mod_1("input"))
      self.assertNotEqual(loaded_mod_0("input"), loaded_mod_1("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 9 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_save_scriptmodules_submod_redefinition() and returns: input, self, input