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] Only allow Module -> Module for opts managed by pass infra #3430

Merged
merged 2 commits into from
Jul 1, 2019

Conversation

zhiics
Copy link
Member

@zhiics zhiics commented Jun 25, 2019

This PR moves some passes from to the pass manager. The summary of the changes:

  • to a normal form implicitly modifies the module but only returns an updated expr. This may cause problems since some updated functions in the module might be lost. I changed to it a module pass that returns a module to avoid losing information.

  • Some unit tests in DCE don't have typing info. We can run Expr -> Expr opts on this them without types. However, as relay is strongly typed (at least everything in a module should be strongly typed), this PR adds types to them.

  • Partial Evaluation seems to need some more work for moving into the pass infra. I think it should be a module pass because it could evaluate the functions and then apply DCE to delete some of the dead ones. It looks to me we might need a global DCE pass to work on the module level and be able to delete functions. Otherwise, we might need to rely on inlining and outlining.

cc @jroesch @tqchen @MarisaKirisame @wweic @icemelon9 @slyubomirsky

@zhiics zhiics force-pushed the only_module branch 2 times, most recently from e9494d0 to 2624da0 Compare June 25, 2019 08:14
raise TypeError("Unknow mode: {}".format(mode))


def OptimizeOnExpr(expr, passes):
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be a function instead of a class style pass constructor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I was using this just to keep it like an optimization as the other ones.

@MarisaKirisame
Copy link
Contributor

for the ANF pass, the 'implicit update' is needed to traverse every global var used. however, with function module, this is not needed anymore. maybe you can remove the implicit update of the code?

for PE, I think it should be a Mod -> Mod at the impl level, and I will fix it.

@MarisaKirisame
Copy link
Contributor

@zhiics can you not pass 'higher_order' rn? There isnt much case where the other mode is supported, and I personally think it should be deprecated, or at least, it should only be for expert who know what they are doing.
Also, what do you mean by AD dont support polymorphism? can you give me the error?

@zhiics zhiics force-pushed the only_module branch 2 times, most recently from 8621b9e to 3c4714a Compare June 28, 2019 04:44
@zhiics
Copy link
Member Author

zhiics commented Jun 28, 2019

@MarisaKirisame I tried to fix to ANF and PE in the commit. You can probably take a look.

For higher_order, I just kept it the same as what we had before. I can remove it later.
For the AD error, it is produced in the test_pow, you can probably check out and test it.

@MarisaKirisame
Copy link
Contributor

MarisaKirisame commented Jun 28, 2019

after some thinking, phasing AD as a pass is really bad.
AD do not preserve the semantic, and it do not preserve the type. It is not something u can just call - in this sense it is closer to freevars then to a pass.
Making it a pass just give people footgun to shoot themselves. (for example, ppl might pass a module into the AD pass, and transform all function to the AD mode).
but this is not how it is supposed to be use at all! It will probably just fail to type check, but for now, IMO it is best to make it just a standalone function, while I work on training and figure out how to make it part of our story.

can you revert this change? thank you.

@zhiics
Copy link
Member Author

zhiics commented Jun 28, 2019

@MarisaKirisame Okay. I will revert the gradient pass. Later, we will have an analysis file and put the analysis passes there.

@MarisaKirisame
Copy link
Contributor

MarisaKirisame commented Jun 28, 2019

@zhiics i agree. Thx.

@zhiics
Copy link
Member Author

zhiics commented Jun 28, 2019

@MarisaKirisame reverted

@tqchen
Copy link
Member

tqchen commented Jun 28, 2019

Re: AD as a Pass. I still think it should be Module->Module, we just need to debate about the APIs.
For example, the AD pass could take arguments of the name of interest("main") and differentiate that function, produce another function "main_diff" and related function if necessary.

@MarisaKirisame
Copy link
Contributor

MarisaKirisame commented Jun 28, 2019

@tqchen this is a reasonable design, however there are other ways to do this, and I am thinking of doing a redesign/re-implementation of the AD. I feel like it could be delayed a bit.

Regardless, having it as FunctionPass seems like the wrong design.

@tqchen
Copy link
Member

tqchen commented Jun 28, 2019

The main motivation is that we want to consolidate everything under Module->Module. If @MarisaKirisame you can quickly come up with a Module->Module style API proposal, I recommend we do so, given that it won't affect implementation as much.

@zhiics
Copy link
Member Author

zhiics commented Jun 28, 2019

Yes, name of interest looks like a plausible way. I will keep this pass not touched in this PR.

@jroesch
Copy link
Member

jroesch commented Jul 1, 2019

Re: AD we should add a special relay.grad operator, which attributes configure the AD pass. When we run the pass we will expand all static grad calls into their AD code.

@jroesch jroesch merged commit f2a6851 into apache:master Jul 1, 2019
@zhiics zhiics deleted the only_module branch July 2, 2019 21:49
wweic pushed a commit to wweic/tvm that referenced this pull request Jul 11, 2019
…fra (apache#3430)

* [Relay][Pass] Only allow Module -> Module for opts managed by pass infra

* revert gradient pass
wweic pushed a commit to wweic/tvm that referenced this pull request Jul 11, 2019
…fra (apache#3430)

* [Relay][Pass] Only allow Module -> Module for opts managed by pass infra

* revert gradient pass
wweic pushed a commit to neo-ai/tvm that referenced this pull request Jul 11, 2019
…fra (apache#3430)

* [Relay][Pass] Only allow Module -> Module for opts managed by pass infra

* revert gradient pass
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.

5 participants