From 6e5676e079d004cf3fb4ab53960296b09c856c64 Mon Sep 17 00:00:00 2001 From: Lucy Qiu Date: Wed, 10 Sep 2025 16:23:59 -0700 Subject: [PATCH] Get data file buffers from python API (#14133) Summary: https://github.com/pytorch/executorch/pull/14133 Retrieve tensor data as a buffer (like executorch_program.buffer), so it can be used in pybindings, see D82046648 Reviewed By: JacobSzwejbka Differential Revision: D82061884 --- exir/program/_program.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/exir/program/_program.py b/exir/program/_program.py index b6eba6b5d18..f3d9eef9221 100644 --- a/exir/program/_program.py +++ b/exir/program/_program.py @@ -22,6 +22,7 @@ ) from executorch.exir._serialize._serialize import serialize_for_executorch from executorch.exir._serialize.data_serializer import DataSerializer +from executorch.exir._warnings import experimental from executorch.exir.backend.backend_api import ( MethodProgramsPartitionerSpec, to_backend, @@ -626,6 +627,24 @@ def buffer(self) -> bytes: self._buffer = bytes(self._get_pte_data()) return self._buffer + @property + @experimental("This API is experimental and subject to change without notice.") + def data_files(self) -> Dict[str, bytes]: + """Returns the data files as a dictionary of filename to byte data. + + Returns: + Dict[str, bytes]: Dictionary mapping data filenames (e.g., .ptd files) to + their serialized byte content. + Returns empty dict if no data files are available. + """ + if self._pte_data is None: + self._get_pte_data() # This populates _tensor_data + + if self._tensor_data is None: + return {} + + return {filename: bytes(cord) for filename, cord in self._tensor_data.items()} + @property def program(self) -> Program: return self._get_emitter_output().program