Skip to content

[Relay] RelayViz graphviz renderer#10400

Merged
masahi merged 1 commit into
apache:mainfrom
chiwwang:graphviz_renderer
Mar 1, 2022
Merged

[Relay] RelayViz graphviz renderer#10400
masahi merged 1 commit into
apache:mainfrom
chiwwang:graphviz_renderer

Conversation

@chiwwang

Copy link
Copy Markdown
Contributor

Following #10085, this PR adds a graphviz backend.
It requires python graphviz package and dot executable in the PATH, similar to tedd.py.

This implementation is a porting of visualize function in
https://tvm.apache.org/2020/07/14/bert-pytorch-tvm, plus a callback get_node_attr.

get_node_attr return specific graphviz-attributes for the node.
It might be useful if we want to emphasize some nodes with certain types and attributes.

An example is provided in
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/test_viz.py

Its outputs are:
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/mod_with_subgraph.pdf
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/mod_wo_subgraph.pdf
Note that nn.conv2d with NCHW layout is green-colored.

Thanks for contributing to TVM! Please refer to guideline https://tvm.apache.org/docs/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers by @ them in the pull request thread.

Following apache#10085, this PR adds a
graphviz backend. It requires python `graphviz` package and `dot`
executable in the PATH, similar to `tedd.py`.

This implementation is much like a porting of `visualize` function in
https://tvm.apache.org/2020/07/14/bert-pytorch-tvm, except that
`node_attr_dict` is replaced with a callback `get_node_attr`.

`get_node_attr` can be somehow used to emphasize a set of nodes.
It might be useful if we encounter problems in inferences
and want to find nodes with certain types and attributes.

An example is provided in
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/test_viz.py

Its outputs are (conv2d with NCHW layout is green-colored):
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/mod_with_subgraph.pdf
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/mod_wo_subgraph.pdf

@masahi masahi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@comaniac comaniac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work! btw would you add this rendering approach to the document as well?

@elvin-n elvin-n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@echuraev echuraev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you! LGTM. Nice work!

@chiwwang

chiwwang commented Mar 1, 2022

Copy link
Copy Markdown
Contributor Author

would you add this rendering approach to the document as well?

@comaniac Yes, it is already added in contrib.rst.
I wrote an example in class DotPlotter, which would be rendered by Sphinx.

But I didn't write this in tutorial, only added one comment. graphviz seems to be optional for TVM so I am not sure whether it's suitable to add in codes that will be run when building doc. (If it's ok then I can add some sections to the tutorial latter.)

@masahi

masahi commented Mar 1, 2022

Copy link
Copy Markdown
Member

Ok let's defer doc change to a follow-up and let @chiwwang continue.

@masahi masahi merged commit 111b2da into apache:main Mar 1, 2022
@comaniac

comaniac commented Mar 2, 2022

Copy link
Copy Markdown
Contributor

I just realized that we haven't updated the doc website for a while so this tutorial is even not there yet 😂\

UPDATE: I just updated the TVM site based on the main branch commit b55997d

pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
Following apache#10085, this PR adds a
graphviz backend. It requires python `graphviz` package and `dot`
executable in the PATH, similar to `tedd.py`.

This implementation is much like a porting of `visualize` function in
https://tvm.apache.org/2020/07/14/bert-pytorch-tvm, except that
`node_attr_dict` is replaced with a callback `get_node_attr`.

`get_node_attr` can be somehow used to emphasize a set of nodes.
It might be useful if we encounter problems in inferences
and want to find nodes with certain types and attributes.

An example is provided in
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/test_viz.py

Its outputs are (conv2d with NCHW layout is green-colored):
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/mod_with_subgraph.pdf
https://github.com/chiwwang/tvm/blob/graphviz_renderer_example/mod_wo_subgraph.pdf
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.

5 participants