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