-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[UX] highlight tvm script #12197
[UX] highlight tvm script #12197
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ganler, LGTM!
@tkonolige Thanks for the suggestions. To put some background: The reason why I use these magic RGB values is to match exact themes in jupyter notebook (or vscode) so they will look compatible. In jupyter notebook, the colors will be displayed as what the RGB values exactly are since it uses HTML to render things. While for terminals, I guess it will map things to nearest 3/4/8-bit colors. That said I fully agree that we want the theme look compatible for both notebook users and terminal users. My proposal is to: 1) first set them as different theme styles (including the theme you suggested that we have 3 tvm-builtin themes where 2 for jupyter notebook environemnts and 1 for terminal env); 2) we set the default style to a magic string, say "auto", and then we detect if the user is doing experiements in a notebook (if notebook -> "light"; if terminal -> ansi colors). |
@ganler thanks for this PR! would be great to add highlighting to TVMScript. on the python deps: unfortunately we're still working through a PR to generate a virtualenv from gen_requirements.txt, so you'll also need to add it to regarding the actual PR, some thoughts: in general it'd be good to avoid adding dependencies to the TVM core unless they're clearly beneficial to a large set of code paths. the approach here seems to be to lex the stringified TVMScript and then highlight based on tokens. I wonder if it would be possible to instead modify the TVMScript printer? The benefit of doing this is that then, you could automatically determine whether you wanted to highlight TVMScript by checking whether it was being |
cc @yelite @junrushao1994 who might have ideas whether the printer should handle this |
Thanks @areusch for the suggestions! I agree that we want to avoid dependencies if possible. As you said, one way is to implement the functionality from scratch.
It is possible with some effort to build a highlighting functionality from scratch: 1) lexer (*); 2) generating ansi escape code; and 3) make things configurable. *With a lexer, we can decouple things as directly modifying tvm/src/printer/tvmscript_printer.cc Line 883 in 4a94a94
Agreed. I think we should not put this under "core". Meanwhile, "Pygments" is actually a very fundamental and reliable library in Python community that has been actively developed for years. For example, latest pypi can use Summing up the bits above, I suggest that we still use Pygments to hightlight TVM script but we don't put it as a required dependency. Instead we can put some log to suggest users to install "Pygments" if they have not done it so far or simply put it in |
I think it's reasonable to let 3rd party library to handle the highlighting. It will take non-trivial effort to implement highlight in the TVMScript printer by ourselves. This also applies to other nice-to-have features like code formatting. Users might want the printed TVMScript to be free from very long lines and we can use black to format the output. IMO all those extra dependencies should be optional and the |
… ansi colors as default terminal style
Some updates: Drop "core" dep, fallback as plain text and warn thanks to @yidawang and @areusch If Pygments is not installed, we print plain text and post a warning: ANSI colors for terminal users thanks to @tkonolige If the environment is not notebook (i.e., terminal or something), we use a style filled with ansi colors (the colors are tuned to close to the default theme of notebook). Dark (iterm2): Light (macOS terminal): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Following apache#12197, this PR introduces `Schedue.show()` which convenience the user experience in the following two aspects: - Python syntax highlighting - Outputs a schedule function instead of standalone instructions so that it's easier to follow. To demonstrate this change: - Before ``Schedule.show()` is introduced: <img width="555" alt="image" src="https://user-images.githubusercontent.com/22515877/185713487-03722566-1df7-45c7-a034-c1460d399681.png"> - After this change: <img width="583" alt="image" src="https://user-images.githubusercontent.com/22515877/185713564-c54f3a9d-cd52-4709-a8b8-d8a61361e611.png">
Following apache#12197, this PR introduces `Schedule.show()` which convenience the user experience in the following two aspects: - Python syntax highlighting - Outputs a schedule function instead of standalone instructions so that it's easier to follow. To demonstrate this change: - Before `Schedule.show()` is introduced: <img width="555" alt="image" src="https://user-images.githubusercontent.com/22515877/185713487-03722566-1df7-45c7-a034-c1460d399681.png"> - After this change: <img width="583" alt="image" src="https://user-images.githubusercontent.com/22515877/185713564-c54f3a9d-cd52-4709-a8b8-d8a61361e611.png">
Following apache#12197, this PR introduces `Schedule.show()` which convenience the user experience in the following two aspects: - Python syntax highlighting - Outputs a schedule function instead of standalone instructions so that it's easier to follow. To demonstrate this change: - Before `Schedule.show()` is introduced: <img width="555" alt="image" src="https://user-images.githubusercontent.com/22515877/185713487-03722566-1df7-45c7-a034-c1460d399681.png"> - After this change: <img width="583" alt="image" src="https://user-images.githubusercontent.com/22515877/185713564-c54f3a9d-cd52-4709-a8b8-d8a61361e611.png">
Following apache#12197, this PR introduces `Schedule.show()` which convenience the user experience in the following two aspects: - Python syntax highlighting - Outputs a schedule function instead of standalone instructions so that it's easier to follow. To demonstrate this change: - Before `Schedule.show()` is introduced: <img width="555" alt="image" src="https://user-images.githubusercontent.com/22515877/185713487-03722566-1df7-45c7-a034-c1460d399681.png"> - After this change: <img width="583" alt="image" src="https://user-images.githubusercontent.com/22515877/185713564-c54f3a9d-cd52-4709-a8b8-d8a61361e611.png">
Following #12197, this PR introduces `Schedule.show()` which convenience the user experience in the following two aspects: - Python syntax highlighting - Outputs a schedule function instead of standalone instructions so that it's easier to follow. To demonstrate this change: - Before `Schedule.show()` is introduced: <img width="555" alt="image" src="https://user-images.githubusercontent.com/22515877/185713487-03722566-1df7-45c7-a034-c1460d399681.png"> - After this change: <img width="583" alt="image" src="https://user-images.githubusercontent.com/22515877/185713564-c54f3a9d-cd52-4709-a8b8-d8a61361e611.png">
* feat(ux): highlight tvm script * resolve dependency * refact(tvmscript): highlight fallback as plain text with warning; put ansi colors as default terminal style * refact(tvmscript): make terminal style close to the default notebook style * fix(pylint): disable=import-outside-toplevel * fix(ci-dep): Pygments>=2.4.0 to support ansicolors w/o # * refact: making Pygments versioning most robust and user-friendly * fix: pylint var naming
Following apache#12197, this PR introduces `Schedule.show()` which convenience the user experience in the following two aspects: - Python syntax highlighting - Outputs a schedule function instead of standalone instructions so that it's easier to follow. To demonstrate this change: - Before `Schedule.show()` is introduced: <img width="555" alt="image" src="https://user-images.githubusercontent.com/22515877/185713487-03722566-1df7-45c7-a034-c1460d399681.png"> - After this change: <img width="583" alt="image" src="https://user-images.githubusercontent.com/22515877/185713564-c54f3a9d-cd52-4709-a8b8-d8a61361e611.png">
See tlc-pack/relax#185
cc: @YuchenJin @junrushao1994 @Hzfengsy