Skip to content

put bundled program under executorch/sdk #1014

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 1 commit 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
28 changes: 14 additions & 14 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 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
10 changes: 5 additions & 5 deletions examples/apple/mps/scripts/mps_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import torch._export as export
from executorch import exir
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.backend.backend_api import to_backend
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 ....models import MODEL_NAME_TO_MODEL
from ....models.model_factory import EagerModelFactory
Expand Down
8 changes: 4 additions & 4 deletions examples/sdk/scripts/export_bundled_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
from typing import List

import torch
from executorch.bundled_program.config import (
from executorch.exir.schema import Program
from executorch.sdk.bundled_program.config import (
MethodInputType,
MethodTestCase,
MethodTestSuite,
)
from executorch.bundled_program.core import create_bundled_program
from executorch.bundled_program.serialize import (
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.schema import Program

from ...models import MODEL_NAME_TO_MODEL
from ...models.model_factory import EagerModelFactory
Expand Down
8 changes: 4 additions & 4 deletions exir/_serialize/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cpp_python_extension(
"//executorch/backends/fb/qnnpack/...",
"//executorch/backends/vulkan/...",
"//executorch/backends/xnnpack/...",
"//executorch/bundled_program/...",
"//executorch/sdk/bundled_program/...",
"//executorch/sdk/etdump/...",
],
deps = [
Expand Down Expand Up @@ -43,9 +43,6 @@ runtime.python_library(
# Please ask before changing this.
visibility = [
"//executorch/backends/...",
"//executorch/bundled_program:core",
"//executorch/bundled_program/serialize:lib",
"//executorch/bundled_program/tests/...",
"//executorch/codegen/...",
"//executorch/examples/async_exec:emit_program_lib",
"//executorch/exir/...",
Expand All @@ -54,6 +51,9 @@ runtime.python_library(
"//executorch/extension/pybindings/test:test",
"//executorch/extension/pybindings/test:test-library",
"//executorch/profiler/...",
"//executorch/sdk/bundled_program:core",
"//executorch/sdk/bundled_program/serialize:lib",
"//executorch/sdk/bundled_program/tests/...",
"//executorch/sdk/experimental/...",
"//executorch/test/...",
"@EXECUTORCH_CLIENTS",
Expand Down
8 changes: 4 additions & 4 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ addopts =
# don't suppress warnings, but don't shove them all to the end either
-p no:warnings
# explicitly list out tests that are running successfully in oss
# bundled_program/
bundled_program/tests/test_bundle_data.py
bundled_program/tests/test_config.py
bundled_program/tests/test_serialize.py
# sdk/
sdk/bundled_program/tests/test_bundle_data.py
sdk/bundled_program/tests/test_config.py
sdk/bundled_program/tests/test_serialize.py
# exir
exir/backend/test/test_graph_partition.py
exir/backend/test/test_backends_nested.py
Expand Down
6 changes: 3 additions & 3 deletions schema/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def define_common_targets():
runtime.export_file(
name = INPUT_BUNDLED,
visibility = [
"//executorch/bundled_program/serialize/...",
"//executorch/sdk/bundled_program/serialize/...",
],
)
runtime.export_file(
name = INPUT_SCALAR_TYPE,
visibility = [
"//executorch/bundled_program/serialize/...",
"//executorch/sdk/bundled_program/serialize/...",
"//executorch/exir/_serialize/...",
"//executorch/sdk/etdump/...",
],
Expand Down Expand Up @@ -110,7 +110,7 @@ def define_common_targets():
name = BUNDLED_LIBRARY_NAME,
srcs = [],
visibility = [
"//executorch/bundled_program/...",
"//executorch/sdk/bundled_program/...",
"//executorch/extension/pybindings/...",
"//executorch/examples/bundled_executor_runner/...",
"//executorch/util/...", # bundled_program_verification
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions bundled_program/core.py → sdk/bundled_program/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
import typing
from typing import Dict, List, Sequence, Type

import executorch.bundled_program.schema as bp_schema
import executorch.exir.schema as core_schema

import executorch.sdk.bundled_program.schema as bp_schema

import torch
import torch.fx
from executorch.bundled_program.config import ConfigValue, MethodTestSuite

from executorch.bundled_program.version import BUNDLED_PROGRAM_SCHEMA_VERSION
from executorch.exir._serialize import _serialize_pte_binary

from executorch.exir.tensor import get_scalar_type, scalar_type_enum, TensorSpec
from executorch.sdk.bundled_program.config import ConfigValue, MethodTestSuite

from executorch.sdk.bundled_program.version import BUNDLED_PROGRAM_SCHEMA_VERSION

# pyre-ignore
supported_program_type_table: Dict[Type[core_schema.KernelTypes], ConfigValue] = {
Expand Down
File renamed without changes.
Loading