|
1 | | -# Arm(R) Backend Tutorial |
| 1 | +# Arm® Backend Tutorial |
2 | 2 |
|
3 | 3 | <!----This will show a grid card on the page-----> |
4 | 4 | ::::{grid} 2 |
@@ -26,10 +26,10 @@ You may encounter some rough edges and features which may be documented or plann |
26 | 26 |
|
27 | 27 | ```{tip} |
28 | 28 | If you are already familiar with this delegate, you may want to jump directly to the examples: |
29 | | -* [https://github.com/pytorch/executorch/tree/main/examples/arm](https://github.com/pytorch/executorch/tree/main/examples/arm) |
30 | | -* [https://github.com/pytorch/executorch/blob/main/examples/arm/ethos_u_minimal_example.ipynb](Compilation for Ethos-U) |
31 | | -* [https://github.com/pytorch/executorch/blob/main/examples/arm/vgf_minimal_example.ipynb](Compilation for VGF/ML-SDK) |
32 | | -* [https://github.com/pytorch/executorch/blob/main/examples/arm/aot_arm_compiler.py](A commandline compiler for example models) |
| 29 | +* [Examples in the ExecuTorch repository](https://github.com/pytorch/executorch/tree/main/examples/arm) |
| 30 | +* [Compilation for Ethos-U](https://github.com/pytorch/executorch/blob/main/examples/arm/ethos_u_minimal_example.ipynb) |
| 31 | +* [Compilation for VGF/ML-SDK](https://github.com/pytorch/executorch/blob/main/examples/arm/vgf_minimal_example.ipynb) |
| 32 | +* [A commandline compiler for example models](https://github.com/pytorch/executorch/blob/main/examples/arm/aot_arm_compiler.py) |
33 | 33 | ``` |
34 | 34 |
|
35 | 35 | ## Prerequisites |
@@ -69,7 +69,6 @@ For VGF run: |
69 | 69 | ``` |
70 | 70 | It is possible to install both sets of dependencies if you omit the disable options. |
71 | 71 |
|
72 | | -Upon successful execution, you can directly go to [the next step](#convert-the-pytorch-model-to-the-pte-file). |
73 | 72 |
|
74 | 73 | ### Notes: |
75 | 74 |
|
@@ -203,27 +202,50 @@ graph_module_edge.exported_program = to_backend( |
203 | 202 |
|
204 | 203 | Similar to the non-delegate flow, the same script will server as a helper utility to help generate the `.pte` file. Notice the `--delegate` option to enable the `to_backend` call. |
205 | 204 |
|
| 205 | +For Ethos targets: |
206 | 206 | ```bash |
207 | 207 | python3 -m examples.arm.aot_arm_compiler --model_name="add" --delegate |
| 208 | +# This targets the default of ethos-u55-128, see --help for further targets |
208 | 209 | # should produce ./add_arm_delegate_ethos-u55-128.pte |
209 | 210 | ``` |
210 | 211 |
|
211 | | -### Delegated Quantized Workflow |
212 | | -Generating the `.pte` file can be done using the aot_arm_compiler: |
| 212 | +For basic post-training quantization: |
213 | 213 | ```bash |
214 | 214 | python3 -m examples.arm.aot_arm_compiler --model_name="mv2" --delegate --quantize |
| 215 | +# This targets the default of ethos-u55-128, see --help for further targets |
215 | 216 | # should produce ./mv2_arm_delegate_ethos-u55-128.pte |
216 | 217 | ``` |
217 | 218 |
|
| 219 | + |
| 220 | +For VGF targets: |
| 221 | +```bash |
| 222 | +python3 -m examples.arm.aot_arm_compiler --model_name="add" --target=vgf --delegate |
| 223 | +# should produce ./add_arm_delegate_vgf.pte |
| 224 | +``` |
| 225 | + |
| 226 | +For basic post-training quantization: |
| 227 | +```bash |
| 228 | +python3 -m examples.arm.aot_arm_compiler --model_name="mv2" --target=vgf --delegate --quantize |
| 229 | +# should produce ./mv2_arm_delegate_vgf.pte |
| 230 | +``` |
| 231 | + |
| 232 | +To capture intermediates such as VGF for lower level integration, invoke with the "-i" option: |
| 233 | +```bash |
| 234 | +python3 -m examples.arm.aot_arm_compiler --model_name="mv2" --target=vgf --delegate --quantize -i ./mv2_output |
| 235 | +# should produce ./mv2_arm_delegate_vgf.pte and intermediates in ./mv2_out/ |
| 236 | +``` |
| 237 | + |
218 | 238 | <br /> |
219 | 239 |
|
220 | | -At the end of this, you should have three different `.pte` files. |
| 240 | +At the end of this, you should have a number of different `.pte` files. |
221 | 241 |
|
222 | | -- The first one contains the [SoftmaxModule](#softmaxmodule), without any backend delegates. |
223 | | -- The second one contains the [AddModule](#addmodule), with Arm Ethos-U backend delegate enabled. |
224 | | -- The third one contains the [quantized MV2Model](#mv2module), with the Arm Ethos-U backend delegate enabled as well. |
| 242 | +- the SoftmaxModule, without any backend delegates. |
| 243 | +- the AddModule, targeting the Arm Ethos-U backend. |
| 244 | +- the Quantized MV2Model, targeting the Arm Ethos-U backend. |
| 245 | +- the AddModule, targeting the VGF backend. |
| 246 | +- the Quantized MV2Model, targeting the VGF backend. |
225 | 247 |
|
226 | | -Now let's try to run these `.pte` files on a Corstone-300 and Corstone-320 platforms in a bare-metal environment. |
| 248 | +Now let's try to run these `.pte` files on a target. |
227 | 249 |
|
228 | 250 | ## Getting a Bare-Metal Executable |
229 | 251 |
|
@@ -391,6 +413,40 @@ I [executorch:arm_executor_runner.cpp:179] |
391 | 413 | The `run.sh` script provides various options to select a particular FVP target, use desired models, select portable kernels and can be explored using the `--help` argument |
392 | 414 | ``` |
393 | 415 |
|
| 416 | +## Running on the VGF backend with the standard executor_runner for Linux |
| 417 | +
|
| 418 | +Follow typical [Building ExecuTorch with CMake](using-executorch-building-from-source.md) flow to build the linux target, ensuring that the VGF delegate is enabled. |
| 419 | +
|
| 420 | +```bash |
| 421 | +-DEXECUTORCH_BUILD_VGF=ON |
| 422 | +``` |
| 423 | +
|
| 424 | +A full example buld line is: |
| 425 | +``` |
| 426 | +cmake bash \ |
| 427 | + -DCMAKE_INSTALL_PREFIX=cmake-out \ |
| 428 | + -DCMAKE_BUILD_TYPE=Release \ |
| 429 | + -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ |
| 430 | + -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ |
| 431 | + -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ |
| 432 | + -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ |
| 433 | + -DEXECUTORCH_BUILD_XNNPACK=OFF \ |
| 434 | + -DEXECUTORCH_BUILD_VULKAN=ON \ |
| 435 | + -DEXECUTORCH_BUILD_VGF=ON \ |
| 436 | + -DEXECUTORCH_ENABLE_LOGGING=ON \ |
| 437 | + -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ |
| 438 | + -DPYTHON_EXECUTABLE=python \ |
| 439 | + -Bcmake-out . |
| 440 | +cmake --build cmake-out -j25 --target install --config Release |
| 441 | +``` |
| 442 | +
|
| 443 | +You can then invoke the executor runner on the host machine, which will use the VGF delegate, and requires the vulkan layer drivers we installed with setup.sh. |
| 444 | +
|
| 445 | +```bash |
| 446 | +./cmake-out/executor_runner -model_path add_arm_delegate_vgf.pte |
| 447 | +``` |
| 448 | +
|
| 449 | +
|
394 | 450 | ## Takeaways |
395 | 451 | In this tutorial you have learnt how to use the ExecuTorch software to both export a standard model from PyTorch and to run it on the compact and fully functioned ExecuTorch runtime, enabling a smooth path for offloading models from PyTorch to Arm based platforms. |
396 | 452 |
|
|
0 commit comments