Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions docs/source/bundled-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,43 @@ This stage mainly focuses on executing the model with the bundled inputs and com

### Get ExecuTorch Program Pointer from `BundledProgram` Buffer
We need the pointer to ExecuTorch program to do the execution. To unify the process of loading and executing `BundledProgram` and Program flatbuffer, we create an API for this
`executorch::bundled_program::get_program_data`. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp#L128-L137) of this API.
`executorch::bundled_program::get_program_data`. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/1.0/examples/devtools/example_runner/example_runner.cpp#L128-L137) of this API.

### Load Bundled Input to Method
To execute the program on the bundled input, we need to load the bundled input into the method. Here we provided an API called `executorch::bundled_program::load_bundled_input`. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp#L253-L259) of this API.
To execute the program on the bundled input, we need to load the bundled input into the method. Here we provided an API called `executorch::bundled_program::load_bundled_input`. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/1.0/examples/devtools/example_runner/example_runner.cpp#L253-L259) of this API.

### Verify the Method's Output.
We call `executorch::bundled_program::verify_method_outputs` to verify the method's output with bundled expected outputs. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp#L300-L311) of this API.
We call `executorch::bundled_program::verify_method_outputs` to verify the method's output with bundled expected outputs. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/1.0/examples/devtools/example_runner/example_runner.cpp#L301-L307) of this API.

### Runtime Example

Please checkout our [example runner](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/README.md#bundledprogram) for a bundled program. You could run these commands to test with the BundledProgram binary (`.bpte`) file you generated in the previous step:

```bash
cd executorch
./examples/devtools/build_example_runner.sh
./cmake-out/examples/devtools/example_runner --bundled_program_path {your-bpte-file} --output_verification
./examples/devtools/build_example_runner.sh
./cmake-out/examples/devtools/example_runner --bundled_program_path {your-bpte-file} --output_verification
```

It is expected to see no output from running the above mentioned snippet.
For a detailed example of how the runner should be like, please refer to our [example runner](https://github.com/pytorch/executorch/blob/release/1.0/examples/devtools/example_runner/example_runner.cpp).

For a detailed example of how the runner should be like, please refer to our [example runner](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp).

### Try the Complete Workflow

To test the entire end-to-end workflow including building the example runner, exporting a model, and verifying the bundled program execution, you can use the test script:

```bash
cd executorch
./examples/devtools/test_example_runner.sh
```

This script will:
1. Build the example runner using `build_example_runner.sh`
2. Export a MobileNetV2 model as a bundled program
3. Run the example runner with the bundled program to verify correctness

This is a great way to ensure your environment is set up correctly and to see the complete BundledProgram workflow in action.

## Common Errors

Expand Down
10 changes: 9 additions & 1 deletion examples/devtools/build_example_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ main() {

local example_dir=examples/devtools
local build_dir="cmake-out/${example_dir}"
local cmake_prefix_path="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"

# Check for both lib and lib64 directories
local executorch_dir="${PWD}/cmake-out/lib/cmake/ExecuTorch"
if [[ ! -d "${executorch_dir}" ]]; then
executorch_dir="${PWD}/cmake-out/lib64/cmake/ExecuTorch"
fi

local cmake_prefix_path="${executorch_dir};${PWD}/cmake-out/third-party/gflags"

rm -rf ${build_dir}
cmake -DCMAKE_PREFIX_PATH="${cmake_prefix_path}" \
-DCMAKE_BUILD_TYPE=Release \
Expand Down
53 changes: 15 additions & 38 deletions examples/devtools/test_example_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,32 @@
# Test the end-to-end flow of building devtools/example_runner and use it to run
# an actual model.


set -e

# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/../../.ci/scripts/utils.sh"
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR

cmake_install_executorch_devtools_lib() {
echo "Installing libexecutorch.a, libportable_kernels.a, libetdump.a, libbundled_program.a"
clean_executorch_install_folders
readonly EXECUTORCH_ROOT="${SCRIPT_DIR}/../.."

retry cmake -DCMAKE_INSTALL_PREFIX=cmake-out \
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
-Bcmake-out .
cmake --build cmake-out -j9 --target install --config Release
}
if [[ -z $PYTHON_EXECUTABLE ]];
then
PYTHON_EXECUTABLE=python3
fi

test_cmake_devtools_example_runner() {
echo "Exporting MobilenetV2"
${PYTHON_EXECUTABLE} -m examples.devtools.scripts.export_bundled_program --model_name="mv2"
cd "${EXECUTORCH_ROOT}"

echo "Building example_runner using build_example_runner.sh"
"${SCRIPT_DIR}/build_example_runner.sh"

local example_dir=examples/devtools
local build_dir=cmake-out/${example_dir}
CMAKE_PREFIX_PATH="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
rm -rf ${build_dir}
retry cmake \
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
-DCMAKE_BUILD_TYPE=Release \
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
-B${build_dir} \
${example_dir}

echo "Building ${example_dir}"
cmake --build ${build_dir} -j9 --config Release

echo "Exporting MobilenetV2"
${PYTHON_EXECUTABLE} -m examples.devtools.scripts.export_bundled_program --model_name="mv2"

echo 'Running example_runner'
${build_dir}/example_runner --bundled_program_path="./mv2_bundled.bpte"
}

if [[ -z $PYTHON_EXECUTABLE ]];
then
PYTHON_EXECUTABLE=python3
fi

if [[ -z $BUCK ]];
then
BUCK=buck2
fi

cmake_install_executorch_devtools_lib
test_cmake_devtools_example_runner
Loading