Skip to content

add exir-api-reference.rst #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/source/export-to-executorch-api-reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Export to ExecuTorch API Reference
----------------------------------

.. automodule:: exir
.. autofunction:: to_edge

.. autoclass:: EdgeProgramManager
:members: methods, config_methods, exported_program, transform, to_backend, to_executorch

.. autoclass:: ExecutorchProgramManager
:members: methods, config_methods, exported_program, buffer, debug_handle_map, dump_executorch_program

.. automodule:: exir.backend.backend_api
.. autofunction:: to_backend

.. autoclass:: LoweredBackendModule
:members: backend_id, processed_bytes, compile_specs, original_module, buffer, program
8 changes: 8 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ Topics in this section will help you get started with ExecuTorch.

export-overview

.. toctree::
:glob:
:maxdepth: 1
:caption: API Reference
:hidden:

export-to-executorch-api-reference

.. toctree::
:glob:
:maxdepth: 1
Expand Down
50 changes: 30 additions & 20 deletions exir/backend/backend_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ def to_backend(args):
"""
A generic function the dispatch happens on the type of the first argument. There are currently to overloaded to_backend function:

def to_backend(
backend_id: str,
edge_graph_module: ExportedProgram,
compile_specs: List[CompileSpec],
) -> LoweredBackendModule:

def to_backend(
graph_module: torch.fx.GraphModule,
partitioner: Type[TPartitioner],
) -> torch.fx.GraphModule

Note: Python is dynamically-typed language and therefore cannot have proper method overloading as that requires the language to
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
argument (type annotation is required). However, it can't take multiple types as arguments.

::

def to_backend(
backend_id: str,
edge_graph_module: ExportedProgram,
compile_specs: List[CompileSpec],
) -> LoweredBackendModule:

def to_backend(
graph_module: torch.fx.GraphModule,
partitioner: Type[TPartitioner],
) -> torch.fx.GraphModule
"""
pass

Expand All @@ -66,11 +68,16 @@ def _(
) -> LoweredBackendModule:
"""
Add overloaded implementations for to_backend:
def to_backend(
backend_id: str,
edge_program: ExportedProgram,
compile_specs: List[CompileSpec],
) -> LoweredBackendModule:

::

def to_backend(
backend_id: str,
edge_program: ExportedProgram,
compile_specs: List[CompileSpec],
) -> LoweredBackendModule:


Requires the passed in exported program in Edge dialect to be executed in
the backend identified by backend_id. The forward method of the given
edge_graph_module will be targeted for execution.
Expand Down Expand Up @@ -258,10 +265,13 @@ def _(
) -> ExportedProgram:
"""
Add overloaded implementations for to_backend:
def to_backend(
edge_program: ExportedProgram,
partitioner: Type[TPartitioner],
) -> ExportedProgram:

::

def to_backend(
edge_program: ExportedProgram,
partitioner: Type[TPartitioner],
) -> ExportedProgram:

Returns a semantically-equivalent program to the one given as input (represented
as a graph module in Edge dialect), but with portions of the program targeted for
Expand Down
19 changes: 9 additions & 10 deletions exir/program/_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,19 +567,18 @@ def to_edge(
compile_config: Optional[EdgeCompileConfig] = None,
) -> "EdgeProgramManager":
"""
Constructs an EdgeProgramManger from a set of exported programs in
aten dialect. Upon construction those programs are transformed into edge dialect.
:func:`to_edge` constructs an EdgeProgramManger from a set of exported programs in
ATen dialect. Upon construction those programs are transformed into edge dialect.

Args:
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".
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".

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.
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.

compile_config: An optional argument used to provide greater control over
the transformation to edge dialect process.
compile_config: An optional argument used to provide greater control over the transformation to edge dialect process.

Returns:
EdgeProgramManager
"""
config = compile_config or EdgeCompileConfig()
if not isinstance(programs, dict):
Expand All @@ -593,7 +592,7 @@ def to_edge(
try:
EXIRATenDialectVerifier()(program.graph_module)
except ExportError as e:
logging.info(f"Input program {name} is not in aten dialect.")
logging.info(f"Input program {name} is not in ATen dialect.")
raise e

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