You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Alternatively, you can use `buck2` to run the `.pte` file with XNNPACK delegate instructions in it on your host platform. You can follow the instructions here to install [buck2](getting-started-setup.md#Build-&-Run). You can now run it with the prebuilt `xnn_executor_runner` provided in the examples. This will run the model on some sample inputs.
175
-
176
-
```bash
177
-
buck2 run examples/xnnpack:xnn_executor_runner -- --model_path ./mv2_xnnpack_fp32.pte
178
-
# or to run the quantized variant
179
-
buck2 run examples/xnnpack:xnn_executor_runner -- --model_path ./mv2_xnnpack_q8.pte
180
-
```
181
-
182
172
## Building and Linking with the XNNPACK Backend
183
-
You can build the XNNPACK backend [BUCK target](https://github.com/pytorch/executorch/blob/main/backends/xnnpack/targets.bzl#L54) and [CMake target](https://github.com/pytorch/executorch/blob/main/backends/xnnpack/CMakeLists.txt#L83), and link it with your application binary such as an Android or iOS application. For more information on this you may take a look at this [resource](demo-apps-android.md) next.
173
+
You can build the XNNPACK backend [CMake target](https://github.com/pytorch/executorch/blob/main/backends/xnnpack/CMakeLists.txt#L83), and link it with your application binary such as an Android or iOS application. For more information on this you may take a look at this [resource](demo-apps-android.md) next.
Once we have the model binary (pte) file, then let's run it with ExecuTorch runtime using the `xnn_executor_runner`.
28
+
Once we have the model binary (pte) file, then let's run it with ExecuTorch runtime using the `xnn_executor_runner`. With cmake, you first configure your cmake with the following:
29
29
30
30
```bash
31
-
buck2 run examples/xnnpack:xnn_executor_runner -- --model_path ./mv2_xnnpack_fp32.pte
@@ -38,11 +66,7 @@ Here we will discuss quantizing a model suitable for XNNPACK delegation using XN
38
66
39
67
Though it is typical to run this quantized mode via XNNPACK delegate, we want to highlight that this is just another quantization flavor, and we can run this quantized model without necessarily using XNNPACK delegate, but only using standard quantization operators.
40
68
41
-
A shared library to register the out variants of the quantized operators (e.g., `quantized_decomposed::add.out`) into EXIR is required. To generate this library, run the following command if using `buck2`:
Or if on cmake, follow the instructions in `test_quantize.sh` to build it, the default path is `cmake-out/kernels/quantized/libquantized_ops_lib.so`.
69
+
A shared library to register the out variants of the quantized operators (e.g., `quantized_decomposed::add.out`) into EXIR is required. On cmake, follow the instructions in `test_quantize.sh` to build it, the default path is `cmake-out/kernels/quantized/libquantized_ops_lib.so`.
46
70
47
71
Then you can generate a XNNPACK quantized model with the following command by passing the path to the shared library into the script `quantization/example.py`:
48
72
```bash
@@ -55,12 +79,37 @@ You can find more valid quantized example models by running:
A quantized model can be run via `executor_runner`:
82
+
## Running the XNNPACK Model with CMake
83
+
After exporting the XNNPACK Delegated model, we can now try running it with example inputs using CMake. We can build and use the xnn_executor_runner, which is a sample wrapper for the ExecuTorch Runtime and XNNPACK Backend. We first begin by configuring the CMake build like such:
59
84
```bash
60
-
buck2 run examples/portable/executor_runner:executor_runner -- --model_path ./mv2_quantized.pte
85
+
# cd to the root of executorch repo
86
+
cd executorch
87
+
88
+
# Get a clean cmake-out directory
89
+
rm- -rf cmake-out
90
+
mkdir cmake-out
91
+
92
+
# Configure cmake
93
+
cmake \
94
+
-DCMAKE_INSTALL_PREFIX=cmake-out \
95
+
-DCMAKE_BUILD_TYPE=Release \
96
+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
97
+
-DEXECUTORCH_BUILD_XNNPACK=ON \
98
+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
99
+
-DEXECUTORCH_ENABLE_LOGGING=ON \
100
+
-DPYTHON_EXECUTABLE=python \
101
+
-Bcmake-out .
61
102
```
62
-
Please note that running a quantized model will require the presence of various quantized/dequantize operators in the [quantized kernel lib](../../kernels/quantized).
Now you should be able to find the executable built at `./cmake-out/backends/xnnpack/xnn_executor_runner` you can run the executable with the model you generated as such
0 commit comments