MCPcopy Create free account
hub / github.com/pytorch/executorch / load_program

Method load_program

runtime/__init__.py:285–334  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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)

Callers 15

_test_pass_e2eMethod · 0.80
_run_and_compareMethod · 0.80
run_executorch_testMethod · 0.80
run_inferenceFunction · 0.80
run_whisper_inferenceFunction · 0.80
execute_layer_testMethod · 0.80

Calls 1

ProgramClass · 0.70