pytorch
51d18369 - [1/N] Nnapi backend delegation preprocess (#61499)

Commit
3 years ago
[1/N] Nnapi backend delegation preprocess (#61499) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/61499 Added a preprocess function for the delegate to Nnapi backend (internal and external files). In the past we had functions and classes for converting to the Nnapi backend. Now, these functions and classes will be wrapped by the delegate API. ### nnapi_backend_preprocess.cpp: Contains the preprocess function, which uses Pybind to call an existing python function, `convert_model_to_nnapi()`. - The model is wrapped by a `RecursiveScriptModule`, so that `convert_model_to_nnapi()` can run correctly, since when jumping from Python to C++ to Python, the model loses its original wrapper. - A tensor, which includes shape, data type, and quantization information, is passed through preprocess's compile_spec to `convert_model_to_nnapi()`. - Finally, the Nnapi model is serialized for mobile and returned as a string. ### nnapi_backend_lib.cpp: Contains stub functions for compile and execute, and is necessary for the Nnapi backend to be registered correctly. These will be implemented in a future PR. **TODO:** implement execute and compile for the delegate API; throw exceptions for incorrect an compile_spec; add OSS tests **Testing:** Tests were done locally (see D29647123). A simple module was lowered to Nnapi, saved locally, and examined. ghstack-source-id: 133415234 Test Plan: Tests were done locally (see D29647123). TODO: add test in OSS in test_backends.py after CMake is ready. I ran buck run caffe2:nnapi_backend_example. The model files are saved as nnapi_model.ptl and mobile_model.ptl. I checked that both zip files have expected contents. Reviewed By: iseeyuan Differential Revision: D29563351 fbshipit-source-id: 642e349356e38aecc1b9973c285569650c02668c
Author
Parents
Loading