Skip to content

Commit

Permalink
more ocmments
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewZhaoLuo committed Dec 15, 2021
1 parent 247d415 commit ac1ce9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/tvm/relay/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ TVM_DLL Pass InferType();
* \brief Infer the type of an expression, reusing existing type information.
*
* The result of type checking is a new expression with unambiguous
* type information filled in for that expression only. The local
* version depends on existing type information populated throughout
* type information filled in for the given node only. The local
* version can use existing type information populated throughout
* the expression and assumes this information is correct. The local
* version also avoids examining large amounts of the graph assuming
* type information is filled in properly which makes it much faster if we
Expand Down
14 changes: 13 additions & 1 deletion src/relay/transforms/type_infer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,8 @@ class SameTypedSubgraphExtractor : public ExprMutator {
by depending on existing type information being populated in expressions the target
node depends on. If a node with populated type information is found we simply
replace it with a variable of that type. In this way, we can avoid copying and
recursing through most of the expression graph.
recursing through most of the expression graph. Note, this assumes that current
populated type information is correct!
ExprMutator is sufficient over MixedModemutator since we will not recurse much.
*/
Expand Down Expand Up @@ -899,6 +900,17 @@ class SameTypedSubgraphExtractor : public ExprMutator {
namespace transform {

Type InferTypeLocal(const Expr& expr) {
/*
This type inference differs from InferType in that it uses existing type information
to avoid recursing over much of the graph, and it only examines the type of the input
node. This makes it faster if you need to run type inference iteratively throughout
a pass for example.
However, it assumes any existing populated type inference is correct! If some populated
type inference is incorrect, an incorrect type may be returned or a type error will be
raised. If you know not all populated type fields are correct with the current graph,
you should use InferType() instead.
*/
SameTypedSubgraphExtractor subgraph_extractor;
auto mod = IRModule::FromExpr(subgraph_extractor(expr));

Expand Down

0 comments on commit ac1ce9f

Please sign in to comment.