Skip to content

Commit 889d990

Browse files
guangy10facebook-github-bot
authored andcommitted
Restructuring demos - runtime (#531)
Summary: ## Proposed code structure (dir only): ``` executorch/examples/ ├── README.md # top-level description for demos and folder structures ├── models │ ├── deeplab_v3 │ | ... │ └── wav2letter ├── quantization │ ├── toy_quantizer │ └── xnnpack ├── backend │ ├── toy_backend │ └── xnnpack ├── export │ ├── portable │ └── xnnpack ├── recipes # AOT + runtime to create a demo experience. Where description (README.md) for each demo should go │ ├── arm_tosa_delegate │ ├── portable_mode │ ├── toy_quantize_and_delegate # for vendor │ └── xnnpack ├── runtime │ ├── bundled │ │ ├── bundled_executor_runner │ ├── portable │ │ ├── executor_runner │ └── xnnpack │ └── xnn_executor_runner ├── third-party ├── ios_demo_apps ├── android_demo_apps ├── custom_ops # non-e2e demo └── selective_build # non-e2e demo ``` Reference to old code structure: https://github.com/pytorch/executorch/tree/main/examples ## This Diff Focus on restructing runtime examples: ``` executorch/examples/runtime/ ├── bundled │ ├── BUCK │ ├── bundled_executor_runner.cpp │ ├── TARGETS │ └── targets.bzl ├── portable │ ├── BUCK │ ├── executor_runner.cpp │ ├── TARGETS │ └── targets.bzl └── xnnpack ├── TARGETS └── targets.bzl ``` NOTE: Please ignore CI failures, build files and test files, and only focus to discuss if the proposed code structure will provide better user experience. Differential Revision: D49714823
1 parent 1de10f4 commit 889d990

File tree

19 files changed

+64
-48
lines changed

19 files changed

+64
-48
lines changed

.ci/scripts/test.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test_model() {
5757

5858
# Run test model
5959
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
60-
buck2 run //examples/executor_runner:executor_runner -- --model_path "./${MODEL_NAME}.pte"
60+
buck2 run //examples/runtime/executor_runner:executor_runner -- --model_path "./${MODEL_NAME}.pte"
6161
elif [[ "${BUILD_TOOL}" == "cmake" ]]; then
6262
if [[ ! -f ${CMAKE_OUTPUT_DIR}/executor_runner ]]; then
6363
build_cmake_executor_runner
@@ -109,7 +109,7 @@ test_model_with_xnnpack() {
109109

110110
# Run test model
111111
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
112-
buck2 run //examples/backend:xnn_executor_runner -- --model_path "${OUTPUT_MODEL_PATH}"
112+
buck2 run //examples/runtime/xnnpack:xnn_executor_runner -- --model_path "${OUTPUT_MODEL_PATH}"
113113
elif [[ "${BUILD_TOOL}" == "cmake" ]]; then
114114
if [[ ! -f ${CMAKE_OUTPUT_DIR}/backends/xnnpack/xnn_executor_runner ]]; then
115115
build_cmake_xnn_executor_runner
@@ -129,9 +129,9 @@ test_demo_backend_delegation() {
129129

130130
# Run test model
131131
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
132-
buck2 run //examples/executor_runner:executor_runner -- --model_path "./composite_model.pte"
133-
buck2 run //examples/executor_runner:executor_runner -- --model_path "./partition_lowered_model.pte"
134-
buck2 run //examples/executor_runner:executor_runner -- --model_path "./whole.pte"
132+
buck2 run //examples/runtime/executor_runner:executor_runner -- --model_path "./composite_model.pte"
133+
buck2 run //examples/runtime/executor_runner:executor_runner -- --model_path "./partition_lowered_model.pte"
134+
buck2 run //examples/runtime/executor_runner:executor_runner -- --model_path "./whole.pte"
135135
elif [[ "${BUILD_TOOL}" == "cmake" ]]; then
136136
if [[ ! -f ${CMAKE_OUTPUT_DIR}/executor_runner ]]; then
137137
build_cmake_executor_runner

.ci/scripts/utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ install_flatc_from_source() {
7070

7171
build_executorch_runner_buck2() {
7272
# Build executorch runtime with retry as this step is flaky on macos CI
73-
retry buck2 build //examples/executor_runner:executor_runner
73+
retry buck2 build //examples/runtime/executor_runner:executor_runner
7474
}
7575

7676
build_executorch_runner_cmake() {

build/cmake_deps.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ excludes = [
1313

1414
[targets.executor_runner]
1515
buck_targets = [
16-
"//examples/executor_runner:executor_runner",
16+
"//examples/runtime/portable:executor_runner",
1717
]
1818
filters = [
1919
".cpp$",
@@ -93,7 +93,7 @@ deps = [
9393

9494
[targets.xnn_executor_runner]
9595
buck_targets = [
96-
"//examples/backend:xnn_executor_runner",
96+
"//examples/runtime/xnnpack:xnn_executor_runner",
9797
]
9898
filters = [
9999
".cpp$",

docs/source/getting-started-setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Complete the following steps:
193193

194194
3. Build a binary:
195195
```bash
196-
/tmp/buck2 build //examples/executor_runner:executor_runner --show-output
196+
/tmp/buck2 build //examples/runtime/executor_runner:executor_runner --show-output
197197
```
198198

199199
:::{dropdown} Output
@@ -227,7 +227,7 @@ the `buck run` command to run our program.
227227
* To run the `add.pte` program:
228228

229229
```bash
230-
/tmp/buck2 run //examples/executor_runner:executor_runner -- --model_path add.pte
230+
/tmp/buck2 run //examples/runtime/executor_runner:executor_runner -- --model_path add.pte
231231
```
232232

233233
:::{dropdown} Sample Output

docs/website/docs/tutorials/00_setting_up_executorch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ You may want to copy the `buck2` binary into your `$PATH` so you can run it as `
9898
`executor_runner` is an example wrapper around executorch runtime which includes all the operators and backends
9999

100100
```bash
101-
/tmp/buck2 build //examples/executor_runner:executor_runner --show-output
101+
/tmp/buck2 build //examples/runtime/executor_runner:executor_runner --show-output
102102
```
103103

104104
The `--show-output` flag will print the path to the executable if you want to run it directly.
@@ -112,10 +112,10 @@ conda install -c conda-forge lld
112112

113113
```bash
114114
# add.pte is the program generated from export_example.py during AOT Setup Step 3
115-
/tmp/buck2 run //examples/executor_runner:executor_runner -- --model_path add.pte
115+
/tmp/buck2 run //examples/runtime/executor_runner:executor_runner -- --model_path add.pte
116116

117117
# To run a delegated model
118-
/tmp/buck2 run //examples/executor_runner:executor_runner -- --model_path composite_model.pte
118+
/tmp/buck2 run //examples/runtime/executor_runner:executor_runner -- --model_path composite_model.pte
119119
```
120120

121121
or execute the binary directly from the `--show-output` path shown when building.

examples/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
# Examples
22

3-
This dir contains scripts and other helper utilities to illustrate an end-to-end workflow to run a torch.nn.module on the ExecuTorch runtime.
3+
This dir contains scripts and other helper utilities to illustrate an end-to-end workflow to run a torch.nn.module on the Executorch runtime.
44
It also includes a list of modules, from a simple `Add` to a full model like `MobileNetv2` and `MobileNetv3`, with more to come.
55

66

77
## Directory structure
88
```bash
99
examples
1010
|── backend # Contains examples for exporting delegate models and running them using custom executor runners
11-
├── custom_ops # Contains examples to register custom operators into PyTorch as well as register its kernels into ExecuTorch runtime
11+
├── custom_ops # Contains examples to register custom operators into PyTorch as well as register its kernels into Executorch runtime
1212
├── example_quantizer_and_delegate # Contains examples to to fully lowered a MobileNetV2 model to the example backend with an example quantizer
13-
├── executor_runner # This is an example C++ wrapper around the ET runtime
1413
├── export # Python helper scripts to illustrate export workflow
1514
├── ios_demo_apps # Contains iOS demo apps
16-
├── models # Contains a set of simple to PyTorch models
15+
├── models # Contains a set of out-of-box PyTorch models
1716
├── quantization # Contains examples of quantization workflow
18-
├── arm # Contains examples of the Arm TOSA and Ethos-U NPU flows
17+
├── recipes # Contains recipes for a set of demos
18+
├── runtime # Contains examples of C++ wrapper around the ET runtime
1919
└── README.md # This file
2020
```
2121

2222
## Using the examples
2323

2424
We will walk through an example model to generate a binary file from a python torch.nn.module
2525
from the `models` dir using scripts from the `export` dir. Then we will run on these binary
26-
model files on the ExecuTorch (ET) runtime. For that we will use `executor_runner`. It is a simple
27-
wrapper for the ExecuTorch runtime to serve as an example. Although simple, it is capable of loading
26+
model files on the Executorch (ET) runtime. For that we will use `executor_runner`. It is a simple
27+
wrapper for the Executorch runtime to serve as an example. Although simple, it is capable of loading
2828
and executing previously exported binary file(s).
2929

3030

3131
1. Following the setup guide in [Setting up ExecuTorch from GitHub](/docs/website/docs/tutorials/00_setting_up_executorch.md)
32-
you should be able to get the basic development environment for ExecuTorch working.
32+
you should be able to get the basic development environment for Executorch working.
3333

3434
2. Using the script `export/export_example.py` generate a model binary file by selecting a
3535
model name from the list of available models in the `models` dir.
@@ -49,10 +49,10 @@ python3 -m examples.export.export_example --model_name="mv2" # for MobileNetv2
4949

5050
Use `-h` (or `--help`) to see all the supported models.
5151

52-
3. Once we have the model binary (pte) file, then let's run it with ExecuTorch runtime using the `executor_runner`.
52+
3. Once we have the model binary (pte) file, then let's run it with Executorch runtime using the `executor_runner`.
5353

5454
```bash
55-
buck2 run examples/executor_runner:executor_runner -- --model_path mv2.pte
55+
buck2 run examples/runtime/executor_runner:executor_runner -- --model_path mv2.pte
5656
```
5757

5858
## Quantization
@@ -87,7 +87,7 @@ buck2 run executorch/examples/quantization:example -- --help
8787
Quantized model can be run via executor_runner, similar to floating point model, via, as shown above:
8888

8989
```bash
90-
buck2 run examples/executor_runner:executor_runner -- --model_path mv2.pte
90+
buck2 run examples/runtime/executor_runner:executor_runner -- --model_path mv2.pte
9191
```
9292

9393
Note that, running quantized model, requires various quantized/dequantize operators, available in [quantized kernel lib](/kernels/quantized).

examples/backend/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ The following command will produce an floating-point XNNPACK delegated model `mv
1313
python3 -m examples.backend.xnnpack_examples --model_name="mv2" --delegate
1414
```
1515

16-
Once we have the model binary (pte) file, then let's run it with ExecuTorch runtime using the `xnn_executor_runner`.
16+
Once we have the model binary (pte) file, then let's run it with Executorch runtime using the `xnn_executor_runner`.
1717

1818
```bash
19-
buck2 run examples/backend:xnn_executor_runner -- --model_path ./mv2_xnnpack_fp32.pte
19+
buck2 run examples/runtime/xnnpack:xnn_executor_runner -- --model_path ./mv2_xnnpack_fp32.pte
2020
```
2121

2222
## XNNPACK quantization + delegation
@@ -26,10 +26,10 @@ The following command will produce an XNNPACK quantized and delegated model `mv2
2626
python3 -m examples.backend.xnnpack_examples --model_name="mv2" --quantize --delegate
2727
```
2828

29-
Once we have the model binary (pte) file, then let's run it with ExecuTorch runtime using the `xnn_executor_runner`.
29+
Once we have the model binary (pte) file, then let's run it with Executorch runtime using the `xnn_executor_runner`.
3030

3131
```bash
32-
buck2 run examples/backend:xnn_executor_runner -- --model_path ./mv2_xnnpack_q8.pte
32+
buck2 run examples/runtime/xnnpack:xnn_executor_runner -- --model_path ./mv2_xnnpack_q8.pte
3333
```
3434

3535
## XNNPACK performance gain
@@ -40,14 +40,14 @@ We tested the performance for MobileNet V2 and MobileNet V3 on Linux x86 and Mac
4040

4141
For each model, we export three variations: portable (without any optimization), xnnpack fp32 (exported for XNNPACK delegation without quantization), xnnpack q8 (exported for XNNPACK delegation with qint8 delegation).
4242

43-
We build the benchmarking binary (will be released in the near future, but it is similar to `examples/backend:xnn_executor_runner`). Benchmarking binary, by default, runs 10 iterations of warmup and 50 iterations of benchmarking. Number reported here are average measured latency, in ms, across 50 runs. The first iteration is slower due to warm up, and the performance is is stable on subsequent iterations, so we also report the execution time for the first iteration for reference. Below is the model execution time for first iteration and subsequent iterations (average after warmup), in milliseconds. We use a single thread to test the models. Details about the methodology and repro steps are below the tables.
43+
We build the benchmarking binary (will be released in the near future, but it is similar to `examples/runtime/xnnpack:xnn_executor_runner`). Benchmarking binary, by default, runs 10 iterations of warmup and 50 iterations of benchmarking. Number reported here are average measured latency, in ms, across 50 runs. The first iteration is slower due to warm up, and the performance is is stable on subsequent iterations, so we also report the execution time for the first iteration for reference. Below is the model execution time for first iteration and subsequent iterations (average after warmup), in milliseconds. We use a single thread to test the models. Details about the methodology and repro steps are below the tables.
4444

4545
### Methodology
4646

47-
Models are exported with the steps above for XNNPACK delegation, and with `examples/export:export_example` for portable backend without any optimization. Then use `//examples/backend:xnn_executor_runner` with profiler (command listed below); or in the future, use the runtime in `//sdk/runners:executor_runner` since it gives more options such as number of iterations after build rules for OSS is added.
47+
Models are exported with the steps above for XNNPACK delegation, and with `examples/export:export_example` for portable backend without any optimization. Then use `//examples/runtime/xnnpack:xnn_executor_runner` with profiler (command listed below); or in the future, use the runtime in `//sdk/runners:executor_runner` since it gives more options such as number of iterations after build rules for OSS is added.
4848

4949
```
50-
buck run -c executorch.prof_enabled=true -c executorch.prof_buf_size=8096 -c executorch.num_prof_blocks=61 //examples/backend:xnn_executor_runner -- --model_path mv3.pte
50+
buck run -c executorch.prof_enabled=true -c executorch.prof_buf_size=8096 -c executorch.num_prof_blocks=61 //examples/runtime/xnnpack:xnn_executor_runner -- --model_path mv3.pte
5151
```
5252

5353
A rough number of execution time can be obtained via the log timestamp. The profiler result can be analyzed with `profiler:profiler_results_cli`.

examples/backend/targets.bzl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,3 @@ def define_common_targets():
2929
"//executorch/exir/backend:backend_api",
3030
],
3131
)
32-
33-
# executor_runner for XNNPACK Backend and portable kernels.
34-
runtime.cxx_binary(
35-
name = "xnn_executor_runner",
36-
srcs = [],
37-
deps = [
38-
"//executorch/examples/executor_runner:executor_runner_lib",
39-
"//executorch/backends/xnnpack:xnnpack_backend",
40-
"//executorch/kernels/portable:generated_lib_all_ops",
41-
],
42-
define_static_target = True,
43-
**get_oss_build_kwargs()
44-
)

examples/custom_ops/test_custom_ops.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test_buck2_custom_op_1() {
2121
# should save file custom_ops_1.pte
2222

2323
echo 'Running executor_runner'
24-
buck2 run //examples/executor_runner:executor_runner \
24+
buck2 run //examples/runtime/executor_runner:executor_runner \
2525
--config=executorch.register_custom_op=1 -- --model_path="./${model_name}.pte"
2626
# should give correct result
2727

@@ -58,7 +58,7 @@ test_buck2_custom_op_2() {
5858
${PYTHON_EXECUTABLE} -m "examples.custom_ops.${model_name}" --so_library="$SO_LIB"
5959
# should save file custom_ops_2.pte
6060

61-
buck2 run //examples/executor_runner:executor_runner \
61+
buck2 run //examples/runtime/executor_runner:executor_runner \
6262
--config=executorch.register_custom_op=2 -- --model_path="./${model_name}.pte"
6363
# should give correct result
6464
echo "Removing ${model_name}.pte"

examples/quantization/test_quantize.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test_buck2_quantization() {
3535
${PYTHON_EXECUTABLE} -m "examples.quantization.example" --so_library="$SO_LIB" --model_name="$1"
3636

3737
echo 'Running executor_runner'
38-
$BUCK run //examples/executor_runner:executor_runner -- --model_path="./${1}_quantized.pte"
38+
$BUCK run //examples/runtime/executor_runner:executor_runner -- --model_path="./${1}_quantized.pte"
3939
# should give correct result
4040

4141
echo "Removing ${1}_quantized.pte"
File renamed without changes.

examples/runtime/xnnpack/TARGETS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Any targets that should be shared between fbcode and xplat must be defined in
2+
# targets.bzl. This file can contain fbcode-only targets.
3+
4+
load(":targets.bzl", "define_common_targets")
5+
6+
oncall("executorch")
7+
8+
define_common_targets()

examples/runtime/xnnpack/targets.bzl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_oss_build_kwargs", "runtime")
2+
3+
def define_common_targets():
4+
"""Defines targets that should be shared between fbcode and xplat.
5+
6+
The directory containing this targets.bzl file should also contain both
7+
TARGETS and BUCK files that call this function.
8+
"""
9+
10+
# executor_runner for XNNPACK Backend and portable kernels.
11+
runtime.cxx_binary(
12+
name = "xnn_executor_runner",
13+
srcs = [],
14+
deps = [
15+
"//executorch/examples/runtime/portable:executor_runner_lib",
16+
"//executorch/backends/xnnpack:xnnpack_backend",
17+
"//executorch/kernels/portable:generated_lib_all_ops",
18+
],
19+
define_static_target = True,
20+
**get_oss_build_kwargs()
21+
)

examples/selective_build/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def define_common_targets():
7373
name = "selective_build_test",
7474
srcs = [],
7575
deps = [
76-
"//executorch/examples/executor_runner:executor_runner_lib",
76+
"//executorch/examples/runtime/executor_runner:executor_runner_lib",
7777
] + lib,
7878
define_static_target = True,
7979
**get_oss_build_kwargs()

0 commit comments

Comments
 (0)