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
@jroesch can you elaborate and give an example?
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.
Do you think it's worth integrating this code with the text printer? We could e.g. reuse the Doc ADT in #2605.
+1. It would be very useful to have program == eval(program.repr())
close due to inactive status
Most helpful comment
My goal is to obtain a program fragment like:
Instead of:
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
pprintmodule (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.