Skip to content

Commit 8705a04

Browse files
Gasoonjiafacebook-github-bot
authored andcommitted
sdk example tutorial (#846)
Summary: Pull Request resolved: #846 This diff creates README.md for sdk example (mainly focus on bp for now) and add sdk-related info to example/README.md. Reviewed By: tarun292, guangy10 Differential Revision: D50197309 fbshipit-source-id: 5ba5227f33afa373f250e6b9ac61cdb60643ce9b
1 parent 5c00a83 commit 8705a04

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

examples/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ examples
1919
├── qualcomm # Contains demos of Qualcomm QNN backend
2020
├── xtensa # Contains demos of exporting and running a simple model on Xtensa Hifi4 DSP
2121
├── demo-apps # Contains demo apps for Android and iOS
22+
├── sdk # Contains demos of BundledProgram and ETDump
2223
├── third-party # Third-party libraries required for working on the demos
2324
└── README.md # This file
2425
```
@@ -59,6 +60,10 @@ You will find demos of [ExecuTorch QNN Backend](./qualcomm) in the [`qualcomm/`]
5960
The [`xtensa/`](./xtensa) directory hosts a demo that showcases the process of exporting and executing a model on Xtensa Hifi4 DSP. You can utilize [this tutorial](../docs/source/build-run-xtensa.md) to guide you in configuring the demo and running it.
6061

6162

63+
## Demo of ExecuTorch SDK
64+
65+
You will find demos of [ExecuTorch SDK](./sdk/) in the [`sdk/`](./sdk/) directory. The examples focuses on exporting and executing BundledProgram for ExecuTorch model verification, and ETDump generation.
66+
6267
## Dependencies
6368

6469
Various models and workflows listed in this directory have dependencies on some other packages. You need to follow the setup guide in [Setting up ExecuTorch from GitHub](/docs/website/docs/tutorials/00_setting_up_executorch.md) to have appropriate packages installed.

examples/sdk/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SDK Examples
2+
This directory contains examples of BundledProgram and ETDump generation.
3+
4+
## Directory structure
5+
```bash
6+
examples/sdk
7+
├── scripts # Python scripts to illustrate export workflow of bundled program.
8+
├── sdk_executor_runner # Contains an example for both BundledProgram to verify ExecuTorch model, and generate ETDump for runtime results.
9+
└── README.md # Current file
10+
```
11+
12+
## BundledProgram
13+
14+
We will use an example model (in `torch.nn.Module`) and its representative inputs, both from [`models/`](../models) directory, to generate a [BundledProgram(`.bp`)](../../docs/source/sdk-bundled-io.md) file using the [script](scripts/export_bundled_program.py). Then we will use [sdk_example_runner](sdk_example_runner/sdk_example_runner.cpp) to execute the `.bp` model on the ExecuTorch runtime and verify the model on BundledProgram API.
15+
16+
17+
1. Sets up the basic development environment for ExecuTorch by [Setting up ExecuTorch from GitHub](../../docs/source/getting-started-setup.md).
18+
19+
2. Using the [script](scripts/export_bundled_program.py) to generate a BundledProgram binary file by retreiving a `torch.nn.Module` model and its representative inputs from the list of available models in the [`models/`](../models) dir。
20+
21+
```bash
22+
cd executorch # To the top level dir
23+
24+
# To get a list of example models
25+
python3 -m examples.sdk.scripts.export_bundled_program -h
26+
27+
# To generate a specific `.bp` model
28+
python3 -m examples.sdk.scripts.export_bundled_program -m mv2 # for MobileNetv2
29+
30+
# This should generate ./mv2_bundled.bp file, if successful.
31+
```
32+
33+
3. Once we have the BundledProgram binary (`.bp`) file, then let's run and verify it with ExecuTorch runtime and BundledProgram APIs using the [sdk_example_runner](sdk_example_runner/sdk_example_runner.cpp).
34+
35+
```bash
36+
buck2 run examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bp --output_verification
37+
```
38+
39+
40+
## Generate ETDump
41+
42+
Next step is to generate an ``ETDump``. ``ETDump`` contains runtime results
43+
from executing the model. To generate, users have two options:
44+
45+
**Option 1:**
46+
47+
Use Buck::
48+
```bash
49+
python3 -m examples.sdk.scripts.export_bundled_program -m mv2
50+
buck2 run -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bp
51+
```
52+
**Option 2:**
53+
54+
Use CMake::
55+
```bash
56+
cd executorch
57+
rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DBUCK2=buck2 -DEXECUTORCH_BUILD_SDK=1 -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=1 ..
58+
cd ..
59+
cmake --build cmake-out -j8 -t sdk_example_runner
60+
./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bp
61+
```

0 commit comments

Comments
 (0)