Skip to content
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

[Relay] Escape Patch that allow type inference to work without changing binding. #3571

Merged
merged 1 commit into from
Jul 24, 2019
Merged
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
24 changes: 24 additions & 0 deletions python/tvm/relay/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,30 @@ 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.

Expand Down
3 changes: 3 additions & 0 deletions src/relay/pass/type_infer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,9 @@ Function InferType(const Function& func,
return Downcast<Function>(func_ret);
}

TVM_REGISTER_API("relay._transform.infer_type")
.set_body_typed<Expr(Expr, Module)>([](Expr l, Module r) { return InferType(l, r); });

namespace transform {

Pass InferType() {
Expand Down