|
| 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