Skip to content

executor::util -> executor::bundled_program for bp runtime api #1056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ __pycache__/
build/lib/
exir/_serialize/scalar_type.fbs
exir/_serialize/program.fbs
bundled_program/serialize/bundled_program_schema.fbs
bundled_program/serialize/scalar_type.fbs
sdk/bundled_program/serialize/bundled_program_schema.fbs
sdk/bundled_program/serialize/scalar_type.fbs

# Any exported models and profiling outputs
*.pte
Expand Down
12 changes: 6 additions & 6 deletions backends/apple/mps/test/test_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
TestMPS,
)

from executorch.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.bundled_program.core import create_bundled_program
from executorch.bundled_program.serialize import (
serialize_from_bundled_program_to_flatbuffer,
)

from executorch.exir import ExirExportedProgram
from executorch.exir.backend.backend_api import to_backend
from executorch.exir.tests.models import (
Expand All @@ -44,6 +38,12 @@
Repeat,
)

from executorch.sdk.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.sdk.bundled_program.core import create_bundled_program
from executorch.sdk.bundled_program.serialize import (
serialize_from_bundled_program_to_flatbuffer,
)


class MODEL_TYPE(Enum):
EXIR_DEFAULT_MODEL = 0
Expand Down
10 changes: 5 additions & 5 deletions backends/apple/mps/test/test_mps_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

import torch
from executorch.backends.apple.mps.mps_preprocess import MPSBackend
from executorch.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.bundled_program.core import create_bundled_program
from executorch.bundled_program.serialize import (
serialize_from_bundled_program_to_flatbuffer,
)
from executorch.exir import ExecutorchProgram, ExirExportedProgram
from executorch.exir.backend.backend_api import to_backend, validation_disabled

from executorch.exir.print_program import print_program
from executorch.sdk.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.sdk.bundled_program.core import create_bundled_program
from executorch.sdk.bundled_program.serialize import (
serialize_from_bundled_program_to_flatbuffer,
)

# Config for Capturing the weights, will be moved in the future
_CAPTURE_CONFIG = exir.CaptureConfig(enable_aot=True, _unlift=True)
Expand Down
18 changes: 9 additions & 9 deletions backends/xnnpack/test/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ python_unittest(
"//executorch/backends/xnnpack:xnnpack_preprocess",
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
"//executorch/backends/xnnpack/utils:xnnpack_utils",
"//executorch/bundled_program:config",
"//executorch/bundled_program:core",
"//executorch/bundled_program/serialize:lib",
"//executorch/exir:lib",
"//executorch/exir/backend:backend_api",
"//executorch/exir/passes:spec_prop_pass",
"//executorch/extension/pybindings:portable_lib", # @manual
"//executorch/extension/pytree:pylib",
"//executorch/sdk/bundled_program:config",
"//executorch/sdk/bundled_program:core",
"//executorch/sdk/bundled_program/serialize:lib",
],
)

Expand All @@ -49,15 +49,15 @@ python_unittest(
"//executorch/backends/xnnpack:xnnpack_preprocess",
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
"//executorch/backends/xnnpack/utils:xnnpack_utils",
"//executorch/bundled_program:config",
"//executorch/bundled_program:core",
"//executorch/bundled_program/serialize:lib",
"//executorch/exir:lib",
"//executorch/exir/backend:backend_api",
"//executorch/exir/dialects:lib",
"//executorch/exir/passes:spec_prop_pass",
"//executorch/extension/pybindings:portable_lib", # @manual
"//executorch/extension/pytree:pylib",
"//executorch/sdk/bundled_program:config",
"//executorch/sdk/bundled_program:core",
"//executorch/sdk/bundled_program/serialize:lib",
],
)

Expand All @@ -78,14 +78,14 @@ python_unittest(
"//executorch/backends/xnnpack:xnnpack_preprocess",
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
"//executorch/backends/xnnpack/utils:xnnpack_utils",
"//executorch/bundled_program:config",
"//executorch/bundled_program:core",
"//executorch/bundled_program/serialize:lib",
"//executorch/exir:lib",
"//executorch/exir/backend:backend_api",
"//executorch/exir/passes:spec_prop_pass",
"//executorch/extension/pybindings:portable_lib", # @manual
"//executorch/extension/pytree:pylib",
"//executorch/sdk/bundled_program:config",
"//executorch/sdk/bundled_program:core",
"//executorch/sdk/bundled_program/serialize:lib",
"//pytorch/vision:torchvision",
],
)
Expand Down
12 changes: 6 additions & 6 deletions backends/xnnpack/test/test_xnnpack_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@

# import the xnnpack backend implementation
from executorch.backends.xnnpack.xnnpack_preprocess import XnnpackBackend

from executorch.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.bundled_program.core import create_bundled_program
from executorch.bundled_program.serialize import (
serialize_from_bundled_program_to_flatbuffer,
)
from executorch.exir import ExecutorchProgram, ExirExportedProgram
from executorch.exir.backend.backend_api import to_backend, validation_disabled

Expand All @@ -41,6 +35,12 @@
)
from executorch.extension.pytree import tree_flatten

from executorch.sdk.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.sdk.bundled_program.core import create_bundled_program
from executorch.sdk.bundled_program.serialize import (
serialize_from_bundled_program_to_flatbuffer,
)

from torch.ao.quantization import ( # @manual
default_per_channel_symmetric_qnnpack_qconfig,
PlaceholderObserver,
Expand Down
44 changes: 22 additions & 22 deletions docs/source/sdk-bundled-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Since each model may have multiple inference methods, we need to generate `List[

### Step 3: Generate `BundledProgram`

We provide `create_bundled_program` API under `executorch/bundled_program/core.py` to generate `BundledProgram` by bundling the emitted ExecuTorch program with the `List[MethodTestSuite]`:
We provide `create_bundled_program` API under `executorch/sdk/bundled_program/core.py` to generate `BundledProgram` by bundling the emitted ExecuTorch program with the `List[MethodTestSuite]`:

:::{dropdown} `BundledProgram`

Expand All @@ -61,7 +61,7 @@ We provide `create_bundled_program` API under `executorch/bundled_program/core.p

### Step 4: Serialize `BundledProgram` to Flatbuffer.

To serialize `BundledProgram` to make runtime APIs use it, we provide two APIs, both under `executorch/bundled_program/serialize/__init__.py`.
To serialize `BundledProgram` to make runtime APIs use it, we provide two APIs, both under `executorch/sdk/bundled_program/serialize/__init__.py`.

:::{dropdown} Serialize and Deserialize

Expand All @@ -86,9 +86,9 @@ Here is a flow highlighting how to generate a `BundledProgram` given a PyTorch m

import torch

from executorch.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.bundled_program.core import create_bundled_program
from executorch.bundled_program.serialize import (
from executorch.sdk.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.sdk.bundled_program.core import create_bundled_program
from executorch.sdk.bundled_program.serialize import (
serialize_from_bundled_program_to_flatbuffer,
)

Expand Down Expand Up @@ -195,7 +195,7 @@ with open(save_path, "wb") as f:
We can also regenerate `BundledProgram` from flatbuffer file if needed:

```python
from executorch.bundled_program.serialize import deserialize_from_flatbuffer_to_bundled_program
from executorch.sdk.bundled_program.serialize import deserialize_from_flatbuffer_to_bundled_program
save_path = "bundled_program.bpte"
with open(save_path, "rb") as f:
serialized_bundled_program = f.read()
Expand All @@ -213,7 +213,7 @@ We need the pointer to ExecuTorch program to do the execution. To unify the proc
:::{dropdown} `GetProgramData`

```{eval-rst}
.. doxygenfunction:: torch::executor::util::GetProgramData
.. doxygenfunction:: torch::executor::bundled_program::GetProgramData
```
:::

Expand All @@ -232,7 +232,7 @@ ET_CHECK_MSG(

const void* program_ptr;
size_t program_len;
status = torch::executor::util::GetProgramData(
status = torch::executor::bundled_program::GetProgramData(
buff_ptr.get(), buff_len, &program_ptr, &program_len);
ET_CHECK_MSG(
status == Error::Ok,
Expand All @@ -241,22 +241,22 @@ ET_CHECK_MSG(
```

### 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 `torch::executor::util::LoadBundledInput`:
To execute the program on the bundled input, we need to load the bundled input into the method. Here we provided an API called `torch::executor::bundled_program::LoadBundledInput`:

:::{dropdown} `LoadBundledInput`

```{eval-rst}
.. doxygenfunction:: torch::executor::util::LoadBundledInput
.. doxygenfunction:: torch::executor::bundled_program::LoadBundledInput
```
:::

### Verify the Method's Output.
We call `torch::executor::util::VerifyResultWithBundledExpectedOutput` to verify the method's output with bundled expected outputs. Here's the details of this API:
We call `torch::executor::bundled_program::VerifyResultWithBundledExpectedOutput` to verify the method's output with bundled expected outputs. Here's the details of this API:

:::{dropdown} `VerifyResultWithBundledExpectedOutput`

```{eval-rst}
.. doxygenfunction:: torch::executor::util::VerifyResultWithBundledExpectedOutput
.. doxygenfunction:: torch::executor::bundled_program::VerifyResultWithBundledExpectedOutput
```
:::

Expand All @@ -277,7 +277,7 @@ ET_CHECK_MSG(
method.error());

// Load testset_idx-th input in the buffer to plan
status = torch::executor::util::LoadBundledInput(
status = torch::executor::bundled_program::LoadBundledInput(
*method,
program_data.bundled_program_data(),
&bundled_input_allocator,
Expand All @@ -296,7 +296,7 @@ ET_CHECK_MSG(
status);

// Verify the result.
status = torch::executor::util::VerifyResultWithBundledExpectedOutput(
status = torch::executor::bundled_program::VerifyResultWithBundledExpectedOutput(
*method,
program_data.bundled_program_data(),
&bundled_input_allocator,
Expand Down Expand Up @@ -324,8 +324,8 @@ Here's the example of the dtype of test input not meet model's requirement:
```python
import torch

from executorch.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.bundled_program.core import create_bundled_program
from executorch.sdk.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.sdk.bundled_program.core import create_bundled_program

from executorch.exir import to_edge
from torch.export import export
Expand Down Expand Up @@ -411,7 +411,7 @@ Cell In[1], line 72
68 ]
70 # Step 3: Generate BundledProgram
---> 72 bundled_program = create_bundled_program(program, method_test_suites)
File /executorch/bundled_program/core.py:276, in create_bundled_program(program, method_test_suites)
File /executorch/sdk/bundled_program/core.py:276, in create_bundled_program(program, method_test_suites)
264 """Create bp_schema.BundledProgram by bundling the given program and method_test_suites together.
265
266 Args:
Expand All @@ -422,7 +422,7 @@ File /executorch/bundled_program/core.py:276, in create_bundled_program(program,
--> 276 assert_valid_bundle(program, method_test_suites)
278 bundled_method_test_suites: List[bp_schema.BundledMethodTestSuite] = []
280 # Emit data and metadata of bundled tensor
File /executorch/bundled_program/core.py:219, in assert_valid_bundle(program, method_test_suites)
File /executorch/sdk/bundled_program/core.py:219, in assert_valid_bundle(program, method_test_suites)
215 # type of tensor input should match execution plan
216 if type(cur_plan_test_inputs[j]) == torch.Tensor:
217 # pyre-fixme[16]: Undefined attribute [16]: Item `bool` of `typing.Union[bool, float, int, torch._tensor.Tensor]`
Expand Down Expand Up @@ -459,8 +459,8 @@ Another common error would be the method name in any `MethodTestSuite` does not
```python
import torch

from executorch.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.bundled_program.core import create_bundled_program
from executorch.sdk.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.sdk.bundled_program.core import create_bundled_program

from executorch.exir import to_edge
from torch.export import export
Expand Down Expand Up @@ -543,7 +543,7 @@ Cell In[3], line 73
70 method_test_suites[0].method_name = "MISSING_METHOD_NAME"
72 # Generate BundledProgram
---> 73 bundled_program = create_bundled_program(program, method_test_suites)
File /executorch/bundled_program/core.py:276, in create_bundled_program(program, method_test_suites)
File /executorch/sdk/bundled_program/core.py:276, in create_bundled_program(program, method_test_suites)
264 """Create bp_schema.BundledProgram by bundling the given program and method_test_suites together.
265
266 Args:
Expand All @@ -554,7 +554,7 @@ File /executorch/bundled_program/core.py:276, in create_bundled_program(program,
--> 276 assert_valid_bundle(program, method_test_suites)
278 bundled_method_test_suites: List[bp_schema.BundledMethodTestSuite] = []
280 # Emit data and metadata of bundled tensor
File /executorch/bundled_program/core.py:141, in assert_valid_bundle(program, method_test_suites)
File /executorch/sdk/bundled_program/core.py:141, in assert_valid_bundle(program, method_test_suites)
138 method_name_of_program = {e.name for e in program.execution_plan}
139 method_name_of_test_suites = {t.method_name for t in method_test_suites}
--> 141 assert method_name_of_test_suites.issubset(
Expand Down
10 changes: 5 additions & 5 deletions docs/source/tutorials_source/sdk-integration-tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ def forward(self, x):

import torch

from executorch.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.bundled_program.core import create_bundled_program
from executorch.bundled_program.serialize import (
from executorch.exir import to_edge

from executorch.sdk.bundled_program.config import MethodTestCase, MethodTestSuite
from executorch.sdk.bundled_program.core import create_bundled_program
from executorch.sdk.bundled_program.serialize import (
serialize_from_bundled_program_to_flatbuffer,
)

from executorch.exir import to_edge
from torch.export import export

# Step 1: ExecuTorch Program Export
Expand Down
Loading