From a651e8676ba1f3faad76b73dbf70db9a231ad69c Mon Sep 17 00:00:00 2001 From: Zhi <5145158+zhiics@users.noreply.github.com> Date: Tue, 13 Aug 2019 15:23:50 -0700 Subject: [PATCH] fix some pass docs (#3767) --- docs/api/python/relay/ir_pass.rst | 21 ------------ docs/api/python/relay/transform.rst | 44 +++++++++++++++++++++++++ docs/dev/index.rst | 6 ++-- python/tvm/relay/transform.py | 51 ++++++++--------------------- src/relay/pass/type_infer.cc | 3 -- 5 files changed, 62 insertions(+), 63 deletions(-) delete mode 100644 docs/api/python/relay/ir_pass.rst diff --git a/docs/api/python/relay/ir_pass.rst b/docs/api/python/relay/ir_pass.rst deleted file mode 100644 index 0102ee9e6119..000000000000 --- a/docs/api/python/relay/ir_pass.rst +++ /dev/null @@ -1,21 +0,0 @@ -.. Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - -.. http://www.apache.org/licenses/LICENSE-2.0 - -.. Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - -tvm.relay.ir_pass ------------------ -.. automodule:: tvm.relay.ir_pass - :members: \ No newline at end of file diff --git a/docs/api/python/relay/transform.rst b/docs/api/python/relay/transform.rst index 4eb7f9d8fea7..3c0a6dcf22f6 100644 --- a/docs/api/python/relay/transform.rst +++ b/docs/api/python/relay/transform.rst @@ -26,6 +26,50 @@ tvm.relay.transform .. autofunction:: tvm.relay.transform.function_pass +.. autofunction:: tvm.relay.transform.InferType + +.. autofunction:: tvm.relay.transform.FoldScaleAxis + +.. autofunction:: tvm.relay.transform.BackwardFoldScaleAxis + +.. autofunction:: tvm.relay.transform.ForwardFoldScaleAxis + +.. autofunction:: tvm.relay.transform.SimplifyInference + +.. autofunction:: tvm.relay.transform.CanonicalizeOps + +.. autofunction:: tvm.relay.transform.DeadCodeElimination + +.. autofunction:: tvm.relay.transform.FoldConstant + +.. autofunction:: tvm.relay.transform.FuseOps + +.. autofunction:: tvm.relay.transform.CombineParallelConv2D + +.. autofunction:: tvm.relay.transform.AlterOpLayout + +.. autofunction:: tvm.relay.transform.Legalize + +.. autofunction:: tvm.relay.transform.RewriteAnnotatedOps + +.. autofunction:: tvm.relay.transform.ToANormalForm + +.. autofunction:: tvm.relay.transform.ToCPS + +.. autofunction:: tvm.relay.transform.EtaExpand + +.. autofunction:: tvm.relay.transform.ToGraphNormalForm + +.. autofunction:: tvm.relay.transform.EliminateCommonSubexpr + +.. autofunction:: tvm.relay.transform.PartialEvaluate + +.. autofunction:: tvm.relay.transform.CanonicalizeCast + +.. autofunction:: tvm.relay.transform.LambdaLift + +.. autofunction:: tvm.relay.transform.PrintIR + .. autoclass:: tvm.relay.transform.Pass :members: diff --git a/docs/dev/index.rst b/docs/dev/index.rst index b5818277ca1e..fad9852ede75 100644 --- a/docs/dev/index.rst +++ b/docs/dev/index.rst @@ -26,11 +26,13 @@ In this part of documentation, we share the rationale for the specific choices m runtime debugger - nnvm_json_spec - nnvm_overview hybrid_script relay_intro relay_add_op + relay_pass_infra relay_add_pass + virtual_machine codebase_walkthrough inferbound + nnvm_json_spec + nnvm_overview diff --git a/python/tvm/relay/transform.py b/python/tvm/relay/transform.py index 46543afb6693..ccdf00ed64e3 100644 --- a/python/tvm/relay/transform.py +++ b/python/tvm/relay/transform.py @@ -32,7 +32,7 @@ @register_relay_node class PassInfo(RelayNode): - """The class that contains the meta data required by a pass. It is the + """The class contains the meta data required by a pass. It is the container of information needed by running an optimization or analysis. This class can be extended by adding new members when more meta data is needed. @@ -132,11 +132,12 @@ def build_config(opt_level=2, "SimplifyInference": 0, "OpFusion": 1, "FoldConstant": 2, - "CombineParallelConv2D": 3, "FoldScaleAxis": 3, "AlterOpLayout": 3, "CanonicalizeOps": 3, + "CanonicalizeCast": 3, "EliminateCommonSubexpr": 3, + "CombineParallelConv2D": 4, } fallback_device : int, str, or tvm.TVMContext, optional @@ -250,30 +251,6 @@ def __init__(self, passes, opt_level, name, required) -def infer_type(expr, mod=None): - """Infer the type of an expr. - Adding Function into a Module will change it's binding, - and some passes need type inference to work without binding modification. - However, InferType() work by putting stuff into a Module, thus changing all the binding. - - This is an escape patch that allow type inference without binding changing. - - Parameters - ---------- - expr : tvm.relay.Expr - The input expression. - - mod : Optional[tvm.relay.Module] - The input module - - Returns - ------- - ret : tvm.relay.Expr - The output expression. - """ - return _transform.infer_type(expr, mod) - - def InferType(): """Infer the type of an expr. @@ -297,7 +274,7 @@ def FoldScaleAxis(): Note ---- Internally, we will call backward_fold_scale_axis before using - forward_fold_scale_axis. As backward folding targets common conv-bn + forward_fold_scale_axis as backward folding targets the common conv->bn pattern. """ return _transform.FoldScaleAxis() @@ -314,8 +291,8 @@ def BackwardFoldScaleAxis(): Note ---- It is recommended to call backward_fold_scale_axis - before using forward_fold_scale_axis. - As backward folding targets common conv-bn pattern. + before using forward_fold_scale_axis as backward folding targets the common + conv->bn pattern. """ return _transform.BackwardFoldScaleAxis() @@ -331,8 +308,8 @@ def ForwardFoldScaleAxis(): Note ---- It is recommended to call backward_fold_scale_axis - before using forward_fold_scale_axis. - As backward folding targets common conv-bn pattern. + before using forward_fold_scale_axis, as backward folding targets the + common conv->bn pattern. """ return _transform.ForwardFoldScaleAxis() @@ -350,9 +327,9 @@ def SimplifyInference(): def CanonicalizeOps(): - """ Canonicalize special operators to basic operators. - This can simplify followed analysis. (e.g. expanding bias_add to - expand_dims and broadcast_add.) + """Canonicalize special operators to basic operators. + This can simplify followed analysis, e.g. expanding bias_add to + expand_dims and broadcast_add. Returns ------- @@ -363,7 +340,7 @@ def CanonicalizeOps(): def DeadCodeElimination(inline_once=False): - """Remove expressions which does not effect the program result (dead code). + """Remove expressions that do not have any users (dead code). Parameters ---------- @@ -379,7 +356,7 @@ def DeadCodeElimination(inline_once=False): def FoldConstant(): - """Fold the constant expression in expr. + """Fold the constant expressions in a Relay program. Returns ------- @@ -513,7 +490,7 @@ def EtaExpand(): def ToGraphNormalForm(): - """Turn A Normal Form expression into Graph Normal Form expression + """Turn a Relay program in A Normal Form into Graph Normal Form Returns ------- diff --git a/src/relay/pass/type_infer.cc b/src/relay/pass/type_infer.cc index ea59c5dc32ae..1d10651f5c27 100644 --- a/src/relay/pass/type_infer.cc +++ b/src/relay/pass/type_infer.cc @@ -826,9 +826,6 @@ Function InferType(const Function& func, return Downcast(func_ret); } -TVM_REGISTER_API("relay._transform.infer_type") -.set_body_typed([](Expr l, Module r) { return InferType(l, r); }); - namespace transform { Pass InferType() {