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][RFC] Modify repr to return a valid Python AST #2631

Closed
jroesch opened this issue Feb 20, 2019 · 5 comments
Closed

[RELAY][RFC] Modify repr to return a valid Python AST #2631

jroesch opened this issue Feb 20, 2019 · 5 comments

Comments

@jroesch
Copy link
Member

jroesch commented Feb 20, 2019

I think we should update repr and by extension the debug printing methods defined in C++ to update a valid Python AST. This would make it possible for us to extract the debug representation when printing it and paste it into a Python file to edit and modify.

I think this will be very useful for experimenting and debugging.

cc @joshpoll @wweic @tqchen @MarisaKirisame

@tqchen
Copy link
Member

tqchen commented Feb 20, 2019

@jroesch can you elaborate and give an example?

@jroesch
Copy link
Member Author

jroesch commented Feb 21, 2019

My goal is to obtain a program fragment like:

Function(
  params=[Var("x", type_annotation=TensorType([10, 10], float32))], 
  ret_type=TensorType([10, 10], float32), 
  body=Call(relay.op.get("add"), ...),
 ...)

Instead of:

FunctionNode([Var(x, ty=TensorType([10, 10], float32))], TensorType([10, 10], float32), CallNode(Op(add), [Var(x, ty=TensorType([10, 10], float32)), Var(x, ty=TensorType([10, 10], float32))], (nullptr), [TensorType([10, 10], float32), TensorType([10, 10], float32)]), [], (nullptr))

Upon further reflection we could just do this in Python, though there are some challenges due to our name representation.

My main goal is that we could obtain textual representation of the program which can be copy-and pasted back into the interpreter along the idea presented by the pprint module (https://docs.python.org/3.7/library/pprint.html).

My inspiration is that I was writing tests and debugging some transformations and it would be nice to be able to easily manually edit the AST to observe changes instead of having to write a Relay program to do so.

@joshpoll
Copy link
Contributor

Do you think it's worth integrating this code with the text printer? We could e.g. reuse the Doc ADT in #2605.

@wweic
Copy link
Contributor

wweic commented Feb 21, 2019

+1. It would be very useful to have program == eval(program.repr())

@tqchen
Copy link
Member

tqchen commented Feb 8, 2020

close due to inactive status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants