-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Graph memory plan] Support nested tuples #6809
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
Conversation
bf5f22e to
3fadfe2
Compare
| auto tok = GetToken(field); | ||
| ICHECK_EQ(tok.size(), 1U); | ||
| fields.push_back(tok[0]); | ||
| auto tokens = GetToken(field); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle 2 levels of nesting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, there is VisitExpr(field) inside GetToken, where nesting is recursively visited and token generated for each tensor in the nest.
| x1 = x + relay.const(1.0) | ||
| x2 = x1 + relay.const(1.0) | ||
| x3 = x2 + relay.const(1.0) | ||
| out = relay.Tuple([x1, relay.Tuple([x2, x3])]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example what if x2 is also a tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just updated this test to verify two level nesting works.
3fadfe2 to
208cfc5
Compare
mbaret
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change lgtm, but I have a question relating to the original discuss post. I've been looking at the compile_engine recently and noticed a number of TODOs there with the comment 'Allow recursive tuple', see for instance: https://github.com/apache/incubator-tvm/blob/3222cad9464cadafcab29dbfb5cf149bf083913f/src/relay/backend/compile_engine.cc#L118
It also seems to me that there's logic in graph_runtime_codegen.cc that flattens tuples assuming they're not recursive. Therefore, I'm a bit surprised it was only graph_plan_memory that was blocking you.
|
@mbaret yes, so this patch suffices for my simple use case of returning nested tuples from the For example, I've just tried compiling this graph containing a sub function with nested tuple output, and it doesn't compile. I'll work on the fix, that should enable removing the tuple flatting in the BYOC partitioning pass @manupa-arm
Those TODOs look unrelated to graph memory planning. They refer to |
208cfc5 to
d384062
Compare
|
@tqchen @zhiics @jroesch @mbaret Supporting nested tuples in Maybe it would help BYOC use cases, but otherwise I don't know if we want to support this in practice. So I'm happy to revert that change and only support returning nested tuples from |
|
I am actually okay without the new change |
|
I'm fine to leave the further changes out of this PR (especially as it's titled with graph plan memory). If it looks more complicated, that may need to be the subject of an RFC. |
72b9564 to
b139231
Compare
|
ok reverted |
b139231 to
2171fac
Compare
* add test * test working * uncomment other tests * remove redundant visit * test double nesting * support nested tuple in CallNode's return type * Revert "support nested tuple in CallNode's return type" This reverts commit 66225ed.
* add test * test working * uncomment other tests * remove redundant visit * test double nesting * support nested tuple in CallNode's return type * Revert "support nested tuple in CallNode's return type" This reverts commit 66225ed.
* add test * test working * uncomment other tests * remove redundant visit * test double nesting * support nested tuple in CallNode's return type * Revert "support nested tuple in CallNode's return type" This reverts commit 66225ed.
The fix for the issue https://discuss.tvm.apache.org/t/graph-plan-memory-doesnt-support-nested-tuples/8278
A token is created for each tensor in a nested tuple. Graph runtime doesn't deal with tuples, so nested tuples are all flattened (
runtime.get_num_outputs()andruntime.get_output(i)don't take tuples or nesting into account).please review @tqchen @zhiics (cc @mbaret @manupa-arm )
I didn't look into memory planning in detail, but I hope this is correct.