Skip to content

Commit

Permalink
[DOCS] Bring relay docs to the top-level flat view (apache#5343)
Browse files Browse the repository at this point in the history
- Changes most of the relay docs to use autosummary.
- Bring relay API docs to the top-level flat view for easier discovery
- Removed a few cases of re-exports.
  • Loading branch information
tqchen authored and dpankratz committed Apr 24, 2020
1 parent 2252f17 commit a77b429
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 90 deletions.
10 changes: 9 additions & 1 deletion docs/api/python/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ Python API
tir
te
driver
relay/index
relay/frontend
relay/nn
relay/vision
relay/image
relay/transform
relay/analysis
relay/backend
relay/testing
autotvm
rpc
contrib
graph_runtime
relay/index
vta/index
topi
19 changes: 3 additions & 16 deletions docs/api/python/relay/frontend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ tvm.relay.frontend
------------------

.. automodule:: tvm.relay.frontend

.. autofunction:: tvm.relay.frontend.from_mxnet

.. autofunction:: tvm.relay.frontend.from_keras

.. autofunction:: tvm.relay.frontend.from_onnx

.. autofunction:: tvm.relay.frontend.from_tflite

.. autofunction:: tvm.relay.frontend.from_coreml

.. autofunction:: tvm.relay.frontend.from_caffe2

.. autofunction:: tvm.relay.frontend.from_tensorflow

.. autofunction:: tvm.relay.frontend.from_pytorch
:members:
:imported-members:
:autosummary:
4 changes: 2 additions & 2 deletions docs/api/python/relay/image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
tvm.relay.image
---------------

.. automodule:: tvm.relay.op.image
.. automodule:: tvm.relay.image
:members:
:imported-members:
:exclude-members:
:autosummary:
25 changes: 3 additions & 22 deletions docs/api/python/relay/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,13 @@
under the License.
tvm.relay
=========

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

analysis
backend
frontend
image
transform
nn
op
vision
testing
---------

.. automodule:: tvm.relay
:members:
:imported-members:
:exclude-members: RelayExpr, Pass, PassInfo, function_pass, PassContext,
ModulePass, FunctionPass, Sequential, module_pass, Type, TypeKind,
:exclude-members: RelayExpr,
Type, TypeKind,
TypeVar, GlobalTypeVar, TypeConstraint, FuncType, TupleType, IncompleteType,
TypeCall, TypeRelation, TensorType, RelayRefType, GlobalVar, SourceName,
Span, Var, Op, Constructor
Expand Down
4 changes: 2 additions & 2 deletions docs/api/python/relay/nn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
tvm.relay.nn
------------
.. automodule:: tvm.relay.op.nn.nn
.. automodule:: tvm.relay.nn
:members:
:imported-members:
:exclude-members:
:autosummary:
24 changes: 0 additions & 24 deletions docs/api/python/relay/op.rst

This file was deleted.

32 changes: 31 additions & 1 deletion docs/api/python/relay/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,34 @@
tvm.relay.testing
-----------------

.. autoclass:: tvm.relay.testing.resnet
.. automodule:: tvm.relay.testing
:members:
:imported-members:
:autosummary:

.. automodule:: tvm.relay.testing.mlp
:members:

.. automodule:: tvm.relay.testing.resnet
:members:

.. automodule:: tvm.relay.testing.dcgan
:members:

.. automodule:: tvm.relay.testing.mobilenet
:members:

.. automodule:: tvm.relay.testing.lstm
:members:

.. automodule:: tvm.relay.testing.inception_v3
:members:

.. automodule:: tvm.relay.testing.squeezenet
:members:

.. automodule:: tvm.relay.testing.vgg
:members:

.. automodule:: tvm.relay.testing.densenet
:members:
1 change: 0 additions & 1 deletion docs/api/python/relay/transform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ tvm.relay.transform
.. automodule:: tvm.relay.transform
:members:
:imported-members:
:exclude-members: Object
:autosummary:
2 changes: 1 addition & 1 deletion docs/api/python/relay/vision.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
tvm.relay.vision
----------------

.. automodule:: tvm.relay.op.vision
.. automodule:: tvm.relay.vision
:members:
:imported-members:
:autosummary:
3 changes: 1 addition & 2 deletions python/tvm/relay/op/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
# under the License.
# pylint: disable=wildcard-import
"""Image network related operators."""
from __future__ import absolute_import as _abs
from .image import *
from ._image import *
from . import _image
1 change: 0 additions & 1 deletion python/tvm/relay/op/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.
"""Image operations."""
from __future__ import absolute_import as _abs
from . import _make

def resize(data,
Expand Down
11 changes: 6 additions & 5 deletions python/tvm/relay/op/nn/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# under the License.
#pylint: disable=invalid-name, too-many-lines
"""Neural network operations."""
from __future__ import absolute_import as _abs
from ...expr import TupleWrapper
from tvm.relay import expr

from . import _make
from .util import get_pad_tuple2d, get_pad_tuple3d

Expand Down Expand Up @@ -1457,7 +1457,7 @@ def dropout(data, rate=0.5):
result : tvm.relay.Expr
The result of dropout
"""
return TupleWrapper(dropout_raw(data, rate), 2)[0]
return expr.TupleWrapper(dropout_raw(data, rate), 2)[0]


def dropout_raw(data, rate=0.5):
Expand Down Expand Up @@ -1580,7 +1580,7 @@ def batch_norm(data,
epsilon,
center,
scale)
return TupleWrapper(result, 3)
return expr.TupleWrapper(result, 3)


def instance_norm(data,
Expand Down Expand Up @@ -1791,7 +1791,8 @@ def sparse_transpose(x):
Tuple of output sparse tensor (same shape and format as input),
i.e. if CSR then output is in ([data, indices, indptr]) form
"""
return TupleWrapper(_make.sparse_transpose(x.data, x.indices, x.indptr), 3)
return expr.TupleWrapper(
_make.sparse_transpose(x.data, x.indices, x.indptr), 3)

def contrib_conv2d_winograd_without_weight_transform(data,
weight,
Expand Down
10 changes: 6 additions & 4 deletions python/tvm/relay/op/vision/multibox.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
# specific language governing permissions and limitations
# under the License.
"""Multibox operations."""
from tvm.relay import expr
from . import _make
from ...expr import TupleWrapper


def multibox_prior(data,
sizes=(1.0,),
Expand Down Expand Up @@ -86,6 +87,7 @@ def multibox_transform_loc(cls_prob,
-------
ret : tuple of tvm.relay.Expr
"""
return TupleWrapper(_make.multibox_transform_loc(cls_prob, loc_pred,
anchor, clip, threshold,
variances), 2)
return expr.TupleWrapper(
_make.multibox_transform_loc(cls_prob, loc_pred,
anchor, clip, threshold,
variances), 2)
8 changes: 5 additions & 3 deletions python/tvm/relay/op/vision/nms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
# specific language governing permissions and limitations
# under the License.
"""Non-maximum suppression operations."""
from tvm.relay import expr
from . import _make
from ...expr import TupleWrapper


def get_valid_counts(data,
score_threshold,
Expand Down Expand Up @@ -47,8 +48,9 @@ def get_valid_counts(data,
out_tensor : relay.Expr
Rearranged data tensor.
"""
return TupleWrapper(_make.get_valid_counts(data, score_threshold,
id_index, score_index), 2)
return expr.TupleWrapper(
_make.get_valid_counts(data, score_threshold,
id_index, score_index), 2)


def non_max_suppression(data,
Expand Down
6 changes: 2 additions & 4 deletions python/tvm/relay/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
from tvm import te
import tvm.relay as relay
import tvm.relay.op as op
from tvm.relay import transform
from tvm.relay import Function, GlobalVar, ScopeBuilder, Tuple, TupleGetItem, create_executor
from tvm.relay import TensorType, TupleType


from . import mlp
from . import resnet
Expand Down Expand Up @@ -55,7 +53,7 @@ def run_opt_pass(expr, opt_pass):


def run_infer_type(expr):
return run_opt_pass(expr, transform.InferType())
return run_opt_pass(expr, relay.transform.InferType())


def _np_randn_from_type(t, scale=1, mean=0):
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/relay/testing/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def add_nat_definitions(prelude):
"""Given a Relay prelude, adds a Peano nat ADT, as well as functions
for adding nats and doubling nats. It also adds versions of
update, nth, and iterate that take nats instead of scalars (the
names are prefixed with 'nat_')."""
names are prefixed with `nat_`)."""
define_nat_adt(prelude)
define_nat_double(prelude)
define_nat_add(prelude)
Expand Down

0 comments on commit a77b429

Please sign in to comment.