Loads an ExecuTorch program from a PTE binary. Args: data: The binary program data to load. Can be a file path (str or Path), bytes/bytearray, or a file-like object. verification: Level of program verification to perform (Minimal or InternalConsistenc
(
self,
data: Union[bytes, bytearray, BinaryIO, Path, str],
*,
verification: Verification = Verification.InternalConsistency,
enable_etdump: bool = False,
debug_buffer_size: int = 0,
)
| 283 | self._legacy_module = legacy_module |
| 284 | |
| 285 | def load_program( |
| 286 | self, |
| 287 | data: Union[bytes, bytearray, BinaryIO, Path, str], |
| 288 | *, |
| 289 | verification: Verification = Verification.InternalConsistency, |
| 290 | enable_etdump: bool = False, |
| 291 | debug_buffer_size: int = 0, |
| 292 | ) -> Program: |
| 293 | """Loads an ExecuTorch program from a PTE binary. |
| 294 | |
| 295 | Args: |
| 296 | data: The binary program data to load. Can be a file path (str or Path), |
| 297 | bytes/bytearray, or a file-like object. |
| 298 | verification: Level of program verification to perform (Minimal or InternalConsistency). |
| 299 | Default is InternalConsistency. |
| 300 | enable_etdump: If True, enables ETDump profiling for runtime performance analysis. |
| 301 | Default is False. |
| 302 | debug_buffer_size: Size of the debug buffer in bytes for ETDump data. |
| 303 | Only used when enable_etdump=True. Default is 0. |
| 304 | |
| 305 | Returns: |
| 306 | The loaded Program instance. |
| 307 | """ |
| 308 | if isinstance(data, (Path, str)): |
| 309 | p = self._legacy_module._load_program( |
| 310 | str(data), |
| 311 | enable_etdump=enable_etdump, |
| 312 | debug_buffer_size=debug_buffer_size, |
| 313 | program_verification=verification, |
| 314 | ) |
| 315 | return Program(p, data=None) |
| 316 | elif isinstance(data, bytes): |
| 317 | data_bytes = data |
| 318 | elif isinstance(data, bytearray): |
| 319 | data_bytes = bytes(data) |
| 320 | elif hasattr(data, "read"): |
| 321 | # File-like object with read() method |
| 322 | data_bytes = data.read() |
| 323 | else: |
| 324 | raise TypeError( |
| 325 | f"Expected data to be bytes, bytearray, a path to a .pte file, or a file-like object, but got {type(data).__name__}." |
| 326 | ) |
| 327 | p = self._legacy_module._load_program_from_buffer( |
| 328 | data_bytes, |
| 329 | enable_etdump=enable_etdump, |
| 330 | debug_buffer_size=debug_buffer_size, |
| 331 | program_verification=verification, |
| 332 | ) |
| 333 | |
| 334 | return Program(p, data=data_bytes) |