pytorch/torch/csrc/jit/python
Tao Xu 495070b388 [Metal] Add the Python binding for optimize_for_mobile (#46456)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/46456

Add the python binding in CMake. The general workflow is

- Build pytorch -  `USE_PYTORCH_METAL=ON python setup.py install --cmake`
- Run optimize_for_mobile

```
import torch
from torch.utils.mobile_optimizer import optimize_for_mobile

scripted_model = torch.jit.load('./mobilenetv2.pt')
optimized_model = optimize_for_mobile(scripted_model, backend='metal')
torch.jit.export_opnames(optimized_model)
torch.jit.save(optimized_model, './mobilenetv2_metal.bc')
```
The exported ops are

```
['aten::adaptive_avg_pool2d', 'aten::add.Tensor', 'aten::addmm', 'aten::reshape', 'aten::size.int', 'metal::copy_to_host', 'metal_prepack::conv2d_run']
```
ghstack-source-id: 114559878

Test Plan:
- Sandcastle CI
- Circle CI

Reviewed By: kimishpatel

Differential Revision: D24356768

fbshipit-source-id: fb5c4c4b6316347b67edb4132da044a81470ddfd
2020-10-17 10:26:25 -07:00
..
init.cpp [Metal] Add the Python binding for optimize_for_mobile (#46456) 2020-10-17 10:26:25 -07:00
init.h
module_python.h
pybind_utils.h Define the record_stream method in native_functions.yaml (#44301) 2020-10-13 09:15:22 -07:00
pybind.h
python_arg_flatten.cpp
python_arg_flatten.h Move torch/csrc/utils/hash.h to c10/util/hash.h. (#42503) 2020-08-29 17:47:00 -07:00
python_custom_class.cpp s/torch::jit::class_/torch::class_/ (#40795) 2020-07-06 15:53:33 -07:00
python_custom_class.h
python_interpreter.cpp Unify boxed function signature between jit and c10 (#37034) 2020-06-29 19:24:26 -07:00
python_ir.cpp Define the record_stream method in native_functions.yaml (#44301) 2020-10-13 09:15:22 -07:00
python_ir.h
python_ivalue.h Explicitly decref py::object in ConcretePyObjectHolder and PythonFunctionGuard (#38364) 2020-05-12 20:55:53 -07:00
python_sugared_value.cpp [JIT] Add API for ignoring arbitrary module attributes (#45262) 2020-10-06 18:02:06 -07:00
python_sugared_value.h Improve sugared value's error message (#42889) 2020-09-18 11:01:40 -07:00
python_tracer.cpp Source code level attribution in profiler (#43898) 2020-09-30 00:57:35 -07:00
python_tracer.h Source code level attribution in profiler (#43898) 2020-09-30 00:57:35 -07:00
python_tree_views.cpp [JIT] Add property support for ScriptModules (#42390) 2020-09-14 18:49:21 -07:00
python_tree_views.h
script_init.cpp [2/3] [JIT] Make sure fusion occurs in test_tensorexpr (#45789) 2020-10-08 12:06:16 -07:00
script_init.h
update_graph_executor_opt.cpp
update_graph_executor_opt.h