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

[TVMScript] Doc Base Class & DocPrinter Scaffolding #11971

Merged
merged 27 commits into from
Jul 7, 2022

Conversation

yelite
Copy link
Contributor

@yelite yelite commented Jun 30, 2022

This PR addes:

  • Doc base class
  • DocPrinter base class
  • PythonDocPrinter
  • LiteralDoc and its support in DocPrinter

Tracking issue: #11912

cc @junrushao1994 @gbonik

@github-actions github-actions bot requested a review from junrushao June 30, 2022 18:31
@junrushao junrushao changed the title [TVMScript Unified Printer] Base doc and doc printer with LiteralDoc support [TVMScript] Doc Base Class & DocPrinter Scaffolding Jun 30, 2022
Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! My comments are mainly about:

  • API consideration
  • Code fragmentation
  • nitpicks

include/tvm/script/printer/doc.h Outdated Show resolved Hide resolved
include/tvm/script/printer/doc.h Show resolved Hide resolved
include/tvm/script/printer/doc.h Outdated Show resolved Hide resolved
python/tvm/script/printer/doc.py Outdated Show resolved Hide resolved
src/script/printer/doc.cc Outdated Show resolved Hide resolved
src/script/printer/python_doc_printer.cc Outdated Show resolved Hide resolved
include/tvm/script/printer/doc.h Show resolved Hide resolved
src/script/printer/python_doc_printer.cc Outdated Show resolved Hide resolved
src/script/printer/python_doc_printer.cc Outdated Show resolved Hide resolved
Comment on lines 92 to 96
std::unique_ptr<DocPrinter> GetPythonDocPrinter(const DocPrinterOptions& options) {
return std::make_unique<PythonDocPrinter>(options);
}

TVM_REGISTER_GLOBAL("script.printer.PrintDocAsPython")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think about API consistency between python and c++: if a public API exists in c++, then it should exist also in python, and vice versa. This is a strict standard in non-legacy TVM codebase (e.g. TIR scheduling, MetaSchedule)

In our particular case, I would propose:

  • renaming from the PrintDocAsPython, use DocToScriptPython as the public C++ / python API
  • GetPythonDocPrinter is Relatively not super useful (only used by the entry function of TVMScript printer) and there is no actual need to expose it in any header file (correct me if I was wrong)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These suggestions sound good to me. I made the following change:

  1. Expose a DocToPythonScript function in the public C++/Python API (I swapped 'Python' and 'Script' to make this sound more natural IMO. Let me know if you want to use the original name you suggested in the comment)
  2. Hide the base DocPrinter to a private header (as is in the previous version of code, just state here for clarity)
  3. Remove GetPythonDocPrinter

(LiteralDoc('""'), r'"\"\""'),
(LiteralDoc("\n\t\\test\r"), r'"\n\t\\test\r"'),
# TODO: make the roundatrippable problem caused by utf8
pytest.param(LiteralDoc("\x88"), r'"\x88"', marks=pytest.mark.xfail),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick question: why are these marked as xfail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were three xfail tests here. I removed the latter two about float number per our discussion yesterday (we want to handle float number precise printing in the IRDocsifier).

This one (on line 45) is about the utf8 encoding. LiteralDoc("\x88") will print '\xc2\x88' (the utf8 encoded bytes for "\x88"). This is not roundtrippable.

To fix this, we need to either:

  1. Add utf8 decoding to StrEscape
  2. Output in the form of b'\xC2\x88'.encode()'

I don't think unicode support is important to our use case and it doesn't help us reach feature parity with the old printer at all. So I don't want to solve it for now, but just leave an xfail test as a note

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation!

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I believe this PR has been in a good state. I have some latest nitpicks but nothing else

@junrushao junrushao merged commit 9f4bf38 into apache:main Jul 7, 2022
blackkker pushed a commit to blackkker/tvm that referenced this pull request Jul 7, 2022
This PR addes:
- Doc base class
- DocPrinter base class
- PythonDocPrinter
- LiteralDoc and its support in DocPrinter

Tracking issue: apache#11912
masahi pushed a commit to masahi/tvm that referenced this pull request Jul 15, 2022
This PR addes:
- Doc base class
- DocPrinter base class
- PythonDocPrinter
- LiteralDoc and its support in DocPrinter

Tracking issue: apache#11912
mikeseven pushed a commit to mikeseven/tvm that referenced this pull request Sep 27, 2023
This PR addes:
- Doc base class
- DocPrinter base class
- PythonDocPrinter
- LiteralDoc and its support in DocPrinter

Tracking issue: apache#11912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants