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
Copy file name to clipboardExpand all lines: content/learning-paths/mobile-graphics-and-gaming/profiling-ml-on-arm/nn-profiling-executorch.md
+25-15Lines changed: 25 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,30 +7,34 @@ layout: learningpathall
7
7
---
8
8
9
9
## 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.
11
11
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.
13
13
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.
15
15
16
16
## Profiling on Android
17
17
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.
19
19
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.
21
21
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.
23
23
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.
25
25
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:
27
29
28
30
```bash
29
31
export ANDROID_NDK=~/Android/Sdk/ndk/28.0.12674087 # replace this with the correct path for your NDK installation
30
32
export ANDROID_ABI=arm64-v8a
31
33
```
32
34
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:
34
38
35
39
```bash
36
40
cmake -DCMAKE_INSTALL_PREFIX=cmake-out \
@@ -49,7 +53,9 @@ Next add Android options to the first `cmake` configuration line in `main()`, th
49
53
50
54
The `cmake` build step for the ExecuTorch library stays the same, as do the next lines setting up local variables.
51
55
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.
@@ -61,9 +67,13 @@ Next we need to adapt the options to Android in the second `cmake` configuration
61
67
"${example_dir}"
62
68
```
63
69
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.
65
75
66
-
Copy `example_runner` and the ExecuTorch bundled program to your Android device. Do this with adb:
76
+
Do this with adb:
67
77
68
78
```bash
69
79
adb push example_runner /data/local/tmp/
@@ -75,9 +85,9 @@ exit
75
85
adb pull /data/local/tmp/etdump.etdp .
76
86
```
77
87
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.
79
89
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:
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