Skip to content

Commit eddbb27

Browse files
lucylqfacebook-github-bot
authored andcommitted
Get data file buffers from python API
Summary: #14133 Retrieve tensor data as a buffer (like executorch_program.buffer), so it can be used in pybindings, see D82046648 Differential Revision: D82061884
1 parent 8496f27 commit eddbb27

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

exir/program/_program.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from executorch.exir._serialize._serialize import serialize_for_executorch
2424
from executorch.exir._serialize.data_serializer import DataSerializer
25+
from executorch.exir._warnings import experimental
2526
from executorch.exir.backend.backend_api import (
2627
MethodProgramsPartitionerSpec,
2728
to_backend,
@@ -626,6 +627,24 @@ def buffer(self) -> bytes:
626627
self._buffer = bytes(self._get_pte_data())
627628
return self._buffer
628629

630+
@property
631+
@experimental("This API is experimental and subject to change without notice.")
632+
def data_files(self) -> Dict[str, bytes]:
633+
"""Returns the data files as a dictionary of filename to byte data.
634+
635+
Returns:
636+
Dict[str, bytes]: Dictionary mapping data filenames (e.g., .ptd files) to
637+
their serialized byte content.
638+
Returns empty dict if no data files are available.
639+
"""
640+
if self._pte_data is None:
641+
self._get_pte_data() # This populates _tensor_data
642+
643+
if self._tensor_data is None:
644+
return {}
645+
646+
return {filename: bytes(cord) for filename, cord in self._tensor_data.items()}
647+
629648
@property
630649
def program(self) -> Program:
631650
return self._get_emitter_output().program

0 commit comments

Comments
 (0)