mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-22 06:11:27 +08:00
[jit][edge] Export maybe-used interface methods from modules. (#65966)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/65966 ghstack-source-id: 141594521 Support exportation of "interface methods" from submodule to a mobile module. "Interface methods" are defined as methods which might be dynamically called in a module therefore need to be exported anyway, like virtual functions in C++. Before this change the algorithm of exportation is a simple iteration through all toplevel methods. Now since we have indirect calls, we need to recursively walkthrough the call graph to find all potentially used methods, which means the order we export methods might break in old runtimes, to guarantee forward compatibility we need to export toplevel methods first, then extra methods, in this order toplevel methods will always be found first. NOTE that interface methods exportations are disabled by default in this diff. We need to call torch._C._enable_mobile_interface_call_export to actaully enable it. Test Plan: buck test mode/dev //caffe2/test:jit -- --exact 'caffe2/test:jit - test_export_opnames_interface (jit.test_misc.TestMisc)' Reviewed By: qihqi, iseeyuan Differential Revision: D31326155 fbshipit-source-id: 5be7234cca07691f62648a85133b6db65e427b53
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a72a6365c9
commit
f510193e22
@ -1931,6 +1931,10 @@ void initJitScriptBindings(PyObject* module) {
|
||||
|
||||
m.def("_get_graph_executor_optimize", &torch::jit::getGraphExecutorOptimize);
|
||||
|
||||
m.def(
|
||||
"_enable_mobile_interface_call_export",
|
||||
&torch::jit::enableMobileInterfaceCallExport);
|
||||
|
||||
m.def("_create_module_with_type", [](const ClassTypePtr& type) {
|
||||
return Module(get_python_cu(), type);
|
||||
}).def("_create_object_with_type", [](const ClassTypePtr& type) {
|
||||
|
Reference in New Issue
Block a user