[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