Skip to content

Commit 04782ba

Browse files
JacobSzwejbkafacebook-github-bot
authored andcommitted
add exir-api-reference.rst (#457)
Summary: Pull Request resolved: #457 Reviewed By: svekars, angelayi Differential Revision: D49551799 fbshipit-source-id: ef3334d71568b929b3eaa3221d50bee0ea67846b
1 parent 782fded commit 04782ba

File tree

4 files changed

+64
-30
lines changed

4 files changed

+64
-30
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Export to ExecuTorch API Reference
2+
----------------------------------
3+
4+
.. automodule:: exir
5+
.. autofunction:: to_edge
6+
7+
.. autoclass:: EdgeProgramManager
8+
:members: methods, config_methods, exported_program, transform, to_backend, to_executorch
9+
10+
.. autoclass:: ExecutorchProgramManager
11+
:members: methods, config_methods, exported_program, buffer, debug_handle_map, dump_executorch_program
12+
13+
.. automodule:: exir.backend.backend_api
14+
.. autofunction:: to_backend
15+
16+
.. autoclass:: LoweredBackendModule
17+
:members: backend_id, processed_bytes, compile_specs, original_module, buffer, program

docs/source/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ Topics in this section will help you get started with ExecuTorch.
9393

9494
export-overview
9595

96+
.. toctree::
97+
:glob:
98+
:maxdepth: 1
99+
:caption: API Reference
100+
:hidden:
101+
102+
export-to-executorch-api-reference
103+
96104
.. toctree::
97105
:glob:
98106
:maxdepth: 1

exir/backend/backend_api.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,22 @@ def to_backend(args):
4040
"""
4141
A generic function the dispatch happens on the type of the first argument. There are currently to overloaded to_backend function:
4242
43-
def to_backend(
44-
backend_id: str,
45-
edge_graph_module: ExportedProgram,
46-
compile_specs: List[CompileSpec],
47-
) -> LoweredBackendModule:
48-
49-
def to_backend(
50-
graph_module: torch.fx.GraphModule,
51-
partitioner: Type[TPartitioner],
52-
) -> torch.fx.GraphModule
53-
5443
Note: Python is dynamically-typed language and therefore cannot have proper method overloading as that requires the language to
5544
be able to discriminate between types at compile-time. @to_backend.register will attach the function to to_backend() base on the type of the first
5645
argument (type annotation is required). However, it can't take multiple types as arguments.
46+
47+
::
48+
49+
def to_backend(
50+
backend_id: str,
51+
edge_graph_module: ExportedProgram,
52+
compile_specs: List[CompileSpec],
53+
) -> LoweredBackendModule:
54+
55+
def to_backend(
56+
graph_module: torch.fx.GraphModule,
57+
partitioner: Type[TPartitioner],
58+
) -> torch.fx.GraphModule
5759
"""
5860
pass
5961

@@ -66,11 +68,16 @@ def _(
6668
) -> LoweredBackendModule:
6769
"""
6870
Add overloaded implementations for to_backend:
69-
def to_backend(
70-
backend_id: str,
71-
edge_program: ExportedProgram,
72-
compile_specs: List[CompileSpec],
73-
) -> LoweredBackendModule:
71+
72+
::
73+
74+
def to_backend(
75+
backend_id: str,
76+
edge_program: ExportedProgram,
77+
compile_specs: List[CompileSpec],
78+
) -> LoweredBackendModule:
79+
80+
7481
Requires the passed in exported program in Edge dialect to be executed in
7582
the backend identified by backend_id. The forward method of the given
7683
edge_graph_module will be targeted for execution.
@@ -258,10 +265,13 @@ def _(
258265
) -> ExportedProgram:
259266
"""
260267
Add overloaded implementations for to_backend:
261-
def to_backend(
262-
edge_program: ExportedProgram,
263-
partitioner: Type[TPartitioner],
264-
) -> ExportedProgram:
268+
269+
::
270+
271+
def to_backend(
272+
edge_program: ExportedProgram,
273+
partitioner: Type[TPartitioner],
274+
) -> ExportedProgram:
265275
266276
Returns a semantically-equivalent program to the one given as input (represented
267277
as a graph module in Edge dialect), but with portions of the program targeted for

exir/program/_program.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -567,19 +567,18 @@ def to_edge(
567567
compile_config: Optional[EdgeCompileConfig] = None,
568568
) -> "EdgeProgramManager":
569569
"""
570-
Constructs an EdgeProgramManger from a set of exported programs in
571-
aten dialect. Upon construction those programs are transformed into edge dialect.
570+
:func:`to_edge` constructs an EdgeProgramManger from a set of exported programs in
571+
ATen dialect. Upon construction those programs are transformed into edge dialect.
572572
573573
Args:
574-
Can be a single ExportedProgram or a dictionary mapping function names
575-
to their corresponding ExportedPrograms. If only a single ExportedProgram is provided
576-
it will be assigned the name "forward".
574+
programs: Can be a single ExportedProgram or a dictionary mapping function names to their corresponding ExportedPrograms. If only a single ExportedProgram is provided it will be assigned the name "forward".
577575
578-
constant_methods: An optional dictionary of method name to the constant value returned
579-
by that method in eager mode. Often used to store config information on Edge models.
576+
constant_methods: An optional dictionary of method name to the constant value returned by that method in eager mode. Often used to store config information on Edge models.
580577
581-
compile_config: An optional argument used to provide greater control over
582-
the transformation to edge dialect process.
578+
compile_config: An optional argument used to provide greater control over the transformation to edge dialect process.
579+
580+
Returns:
581+
EdgeProgramManager
583582
"""
584583
config = compile_config or EdgeCompileConfig()
585584
if not isinstance(programs, dict):
@@ -593,7 +592,7 @@ def to_edge(
593592
try:
594593
EXIRATenDialectVerifier()(program.graph_module)
595594
except ExportError as e:
596-
logging.info(f"Input program {name} is not in aten dialect.")
595+
logging.info(f"Input program {name} is not in ATen dialect.")
597596
raise e
598597

599598
op_replace_pass = [OpReplacePass()] if config._use_edge_ops else []

0 commit comments

Comments
 (0)