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

Class Runtime

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

An instance of the ExecuTorch runtime environment. This can be used to concurrently load and execute any number of ExecuTorch programs and methods. Attributes: backend_registry: Registry for querying available hardware backends. operator_registry: Registry for querying

Source from the content-addressed store, hash-verified

257
258
259class Runtime:
260 """An instance of the ExecuTorch runtime environment.
261
262 This can be used to concurrently load and execute any number of ExecuTorch
263 programs and methods.
264
265 Attributes:
266 backend_registry: Registry for querying available hardware backends.
267 operator_registry: Registry for querying available operators/kernels.
268 """
269
270 @staticmethod
271 @functools.lru_cache(maxsize=1)
272 def get() -> "Runtime":
273 """Gets the Runtime singleton."""
274 import executorch.extension.pybindings.portable_lib as legacy_module # type: ignore[import-not-found]
275
276 return Runtime(legacy_module=legacy_module)
277
278 def __init__(self, *, legacy_module: ModuleType) -> None:
279 # Public attributes.
280 self.backend_registry = BackendRegistry(legacy_module)
281 self.operator_registry = OperatorRegistry(legacy_module)
282 # Private attributes.
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):

Callers 1

getMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected