[torch.Package/TorchScript] torch.Package python logic to save TorchScript (#54893)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54893
Adds logic to torch.Package's `PackageExporter` and `PackageImporter` to handle TorchScript objects. Also adds necessary `__reduce_package__` methods to `ScriptModule` and `RecursiveScriptModule` to enable this
API:
```
# create scripted objects
scripted_mod = torch.jit.script(Mod1("initial_1"))
scripted_mod2 = torch.jit.script(Mod2("initial_2"))
# save objects into package
with PackageExporter(filename, verbose=False) as e:
e.save_pickle("res", "mod.pkl", scripted_mod)
e.save_pickle("res", "mod2.pkl", scripted_mod2)
# load scripted objects from package
importer = PackageImporter(filename)
scripted_mod_loaded = importer.load_pickle("res", "mod.pkl")
scripted_mod2_loaded = importer.load_pickle("res", "mod2.pkl")
```
Test Plan: Imported from OSS
Reviewed By: suo
Differential Revision: D27832547
Pulled By: Lilyjjo
fbshipit-source-id: 73bf254c311fee2a2b21a9a7861d6cdc53709bd1