Commit 20afa0a5 by Jared Roesch Committed by Tianqi Chen

[DOC][Relay]: Add API docs for Relay. (#1750)

parent cb06a184
...@@ -24,3 +24,4 @@ Python API ...@@ -24,3 +24,4 @@ Python API
vta/index vta/index
nnvm/index nnvm/index
hybrid hybrid
relay/index
tvm.relay.backend
-----------------
.. automodule:: tvm.relay.backend
Interpreter
-----------
.. automodule:: tvm.relay.backend.interpreter
:members:
.. automodule:: tvm.relay.backend.compile_engine
:members:
.. automodule:: tvm.relay.backend.graph_runtime_codegen
:members:
tvm.relay.base
--------------
.. automodule:: tvm.relay.base
.. autofunction:: tvm.relay.base.register_relay_node
.. autofunction:: tvm.relay.base.register_relay_attr_node
.. autoclass:: tvm.relay.base.RelayNode
:members:
.. autoclass:: tvm.relay.base.Span
:members:
.. autoclass:: tvm.relay.base.Id
:members:
tvm.relay.build_module
----------------------
.. automodule:: tvm.relay.build_module
.. autofunction:: tvm.relay.build_module.build
.. autofunction:: tvm.relay.build_module.optimize
.. autofunction:: tvm.relay.build_module.create_executor
.. autoclass:: tvm.relay.build_module.BuildConfig
:members:
.. autofunction:: tvm.relay.build_module.build_config
:members:
.. autoclass:: tvm.relay.build_module.GraphExecutor
:members:
tvm.relay.expr
--------------
.. automodule:: tvm.relay.expr
.. autofunction:: tvm.relay.expr.var
.. autofunction:: tvm.relay.expr.const
.. autofunction:: tvm.relay.expr.bind
.. autoclass:: tvm.relay.expr.Expr
:members:
.. autoclass:: tvm.relay.expr.Constant
:members:
.. autoclass:: tvm.relay.expr.Tuple
:members:
.. autoclass:: tvm.relay.expr.Var
:members:
.. autoclass:: tvm.relay.expr.GlobalVar
:members:
.. autoclass:: tvm.relay.expr.Function
:members:
.. autoclass:: tvm.relay.expr.Call
:members:
.. autoclass:: tvm.relay.expr.Let
:members:
.. autoclass:: tvm.relay.expr.If
:members:
.. autoclass:: tvm.relay.expr.TupleGetItem
:members:
.. autoclass:: tvm.relay.expr.TempExpr
:members:
.. autoclass:: tvm.relay.expr.ExprFunctor
:members:
.. autoclass:: tvm.relay.expr.ExprMutator
:members:
.. autoclass:: tvm.relay.expr.TupleWrapper
:members
tvm.relay.frontend
------------------
.. automodule:: tvm.relay.frontend
.. autofunction:: tvm.relay.frontend.from_mxnet
tvm.relay.image
---------------
.. automodule:: tvm.relay.image
:members:
.. automodule:: tvm.relay.op.image.image
:members:
Relay API
=========
This document contains the Python API for the Relay frontend, optimizer, and
compiler toolchain.
Relay is the second-generation, high-level intermediate representation (IR) for the TVM
compiler stack.
.. toctree::
:maxdepth: 2
backend
base
build_module
expr
frontend
image
ir_pass
module
nn
op
scope_builder
ty
vision
tvm.relay.ir_pass
-----------------
.. automodule:: tvm.relay.ir_pass
:members:
\ No newline at end of file
tvm.relay.module
----------------
.. automodule:: tvm.relay.module
.. autoclass:: tvm.relay.module.Module
:members:
tvm.relay.nn
------------
.. automodule:: tvm.relay.nn
:members:
.. automodule:: tvm.relay.op.nn.nn
:members:
tvm.relay.op
------------
.. automodule:: tvm.relay.op
:members:
.. automodule:: tvm.relay.op.op
:members:
.. automodule:: tvm.relay.op.reduce
:members:
.. automodule:: tvm.relay.op.tensor
:members:
.. automodule:: tvm.relay.op.transform
:members:
.. automodule:: tvm.relay.op.nn.nn
:members:
.. automodule:: tvm.relay.op.vision.multibox
:members:
.. automodule:: tvm.relay.op.vision.nms
:members:
tvm.relay.scope_builder
-----------------------
.. automodule:: tvm.relay.scope_builder
.. autoclass:: tvm.relay.scope_builder.ScopeBuilder
:members:
tvm.relay.ty
------------
.. automodule:: tvm.relay.ty
:members:
.. autoclass:: tvm.relay.ty.Type
:members:
.. autoclass:: tvm.relay.ty.TensorType
:members:
.. autoclass:: tvm.relay.ty.Kind
:members:
.. autoclass:: tvm.relay.ty.TypeVar
:members:
.. autoclass:: tvm.relay.ty.TypeConstraint
:members:
.. autoclass:: tvm.relay.ty.TupleType
:members:
.. autoclass:: tvm.relay.ty.FuncType
:members:
.. autoclass:: tvm.relay.ty.IncompleteType
:members:
.. autoclass:: tvm.relay.ty.TypeRelation
:members:
tvm.relay.vision
----------------
.. automodule:: tvm.relay.vision
:members:
.. automodule:: tvm.relay.op.vision.multibox
:members:
.. automodule:: tvm.relay.op.vision.nms
:members:
#pylint: disable=no-else-return #pylint: disable=no-else-return
"""An interface to the Realy interpreter.""" """The Python interface to the Relay reference interpreter."""
from __future__ import absolute_import from __future__ import absolute_import
import numpy as np import numpy as np
...@@ -23,6 +23,7 @@ class Value(NodeBase): ...@@ -23,6 +23,7 @@ class Value(NodeBase):
@register_relay_node @register_relay_node
class TupleValue(Value): class TupleValue(Value):
"""A tuple value produced by the interpreter."""
def __init__(self, *fields): def __init__(self, *fields):
self.__init_handle_by_constructor__( self.__init_handle_by_constructor__(
_make.TupleValue, fields) _make.TupleValue, fields)
...@@ -33,12 +34,13 @@ class TupleValue(Value): ...@@ -33,12 +34,13 @@ class TupleValue(Value):
@register_relay_node @register_relay_node
class Closure(Value): class Closure(Value):
"""A closure produced by the interpreter."""
pass pass
@register_relay_node @register_relay_node
class TensorValue(Value): class TensorValue(Value):
"""A Tensor value produced by the evaluator.""" """A Tensor value produced by the interpreter."""
def __init__(self, data): def __init__(self, data):
"""Allocate a new TensorValue and copy the data from `array` into """Allocate a new TensorValue and copy the data from `array` into
......
...@@ -8,12 +8,12 @@ from . import _expr ...@@ -8,12 +8,12 @@ from . import _expr
NodeBase = NodeBase NodeBase = NodeBase
def register_relay_node(type_key=None): def register_relay_node(type_key=None):
"""register relay node type """Register a Relay node type.
Parameters Parameters
---------- ----------
type_key : str or cls type_key : str or cls
The type key of the node The type key of the node.
""" """
if not isinstance(type_key, str): if not isinstance(type_key, str):
return _register_tvm_node( return _register_tvm_node(
...@@ -22,12 +22,12 @@ def register_relay_node(type_key=None): ...@@ -22,12 +22,12 @@ def register_relay_node(type_key=None):
def register_relay_attr_node(type_key=None): def register_relay_attr_node(type_key=None):
"""register relay attribute node """Register a Relay attribute node.
Parameters Parameters
---------- ----------
type_key : str or cls type_key : str or cls
The type key of the node The type key of the node.
""" """
if not isinstance(type_key, str): if not isinstance(type_key, str):
return _register_tvm_node( return _register_tvm_node(
...@@ -36,7 +36,7 @@ def register_relay_attr_node(type_key=None): ...@@ -36,7 +36,7 @@ def register_relay_attr_node(type_key=None):
class RelayNode(NodeBase): class RelayNode(NodeBase):
"""Base class of all relay node.""" """Base class of all Relay nodes."""
def astext(self, show_meta_data=True, annotate=None): def astext(self, show_meta_data=True, annotate=None):
"""Get the text format of the expression. """Get the text format of the expression.
...@@ -52,8 +52,8 @@ class RelayNode(NodeBase): ...@@ -52,8 +52,8 @@ class RelayNode(NodeBase):
Note Note
---- ----
meta data section is necessary to fully parse the text format. The metadata section is necessary to fully parse the text format.
However, it can contain dumps that are big(constat weights), However, it can contain dumps that are big (e.g constant weights)a,
so it can be helpful to skip printing the meta data section. so it can be helpful to skip printing the meta data section.
Returns Returns
...@@ -66,12 +66,16 @@ class RelayNode(NodeBase): ...@@ -66,12 +66,16 @@ class RelayNode(NodeBase):
@register_relay_node @register_relay_node
class Span(RelayNode): class Span(RelayNode):
"""Specifies a location in a source program."""
def __init__(self, source, lineno, col_offset): def __init__(self, source, lineno, col_offset):
self.__init_handle_by_constructor__(_make.Span, source, lineno, col_offset) self.__init_handle_by_constructor__(_make.Span, source, lineno, col_offset)
@register_relay_node @register_relay_node
class Id(NodeBase): class Id(NodeBase):
"""Unique identifier(name) for Var across type checking.""" """Unique identifier(name) used in Var.
Guaranteed to be stable across all passes.
"""
def __init__(self): def __init__(self):
raise RuntimeError("Cannot directly construct Id") raise RuntimeError("Cannot directly construct Id")
...@@ -240,13 +240,13 @@ class GraphExecutor(_interpreter.Executor): ...@@ -240,13 +240,13 @@ class GraphExecutor(_interpreter.Executor):
Parameters Parameters
---------- ----------
mod : tvm.relay.Module mod : :py:class:`~tvm.relay.module.Module`
The module to support the execution. The module to support the execution.
ctx : tvm.TVMContext ctx : :py:class:`TVMContext`
The runtime context to run the code on. The runtime context to run the code on.
target : tvm.Target target : :py:class:`Target`
The target option to build the function. The target option to build the function.
""" """
def __init__(self, mod, ctx, target): def __init__(self, mod, ctx, target):
...@@ -282,13 +282,13 @@ def create_executor(kind="debug", ...@@ -282,13 +282,13 @@ def create_executor(kind="debug",
kind : str kind : str
The type of executor The type of executor
mod : tvm.relay.Module mod : :py:class:`~tvm.relay.module.Module`
The Relay module containing collection of functions The Relay module containing collection of functions
ctx : tvm.TVMContext ctx : :py:class:`tvm.TVMContext`
The context to execute the code. The context to execute the code.
target : tvm.Target target : :py:class:`tvm.Target`
The corresponding context The corresponding context
""" """
if ctx is not None: if ctx is not None:
......
"""Relay frontends.""" """
Frontends for constructing Relay programs.
Contains the model importers currently defined
for Relay.
"""
from __future__ import absolute_import from __future__ import absolute_import
from .mxnet import from_mxnet from .mxnet import from_mxnet
# pylint: disable=wildcard-import, unused-import, unused-wildcard-import # pylint: disable=wildcard-import, unused-import, unused-wildcard-import
"""Image nets related operators.""" """Image network related operators."""
# Re-export in a specific file name so that autodoc can pick it up # Re-export in a specific file name so that autodoc can pick it up
from .op.image import * from .op.image import *
...@@ -61,7 +61,7 @@ class ScopeBuilder(object): ...@@ -61,7 +61,7 @@ class ScopeBuilder(object):
Examples Examples
-------- --------
..code-block: python .. code-block: python
sb = relay.ScopeBuilder() sb = relay.ScopeBuilder()
cond = relay.var("cond", 'bool') cond = relay.var("cond", 'bool')
...@@ -115,7 +115,7 @@ class ScopeBuilder(object): ...@@ -115,7 +115,7 @@ class ScopeBuilder(object):
Parameters Parameters
---------- ----------
cond: tvm.relay.Expr cond: tvm.relay.expr.Expr
The condition The condition
Returns Returns
...@@ -165,7 +165,7 @@ class ScopeBuilder(object): ...@@ -165,7 +165,7 @@ class ScopeBuilder(object):
Parameters Parameters
---------- ----------
value: tvm.relay.Expr value: tvm.relay.expr.Expr
The return value. The return value.
""" """
if self._ret_values[-1] is not None: if self._ret_values[-1] is not None:
...@@ -177,7 +177,7 @@ class ScopeBuilder(object): ...@@ -177,7 +177,7 @@ class ScopeBuilder(object):
Returns Returns
------- -------
value: tvm.relay.Expr value: tvm.relay.expr.Expr
The final result of the expression. The final result of the expression.
""" """
if len(self._bindings) != 1: if len(self._bindings) != 1:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment