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][PASS] Bind, FoldConstant #2100

Merged
merged 2 commits into from
Nov 14, 2018
Merged

[RELAY][PASS] Bind, FoldConstant #2100

merged 2 commits into from
Nov 14, 2018

Conversation

tqchen
Copy link
Member

@tqchen tqchen commented Nov 14, 2018

  • Refactor type_subt->Bind(overloaded name) and move to type_functor.cc
  • Add support of Bind which bind params(free vars) to certain expression
    • This is useful to bind parameters as a constant into the IR during inference.
  • Support FoldConstant
    • This is useful for folding contents that can be pre-computed, in nnvmv1 it was called precompute_prune.
  • Support constant node in graph runtime backend.
    • constants will be generated as params dict.

The general flow now becomes:

  • bind params into IR as constant
  • Run optimizations, including constant folding
  • In graph runtime codegen, the constants nodes are then lifted out as params

@tqchen
Copy link
Member Author

tqchen commented Nov 14, 2018

@@ -324,7 +329,7 @@ def codegen(self, func):
self.heads = self.visit(func.body)
graph_json = self._get_json()
lowered_funcs = list(self.lowered_funcs)
return graph_json, lowered_funcs
return graph_json, lowered_funcs, self.params
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add returns in pydoc above

"""Perform target invariant optimizations.

Parameters
----------
func : tvm.relay.Function
The input to optimization.

params : dict of str to NDArray
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional[Dict[str, NDArray]]

@MarisaKirisame
Copy link
Contributor

I did a quick pass of the code, LGTM
one major issue with all the pass(not just this one, but dead code elim too) we write is they do not respect effect or recursion, and we have to have them respect it. I think we can talk about this issue in PLDI.

@tqchen
Copy link
Member Author

tqchen commented Nov 14, 2018

The side effect is checked by is_stateful, I think the folding pass should work with functions of recursion, by ignoring recursive calls. But indeed they don't unroll the recursion if that is what you mean

@MarisaKirisame
Copy link
Contributor

@tqchen tuplegetitem(tuplenode(...)) will just take the expr
but if some expr in tuplenode went into infinite recursion, or has effect, it will change the behavior of the program

@tqchen
Copy link
Member Author

tqchen commented Nov 14, 2018

I see, indeed, we will need side effect check pass and possibly combine dead code elim into folding. For now it is fine as the program is side-effect free

@jroesch
Copy link
Member

jroesch commented Nov 14, 2018

Looks good to me we can follow up on those issues afterwards.

@tqchen tqchen merged commit b252160 into apache:master Nov 14, 2018
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
@ZihengJiang ZihengJiang mentioned this pull request Feb 1, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants