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] Continuation Passing Style #3456

Merged
merged 8 commits into from
Jul 3, 2019
Merged

Conversation

MarisaKirisame
Copy link
Contributor

@MarisaKirisame MarisaKirisame commented Jun 28, 2019

The code implement a higher order continuation passing style transform in the spirit of (http://matt.might.net/articles/cps-conversion/, the higher order transform section).

This help training by helping PE which help AD.

Suppose we have some code, of the form

let a = if b then c else d in e

in the partial evaluator, if b is dynamic c and d will be partially evaluated, and their result will be thrown away, so it cannot help e.

However, if we cps the program, it will become

let f a = e in if b then f c else f d

with e inlined, and possible to do further simplification base on the partial evaluator result of c/d.
There are two big design choice this commit to:

  • polymorphic continuation because we want to type check things. this mean we move from HM to System F.
  • CPS itself. It is somewhat un-revertable, and has implication on further optimization. Some say it is good while some say it is bad.

We should discuss a bit.
@jroesch @tqchen @nhynes

@MarisaKirisame
Copy link
Contributor Author

@junrushao1994 @vinx13 I got it print what you guys want.

@MarisaKirisame MarisaKirisame changed the title [Relay] Cps [Relay] Continuation Passing Style Jun 28, 2019
@MarisaKirisame
Copy link
Contributor Author

turn out system f is not needed.

@vinx13
Copy link
Member

vinx13 commented Jun 29, 2019

Nice work! I will check if this is helpful for more complex cases of AD

@vinx13
Copy link
Member

vinx13 commented Jul 1, 2019

Is global var not yet supported?
Also it would be good to add some tests for CPS itself

@MarisaKirisame
Copy link
Contributor Author

@vinx13 it is not supported, but there is no difficulty (only that I havent write some C++).
there are integration test for CPS, and CPS is itself a bit hard to test (the property) alone, as this one does a bit of simplification to remove immediate continuation.

@MarisaKirisame MarisaKirisame force-pushed the cps branch 3 times, most recently from a7ec531 to 0d1ee5e Compare July 1, 2019 22:27
std::function<Expr()> next;
next = [&]() {
if (args.size() == op->args.size()) {
return LetList::Let(CallNode::make(op->op, args), k);
Copy link
Member

Choose a reason for hiding this comment

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

CallNode::make(op->op, args, op->attrs, op->type_args) otherwise you lose attributes

@MarisaKirisame
Copy link
Contributor Author

This is ready to review.
@zhiics I cant make UnCPS a transform as it only work on certain type.
@icemelon9 @wweic @srkreddy1238 can you guys also help review?

@tqchen
Copy link
Member

tqchen commented Jul 2, 2019

One thing @MarisaKirisame given that we are moving towards new transform.h and Module->Module, would be great to keep everything in the new style

@MarisaKirisame
Copy link
Contributor Author

@tqchen I am unable to make UnCPS into the new style as it only work on some of the function. We probably want to discuss design.

@tqchen
Copy link
Member

tqchen commented Jul 2, 2019

I think we might want to have a conversation about where should we put the remaining function->function transformations into.

add

me find type checker problem

save

save

lint

do

lint

reset ti

add some doc

add failed test case

add recursion for cps

add recursion for cps

fix pytest

lint

save

fix test error

lint

save

fix error
@vinx13 vinx13 merged commit d1eb122 into apache:master Jul 3, 2019
wweic pushed a commit to wweic/tvm that referenced this pull request Jul 11, 2019
* save

add

me find type checker problem

save

save

lint

do

lint

reset ti

add some doc

add failed test case

add recursion for cps

add recursion for cps

fix pytest

lint

save

fix test error

lint

save

fix error

* fix rebase

* fix

* fix test

* lint

* lint

* restore rewriteannotationops

* do
wweic pushed a commit to wweic/tvm that referenced this pull request Jul 11, 2019
* save

add

me find type checker problem

save

save

lint

do

lint

reset ti

add some doc

add failed test case

add recursion for cps

add recursion for cps

fix pytest

lint

save

fix test error

lint

save

fix error

* fix rebase

* fix

* fix test

* lint

* lint

* restore rewriteannotationops

* do
wweic pushed a commit to neo-ai/tvm that referenced this pull request Jul 11, 2019
* save

add

me find type checker problem

save

save

lint

do

lint

reset ti

add some doc

add failed test case

add recursion for cps

add recursion for cps

fix pytest

lint

save

fix test error

lint

save

fix error

* fix rebase

* fix

* fix test

* lint

* lint

* restore rewriteannotationops

* do
@MarisaKirisame MarisaKirisame deleted the cps branch July 13, 2019 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants