Skip to content

Commit 97502d5

Browse files
Gasoonjiafacebook-github-bot
authored andcommitted
make et program serialization in bp in line with et program manager
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 97502d5

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

devtools/bundled_program/core.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
9292
if self._bundled_program_in_schema is not None:
9393
return self._bundled_program_in_schema
9494

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-
10395
bundled_method_test_suites: List[bp_schema.BundledMethodTestSuite] = []
10496

10597
# Emit data and metadata of bundled tensor
@@ -149,8 +141,13 @@ def serialize_to_schema(self) -> bp_schema.BundledProgram:
149141
)
150142
)
151143

152-
# TODO(T181463742): avoid calling bytes(..) which may incur large copies.
153-
program_bytes: bytes = bytes(_serialize_pte_binary(program))
144+
if self.executorch_program:
145+
program_bytes = self.executorch_program.buffer
146+
else:
147+
assert self._pte_file_path is not None
148+
with open(self._pte_file_path, "rb") as f:
149+
program_bytes = f.read()
150+
154151
self._bundled_program_in_schema = bp_schema.BundledProgram(
155152
version=BUNDLED_PROGRAM_SCHEMA_VERSION,
156153
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)