[Relay] parser/pretty printer roundtripping #3536
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR add support for roundtripping relay code from/to string.
Right now, it support roundtripping all the defined network, and I think this is a good time to wrap up and merge.
A few things to discuss:
Doc does not accept string input with newline/tab any more, as it will interfere with the layout algorithm that will land in the future.
The printing strategy is ugly for anfed code. It will print a variable, then graph that variable.
Similarly, there should be inline ability for simple expression such as a + b + c, instead of always allocate graph var.
FuncOp is highly redundant. Can we get this information with tvm?
I copied the josn pretty printer so it use Doc Style.
since ppl do assert alpha_equal all the time, I build it into alpha_equal to give better error message.
Future Work:
0: pattern matching/adt/fatal/ref for both pretty printing/parser
1: doc.h do not have a layout engine - right now it will emit the same string regardless of screen width/remaining space
2: indentation is off - nested let look incredibly broken
3: every tree - style program will still make a graph var for everything, so it is impossible to display code that resemble sml
4: deprecate the old json pretty printer?
5: src/error.cc often do not display error message for unknown reason
6: more principle solution for dealing with literal
7: to do attrs in alphaequal extensibly
8: handle floating point equality
Tired and Sleepy. M.K. out.