Pretty printing of relax

PR13795 has moved a lot of the pretty printing code to the relay directory. If I understand correctly, the intent was to deprecate the existing pretty printing code, in favor of using TIRScript as the representation.

Should existing relax code (that uses the PrettyPrinter class) use the pretty printer from relay for the time being?

cc: @junrushao

1 Like

Thanks for asking! For TIR and Relax, we will always use TVMScript printer as the only source of truth, and it means ReprPrinter is always redirected to TVMScript printer, PrettyPrinter/TextPrinter and all others will be considered as legacy, but still preserves in the codebase for backward compatibility.

And the printer/parser are designed to be extensible to multi-dialects coexisting, and if one would love to develop a TVMScript printer for Relay, I’m more than happy to get it merged too :slight_smile:

1 Like

The new TVMScript printer for Relax is under rapid development. I have a couple of bugs to fix before shipping and eta is end of this week

3 Likes

That’s great news! I’ll wait for the PR with the new printer.

1 Like

The new printer is finally completed, and its rebased to the latest apache/tvm:main. I’ve passed all tests locally and staged it in the CI to ensure it doesn’t do any abruption.

Branch: Commits · tlc-pack/relax · GitHub

If everything goes smoothly, it will be on mainline in tlc-pack/tvm:relax tomorrow.

3 Likes

@kparzysz @masahi

The printer is landed via this PR: https://github.com/tlc-pack/relax/pull/416.

From now on, for either TIR or Relax, the recommended way of printing is:

C++:

std::cout << AnIRNode; // ReprPrinter has been redirected to use TVMScript
std::cout << AnIRNode->script(...); // for customization

Python:

print(an_ir_node) # __str__ and __repr__ are using ReprPrinter
print(an_ir_node.script(...)) # for customization
an_ir_node.show(...) # for customization + syntax highlighting
4 Likes