Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
[UX] Highlight TVMScript with Pygments (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
ganler authored and yongwww committed Aug 14, 2022
1 parent 0f173c6 commit 5fdd1c7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/gen_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
(
"Base requirements needed to install tvm",
[
"Pygments",
"attrs",
"cloudpickle",
"decorator",
Expand Down
1 change: 1 addition & 0 deletions python/tvm/ir/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def script(self, tir_prefix: str = "T", show_meta: bool = False) -> str:
def show(self, style: Optional[str] = None) -> None:
"""
A sugar for print highlighted TVM script.
Parameters
----------
style : str, optional
Expand Down
29 changes: 29 additions & 0 deletions python/tvm/relax/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,35 @@ def __call__(self, *args):
"""
return Call(self, args, None, None)

def script(self, show_meta: bool = False) -> str:
"""Print relax.Function into TVMScript
Parameters
----------
show_meta : bool
Whether to show meta information
Returns
-------
script : str
The TVM Script of the relax.Function
"""
return tvm._ffi.get_global_func("script.AsRelaxScript")(self, show_meta) # type: ignore

def show(self, style: str = "light") -> None:
"""
A sugar for print highlighted TVM script.
Parameters
----------
style : str, optional
Pygments styles extended by "light" (default) and "dark", by default "light"
"""
from tvm.script.highlight import cprint # pylint: disable=import-outside-toplevel

# Use deferred import to avoid circular import while keeping cprint under tvm/script
cprint(self, style=style)


@tvm._ffi.register_object("relax.expr.ExternFunc")
class ExternFunc(BaseFunc):
Expand Down
1 change: 1 addition & 0 deletions python/tvm/script/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from tvm.tir import PrimFunc



def cprint(printable: Union[IRModule, PrimFunc], style: Optional[str] = None) -> None:
"""
Print highlighted TVM script string with Pygments
Expand Down
1 change: 1 addition & 0 deletions python/tvm/tir/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def script(self, tir_prefix: str = "T", show_meta: bool = False) -> str:
def show(self, style: Optional[str] = None) -> None:
"""
A sugar for print highlighted TVM script.
Parameters
----------
style : str, optional
Expand Down

0 comments on commit 5fdd1c7

Please sign in to comment.