Skip to content

make et program serialization in bp in line with et program manager #8334

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

Merged
merged 1 commit into from
Feb 11, 2025
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
1 change: 0 additions & 1 deletion devtools/bundled_program/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ runtime.python_library(
"//executorch/devtools/bundled_program/schema:bundled_program_schema_py",
"//executorch/exir:schema",
"//executorch/exir:tensor",
"//executorch/exir/_serialize:lib",
],
)

Expand Down
18 changes: 7 additions & 11 deletions devtools/bundled_program/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from executorch.devtools.bundled_program.version import BUNDLED_PROGRAM_SCHEMA_VERSION

from executorch.exir import ExecutorchProgram, ExecutorchProgramManager
from executorch.exir._serialize import _deserialize_pte_binary, _serialize_pte_binary
from executorch.exir.tensor import get_scalar_type, scalar_type_enum, TensorSpec

# pyre-ignore
Expand Down Expand Up @@ -92,14 +91,6 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
if self._bundled_program_in_schema is not None:
return self._bundled_program_in_schema

if self.executorch_program:
program = self._extract_program(self.executorch_program)
else:
assert self._pte_file_path is not None
with open(self._pte_file_path, "rb") as f:
p_bytes = f.read()
program = _deserialize_pte_binary(p_bytes)

bundled_method_test_suites: List[bp_schema.BundledMethodTestSuite] = []

# Emit data and metadata of bundled tensor
Expand Down Expand Up @@ -149,8 +140,13 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
)
)

# TODO(T181463742): avoid calling bytes(..) which may incur large copies.
program_bytes: bytes = bytes(_serialize_pte_binary(program))
if self.executorch_program:
program_bytes = self.executorch_program.buffer
else:
assert self._pte_file_path is not None
with open(self._pte_file_path, "rb") as f:
program_bytes = f.read()

self._bundled_program_in_schema = bp_schema.BundledProgram(
version=BUNDLED_PROGRAM_SCHEMA_VERSION,
method_test_suites=bundled_method_test_suites,
Expand Down
2 changes: 1 addition & 1 deletion devtools/bundled_program/test/test_bundle_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_bundled_program_from_pte(self) -> None:

self.assertEqual(
bundled_program.serialize_to_schema().program,
bytes(_serialize_pte_binary(executorch_program.executorch_program)),
executorch_program.buffer,
)

def test_bundled_miss_methods(self) -> None:
Expand Down
Loading