Skip to content

Commit 94d2cdf

Browse files
Gasoonjiafacebook-github-bot
authored andcommitted
make et program serialization in bp in line with et program manager (#8334)
Summary: This change ensures that the serialization of bundled programs is consistent with the serialization of programs in the `et` program manager. Differential Revision: D69395142
1 parent 524ec78 commit 94d2cdf

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

devtools/bundled_program/TARGETS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ runtime.python_library(
2121
"//executorch/devtools/bundled_program/schema:bundled_program_schema_py",
2222
"//executorch/exir:schema",
2323
"//executorch/exir:tensor",
24-
"//executorch/exir/_serialize:lib",
2524
],
2625
)
2726

devtools/bundled_program/core.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from executorch.devtools.bundled_program.version import BUNDLED_PROGRAM_SCHEMA_VERSION
2020

2121
from executorch.exir import ExecutorchProgram, ExecutorchProgramManager
22-
from executorch.exir._serialize import _deserialize_pte_binary, _serialize_pte_binary
2322
from executorch.exir.tensor import get_scalar_type, scalar_type_enum, TensorSpec
2423

2524
# pyre-ignore
@@ -92,14 +91,6 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
9291
if self._bundled_program_in_schema is not None:
9392
return self._bundled_program_in_schema
9493

95-
if self.executorch_program:
96-
program = self._extract_program(self.executorch_program)
97-
else:
98-
assert self._pte_file_path is not None
99-
with open(self._pte_file_path, "rb") as f:
100-
p_bytes = f.read()
101-
program = _deserialize_pte_binary(p_bytes)
102-
10394
bundled_method_test_suites: List[bp_schema.BundledMethodTestSuite] = []
10495

10596
# Emit data and metadata of bundled tensor
@@ -149,8 +140,13 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
149140
)
150141
)
151142

152-
# TODO(T181463742): avoid calling bytes(..) which may incur large copies.
153-
program_bytes: bytes = bytes(_serialize_pte_binary(program))
143+
if self.executorch_program:
144+
program_bytes = self.executorch_program.buffer
145+
else:
146+
assert self._pte_file_path is not None
147+
with open(self._pte_file_path, "rb") as f:
148+
program_bytes = f.read()
149+
154150
self._bundled_program_in_schema = bp_schema.BundledProgram(
155151
version=BUNDLED_PROGRAM_SCHEMA_VERSION,
156152
method_test_suites=bundled_method_test_suites,

devtools/bundled_program/test/test_bundle_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_bundled_program_from_pte(self) -> None:
115115

116116
self.assertEqual(
117117
bundled_program.serialize_to_schema().program,
118-
bytes(_serialize_pte_binary(executorch_program.executorch_program)),
118+
executorch_program.buffer,
119119
)
120120

121121
def test_bundled_miss_methods(self) -> None:

0 commit comments

Comments
 (0)