Skip to content
Closed
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
2 changes: 1 addition & 1 deletion bundled_program/serialize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def convert_to_flatbuffer(program_json: str) -> bytes:
with open(json_path, "wb") as json_file:
json_file.write(program_json.encode("ascii"))
_flatc_compile(d, schema_path, json_path)
output_path = os.path.join(d, "{}.bp".format(BUNDLED_PROGRAM_SCHEMA_NAME))
output_path = os.path.join(d, "{}.bpte".format(BUNDLED_PROGRAM_SCHEMA_NAME))
with open(output_path, "rb") as output_file:
return output_file.read()

Expand Down
4 changes: 2 additions & 2 deletions docs/source/sdk-bundled-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ bundled_program = create_bundled_program(program, bundled_config)

# Step 4: Serialize BundledProgram to flatbuffer.
serialized_bundled_program = serialize_from_bundled_program_to_flatbuffer(bundled_program)
save_path = "bundled_program.bp"
save_path = "bundled_program.bpte"
with open(save_path, "wb") as f:
f.write(serialized_bundled_program)

Expand All @@ -182,7 +182,7 @@ We can also regenerate `BundledProgram` from flatbuffer file if needed:

```python
from executorch.bundled_program.serialize import deserialize_from_flatbuffer_to_bundled_program
save_path = "bundled_program.bp"
save_path = "bundled_program.bpte"
with open(save_path, "rb") as f:
serialized_bundled_program = f.read()

Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials_source/sdk-integration-tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
# Use Buck::
#
# python3 -m examples.sdk.scripts.export_bundled_program -m mv2
# buck2 run -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bp
# buck2 run -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bpte
#
# **Option 2:**
#
Expand All @@ -130,7 +130,7 @@
# rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DBUCK2=buck2 -DEXECUTORCH_BUILD_SDK=1 -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=1 ..
# cd ..
# cmake --build cmake-out -j8 -t sdk_example_runner
# ./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bp
# ./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bpte

######################################################################
# Creating an Inspector
Expand Down
16 changes: 8 additions & 8 deletions examples/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ examples/sdk

## BundledProgram

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.
We will use an example model (in `torch.nn.Module`) and its representative inputs, both from [`models/`](../models) directory, to generate a [BundledProgram(`.bpte`)](../../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 `.bpte` model on the ExecuTorch runtime and verify the model on BundledProgram API.


1. Sets up the basic development environment for ExecuTorch by [Setting up ExecuTorch from GitHub](https://pytorch.org/executorch/stable/getting-started-setup).
Expand All @@ -24,16 +24,16 @@ cd executorch # To the top level dir
# To get a list of example models
python3 -m examples.sdk.scripts.export_bundled_program -h

# To generate a specific `.bp` model
# To generate a specific `.bpte` model
python3 -m examples.sdk.scripts.export_bundled_program -m mv2 # for MobileNetv2

# This should generate ./mv2_bundled.bp file, if successful.
# This should generate ./mv2_bundled.bpte file, if successful.
```

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).
3. Once we have the BundledProgram binary (`.bpte`) 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).

```bash
buck2 run examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bp --output_verification
buck2 run examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bpte --output_verification
```


Expand All @@ -42,15 +42,15 @@ buck2 run examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_progra
### Getting Started

After exporting a `BundledProgram`, runtime profiling and debug data can be collected in an ``ETDump``. An ``ETDump`` is a buffer containing data generated by hooks within the ExecuTorch runtime.
We offer an example runner that accepts a `BundledProgram` (`.bp`) and runs a single iteration over the first method defined.
We offer an example runner that accepts a `BundledProgram` (`.bpte`) and runs a single iteration over the first method defined.

Running the program will generate an `ETDump` file (`.etdp`) at the location specified by `--etdump_path`. Make sure to build the program as specified below to enable the event tracer.

**Buck**

```bash
python3 -m examples.sdk.scripts.export_bundled_program -m mv2
buck2 run -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bp --etdump_path mv2_etdump.etdp
buck2 run -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bpte --etdump_path mv2_etdump.etdp
```
**CMake**

Expand All @@ -59,7 +59,7 @@ Running the program will generate an `ETDump` file (`.etdp`) at the location spe
rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DBUCK2=buck2 -DEXECUTORCH_BUILD_SDK=1 -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=1 ..
cd ..
cmake --build cmake-out -j8 -t sdk_example_runner
./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bp --etdump_path mv2_etdump.etdp
./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bpte --etdump_path mv2_etdump.etdp
```

### Parsing ETDump
Expand Down
2 changes: 1 addition & 1 deletion examples/sdk/scripts/export_bundled_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def export_to_bundled_program(
for i in range(len(program.execution_plan))
]

bundled_program_name = f"{model_name}_bundled.bp"
bundled_program_name = f"{model_name}_bundled.bpte"
output_path = os.path.join(output_directory, bundled_program_name)

print(f"Saving exported program to {output_path}")
Expand Down
2 changes: 1 addition & 1 deletion examples/sdk/sdk_example_runner/sdk_example_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static uint8_t bundled_allocator_pool[kBundledAllocatorPoolSize];

DEFINE_string(
bundled_program_path,
"model_bundled.bp",
"model_bundled.bpte",
"Model serialized in flatbuffer format.");

DEFINE_int32(
Expand Down
2 changes: 1 addition & 1 deletion schema/bundled_program_schema.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace bundled_program_flatbuffer;
// Identifier of a valid bundled program schema.
file_identifier "BP06";
// Extension of written files.
file_extension "bp";
file_extension "bpte";

// Reason for basic struct: union value type can only be table/struct/string
table Int {
Expand Down