-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Python binding to export bytecode format for lite interpreter #32621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
💊 CircleCI build failures summary and remediationsAs of commit 18b2b37: None of the build failures appear to be your fault.
Detailed failure analysisOne may explore the probable reasons each build failed interactively on the Dr. CI website. ❄️ 1 failure recognized as flakyThe following build failures have been detected as flaky and may not be your fault:
|
…ter" Export the "_save_for_mobile" method to Python so that the bytecode format for lite interpreter can be added or updated to the original script model. It's the first step of python binding for lite interpreter, as discussed in this [internal post](https://fb.workplace.com/groups/1144215345733672/permalink/1478900738931796/) and offline. Next step is to export the load_for_mobile and run method of mobile module, so that users could verify the mobile model from Python. Test: use the following python script to display the bytecode part of the updated model file. ``` #!/usr/bin/env python3 import sys import pickle import pprint import zipfile class FakeObject(object): def __init__(self, module, name, args): self.module = module self.name = name self.args = args self.state = None def __repr__(self): state_str = "" if self.state is None else f"(state={self.state!r})" return f"{self.module}.{self.name}{self.args!r}{state_str}" def __setstate__(self, state): self.state = state class FakeClass(object): def __init__(self, module, name): self.module = module self.name = name self.__new__ = self.fake_new def __repr__(self): return f"{self.module}.{self.name}" def __call__(self, *args): return FakeObject(self.module, self.name, args) def fake_new(self, *args): return FakeObject(self.module, self.name, args) class DumpUnpickler(pickle._Unpickler): def find_class(self, module, name): return FakeClass(module, name) def persistent_load(self, pid): return FakeObject("pers", "obj", (pid,)) def main(argv): zfile = zipfile.ZipFile(argv[1]) names = [i for i in zfile.namelist() if "bytecode.pkl" in i] if not names: print("bytecode.pkl not found.") return with zfile.open(names[0], "r") as handle: value = DumpUnpickler(handle).load() pprint.pprint(value) if __name__ == "__main__": sys.exit(main(sys.argv)) ```
""" | ||
return self._c.save(*args, **kwargs) | ||
|
||
def save_for_mobile(self, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be part of the public API for ScriptModule? I thought we were not exposing the lite interpreter externally, so this may be confusing for external users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the "_" is needed in C++ only. I might missed it here. Just to confirm: should we rename it to "_save_for_mobile"? I could have a quick patch for it.
…h#32621) Summary: Pull Request resolved: pytorch#32621 Export the "_save_for_mobile" method to Python so that the bytecode format for lite interpreter can be added or updated to the original script model. It's the first step of python binding for lite interpreter, as discussed in this [internal post](https://fb.workplace.com/groups/1144215345733672/permalink/1478900738931796/) and offline. Next step is to export the load_for_mobile and run method of mobile module, so that users could verify the mobile model from Python. Test: use the following python script to display the bytecode part of the updated model file. ``` #!/usr/bin/env python3 import sys import pickle import pprint import zipfile class FakeObject(object): def __init__(self, module, name, args): self.module = module self.name = name self.args = args self.state = None def __repr__(self): state_str = "" if self.state is None else f"(state={self.state!r})" return f"{self.module}.{self.name}{self.args!r}{state_str}" def __setstate__(self, state): self.state = state class FakeClass(object): def __init__(self, module, name): self.module = module self.name = name self.__new__ = self.fake_new def __repr__(self): return f"{self.module}.{self.name}" def __call__(self, *args): return FakeObject(self.module, self.name, args) def fake_new(self, *args): return FakeObject(self.module, self.name, args) class DumpUnpickler(pickle._Unpickler): def find_class(self, module, name): return FakeClass(module, name) def persistent_load(self, pid): return FakeObject("pers", "obj", (pid,)) def main(argv): zfile = zipfile.ZipFile(argv[1]) names = [i for i in zfile.namelist() if "bytecode.pkl" in i] if not names: print("bytecode.pkl not found.") return with zfile.open(names[0], "r") as handle: value = DumpUnpickler(handle).load() pprint.pprint(value) if __name__ == "__main__": sys.exit(main(sys.argv)) ``` Test Plan: Imported from OSS Differential Revision: D19596359 Pulled By: iseeyuan fbshipit-source-id: 19a4a771320f95217f5b0f031c2c04db7b4079a8
It's a patch to #32621, make the api private.
…h#32621) Summary: Pull Request resolved: pytorch#32621 Export the "_save_for_mobile" method to Python so that the bytecode format for lite interpreter can be added or updated to the original script model. It's the first step of python binding for lite interpreter, as discussed in this [internal post](https://fb.workplace.com/groups/1144215345733672/permalink/1478900738931796/) and offline. Next step is to export the load_for_mobile and run method of mobile module, so that users could verify the mobile model from Python. Test: use the following python script to display the bytecode part of the updated model file. ``` #!/usr/bin/env python3 import sys import pickle import pprint import zipfile class FakeObject(object): def __init__(self, module, name, args): self.module = module self.name = name self.args = args self.state = None def __repr__(self): state_str = "" if self.state is None else f"(state={self.state!r})" return f"{self.module}.{self.name}{self.args!r}{state_str}" def __setstate__(self, state): self.state = state class FakeClass(object): def __init__(self, module, name): self.module = module self.name = name self.__new__ = self.fake_new def __repr__(self): return f"{self.module}.{self.name}" def __call__(self, *args): return FakeObject(self.module, self.name, args) def fake_new(self, *args): return FakeObject(self.module, self.name, args) class DumpUnpickler(pickle._Unpickler): def find_class(self, module, name): return FakeClass(module, name) def persistent_load(self, pid): return FakeObject("pers", "obj", (pid,)) def main(argv): zfile = zipfile.ZipFile(argv[1]) names = [i for i in zfile.namelist() if "bytecode.pkl" in i] if not names: print("bytecode.pkl not found.") return with zfile.open(names[0], "r") as handle: value = DumpUnpickler(handle).load() pprint.pprint(value) if __name__ == "__main__": sys.exit(main(sys.argv)) ``` Test Plan: Imported from OSS Differential Revision: D19596359 Pulled By: iseeyuan fbshipit-source-id: 19a4a771320f95217f5b0f031c2c04db7b4079a8
Summary: Pull Request resolved: pytorch#32771 It's a patch to pytorch#32621, make the api private. Test Plan: Imported from OSS Differential Revision: D19657307 Pulled By: iseeyuan fbshipit-source-id: e604a0cbed6a1e61413daaafc65bea92b90f1f5d
Stack from ghstack:
Export the "_save_for_mobile" method to Python so that the bytecode format for lite interpreter can be added or updated to the original script model.
It's the first step of python binding for lite interpreter, as discussed in this internal post and offline.
Next step is to export the load_for_mobile and run method of mobile module, so that users could verify the mobile model from Python.
Test: use the following python script to display the bytecode part of the updated model file.
Differential Revision: D19596359