diff --git a/devtools/bundled_program/TARGETS b/devtools/bundled_program/TARGETS index 27560f70877..74e813cbf80 100644 --- a/devtools/bundled_program/TARGETS +++ b/devtools/bundled_program/TARGETS @@ -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", ], ) diff --git a/devtools/bundled_program/core.py b/devtools/bundled_program/core.py index 2c930f06b74..a72b7fa962f 100644 --- a/devtools/bundled_program/core.py +++ b/devtools/bundled_program/core.py @@ -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 @@ -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 @@ -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, diff --git a/devtools/bundled_program/test/test_bundle_data.py b/devtools/bundled_program/test/test_bundle_data.py index b833903c2fd..a587a8672e9 100644 --- a/devtools/bundled_program/test/test_bundle_data.py +++ b/devtools/bundled_program/test/test_bundle_data.py @@ -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: