Skip to content

Commit da2cd5b

Browse files
[pybind] Add pybind API reference docs (#6328)
Add pybind API reference docs (#6276) Summary: [pybind] Add pybind API reference docs As titled Pull Request resolved: #6276 Test Plan: https://docs-preview.pytorch.org/pytorch/executorch/6276/runtime-python-api-reference.html Reviewed By: dbort Differential Revision: D64449105 Pulled By: larryliu0820 fbshipit-source-id: 6a0d09510ff2a685c7d98a0119158a5d47d619be (cherry picked from commit 6b858f2) Co-authored-by: Mengwei Liu <[email protected]>
1 parent 0a64c3e commit da2cd5b

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Topics in this section will help you get started with ExecuTorch.
135135

136136
export-to-executorch-api-reference
137137
executorch-runtime-api-reference
138+
runtime-python-api-reference
138139
api-life-cycle
139140

140141
.. toctree::
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ExecuTorch Runtime Python API Reference
2+
----------------------------------
3+
The Python ``executorch.runtime`` module wraps the C++ ExecuTorch runtime. It can load and execute serialized ``.pte`` program files: see the `Export to ExecuTorch Tutorial <tutorials/export-to-executorch-tutorial.html>`__ for how to convert a PyTorch ``nn.Module`` to an ExecuTorch ``.pte`` program file. Execution accepts and returns ``torch.Tensor`` values, making it a quick way to validate the correctness of the program.
4+
5+
For detailed information on how APIs evolve and the deprecation process, please refer to the `ExecuTorch API Life Cycle and Deprecation Policy <api-life-cycle.html>`__.
6+
7+
.. automodule:: executorch.runtime
8+
.. autoclass:: Runtime
9+
:members: get, load_program
10+
11+
.. autoclass:: OperatorRegistry
12+
:members: operator_names
13+
14+
.. autoclass:: Program
15+
:members: method_names, load_method
16+
17+
.. autoclass:: Method
18+
:members: execute, metadata

runtime/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
"""Interface to the native C++ ExecuTorch runtime.
8-
7+
"""
98
Example usage:
10-
.. code-block:: text
9+
10+
.. code-block:: python
1111
1212
from pathlib import Path
1313
1414
import torch
15-
from executorch.runtime import Verification, Runtime
15+
from executorch.runtime import Verification, Runtime, Program, Method
1616
1717
et_runtime: Runtime = Runtime.get()
1818
program: Program = et_runtime.load_program(
@@ -28,6 +28,7 @@
2828
print(f" outputs: {outputs}")
2929
3030
Example output:
31+
3132
.. code-block:: text
3233
3334
Program methods: ('forward', 'forward2')
@@ -107,6 +108,9 @@ def __init__(self, module: ExecuTorchModule, data: Optional[bytes]) -> None:
107108

108109
@property
109110
def method_names(self) -> Set[str]:
111+
"""
112+
Returns method names of the `Program` as a set of strings.
113+
"""
110114
return set(self._methods.keys())
111115

112116
def load_method(self, name: str) -> Optional[Method]:
@@ -130,7 +134,9 @@ def __init__(self, legacy_module: ModuleType) -> None:
130134

131135
@property
132136
def operator_names(self) -> Set[str]:
133-
"""The names of all registered operators."""
137+
"""
138+
Returns the names of all registered operators as a set of strings.
139+
"""
134140
return set(self._legacy_module._get_operator_names())
135141

136142

0 commit comments

Comments
 (0)