Skip to content

Commit 1c57c1d

Browse files
authored
Merge pull request #1534 from madeline-underwood/patch-34
Editorial first-pass of Ben Clark's "Adding ExecuTorch profiling instructions PR1533" LP update PR.
2 parents 125d49b + c2d4cd6 commit 1c57c1d

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

content/learning-paths/mobile-graphics-and-gaming/profiling-ml-on-arm/nn-profiling-executorch.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,34 @@ layout: learningpathall
77
---
88

99
## ExecuTorch Profiling Tools
10-
[ExecuTorch](https://pytorch.org/executorch/stable/index.html) can be used for running PyTorch models on constrained devices like mobile. As so many models are developed in PyTorch, this is a useful way to quickly deploy them to mobile devices, without needing conversion tools like Google's [ai-edge-torch](https://github.com/google-ai-edge/ai-edge-torch) to turn them into tflite.
10+
You can use [ExecuTorch](https://pytorch.org/executorch/stable/index.html) for running PyTorch models on constrained devices like mobile. As so many models are developed in PyTorch, this is a useful way to quickly deploy them to mobile devices, without the requirement for conversion tools such as Google's [ai-edge-torch](https://github.com/google-ai-edge/ai-edge-torch) to convert them into tflite.
1111

12-
To get started on ExecuTorch, you can follow the instructions on the [PyTorch website](https://pytorch.org/executorch/stable/getting-started-setup). Further, to then deploy on Android, the instructions are [here](https://pytorch.org/executorch/stable/demo-apps-android.html). If you haven't already got ExecuTorch running on Android, you should follow these instructions first.
12+
To get started on ExecuTorch, you can follow the instructions on the [PyTorch website](https://pytorch.org/executorch/stable/getting-started-setup). To then deploy on Android, you can also find instructions on the [Pytorch website](https://pytorch.org/executorch/stable/demo-apps-android.html). If you do not already have ExecuTorch running on Android, follow these instructions first.
1313

14-
ExecuTorch comes with a set of profiling tools, but currently they are aimed at Linux, not Android where you will want to deploy. The instructions to profile on Linux are [here](https://pytorch.org/executorch/main/tutorials/devtools-integration-tutorial.html), but we will look at how to adapt them for Android.
14+
ExecuTorch comes with a set of profiling tools, but currently they are aimed at Linux, and not Android. The instructions to profile on Linux are [here](https://pytorch.org/executorch/main/tutorials/devtools-integration-tutorial.html), and you can adapt them for use on Android.
1515

1616
## Profiling on Android
1717

18-
To profile on Android, the steps are the same as [Linux](https://pytorch.org/executorch/main/tutorials/devtools-integration-tutorial.html), except that we need to generate the ETDump file on an Android device.
18+
To profile on Android, the steps are the same as for [Linux](https://pytorch.org/executorch/main/tutorials/devtools-integration-tutorial.html), except that you need to generate the ETDump file on an Android device.
1919

20-
To start with, generate the ETRecord exactly as per the Linux instructions.
20+
To start, generate the ETRecord in exactly the same way as described for the Linux instructions.
2121

22-
Next, follow the instructions to create the ExecuTorch bundled program that you'll need to generate the ETDump. You'll copy this to your Android device together with the runner program you're about to compile.
22+
Next, follow the instructions to create the ExecuTorch bundled program that you will need to generate the ETDump. You will copy this to your Android device together with the runner program that you are about to compile.
2323

24-
To compile the runner program you'll need to adapt the `build_example_runner.sh` script in the instructions (located in the `examples/devtools` subfolder of the ExecuTorch repository) to compile it for Android. Copy the script and rename the copy to `build_android_example_runner.sh`, ready for editing. Remove all lines with `coreml` in them, and the options dependent on it, as these are not needed for Android.
24+
To compile the runner program, you will need to adapt the `build_example_runner.sh` script in the instructions that are located in the `examples/devtools` subfolder of the ExecuTorch repository to compile it for Android. Copy the script and rename the file to `build_android_example_runner.sh`, ready for editing. Remove all lines with `coreml` in them, and the options dependent on it, as these are not needed for Android.
2525

26-
You'll need to set the `ANDROID_NDK` environment variable to point to your Android NDK installation. At the top of the `main()` function add:
26+
You then need to set the `ANDROID_NDK` environment variable to point to your Android NDK installation.
27+
28+
At the top of the `main()` function add:
2729

2830
```bash
2931
export ANDROID_NDK=~/Android/Sdk/ndk/28.0.12674087 # replace this with the correct path for your NDK installation
3032
export ANDROID_ABI=arm64-v8a
3133
```
3234

33-
Next add Android options to the first `cmake` configuration line in `main()`, that configures the building of the ExecuTorch library. Change it to:
35+
Next, add Android options to the first `cmake` configuration line in `main()`, that configures the building of the ExecuTorch library.
36+
37+
Change it to:
3438

3539
```bash
3640
cmake -DCMAKE_INSTALL_PREFIX=cmake-out \
@@ -49,7 +53,9 @@ Next add Android options to the first `cmake` configuration line in `main()`, th
4953

5054
The `cmake` build step for the ExecuTorch library stays the same, as do the next lines setting up local variables.
5155

52-
Next we need to adapt the options to Android in the second `cmake` configuration line, that configures the building of the runner. This now becomes:
56+
Next you will adapt the options to Android in the second `cmake` configuration line, which is the one that configures the building of the runner.
57+
58+
Change it to:
5359

5460
```bash
5561
cmake -DCMAKE_PREFIX_PATH="${cmake_prefix_path}" \
@@ -61,9 +67,13 @@ Next we need to adapt the options to Android in the second `cmake` configuration
6167
"${example_dir}"
6268
```
6369

64-
Once the configuration lines are changed, you can now run the script `./build_android_example_runner.sh` to build the runner program. Once compiled you can find the executable `example_runner` in `cmake-out/examples/devtools/`.
70+
Once you have changed the configuration lines, you can now run the script `./build_android_example_runner.sh` to build the runner program.
71+
72+
Once compiled, find the executable `example_runner` in `cmake-out/examples/devtools/`.
73+
74+
Copy `example_runner` and the ExecuTorch bundled program to your Android device.
6575

66-
Copy `example_runner` and the ExecuTorch bundled program to your Android device. Do this with adb:
76+
Do this with adb:
6777

6878
```bash
6979
adb push example_runner /data/local/tmp/
@@ -75,9 +85,9 @@ exit
7585
adb pull /data/local/tmp/etdump.etdp .
7686
```
7787

78-
You now have the ETDump file ready to analyse with an ExecuTorch Inspector, as per the Linux instructions.
88+
You now have the ETDump file ready to analyze with an ExecuTorch Inspector, in line with the Linux instructions.
7989

80-
To get a full display of the operators and their timings you can just do:
90+
To get a full display of the operators and their timings, use the following:
8191

8292
```python
8393
from executorch.devtools import Inspector
@@ -88,4 +98,4 @@ inspector = Inspector(etdump_path=etdump_path, etrecord=etrecord_path)
8898
inspector.print_data_tabular()
8999
```
90100

91-
However, as the [ExecuTorch profiling page](https://pytorch.org/executorch/main/tutorials/devtools-integration-tutorial.html) explains, there are data analysis options available. These enable you to quickly find the slowest layer, group operators etc. Both the `EventBlock` and `DataFrame` approaches work well. However, at time of writing, the `find_total_for_module()` function has a [bug](https://github.com/pytorch/executorch/issues/7200) and returns incorrect values - hopefully this will soon be fixed.
101+
However, as the [ExecuTorch profiling page](https://pytorch.org/executorch/main/tutorials/devtools-integration-tutorial.html) explains, there are data analysis options available. These enable you to quickly find specified criteria such as the slowest layer or group operators. Both the `EventBlock` and `DataFrame` approaches work well. However, at time of writing, the `find_total_for_module()` function has a [bug](https://github.com/pytorch/executorch/issues/7200) and returns incorrect values - hopefully this will soon be fixed.

0 commit comments

Comments
 (0)