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

[Relay] RelayViz graphviz renderer #10400

Merged
merged 1 commit into from
Mar 1, 2022
Merged

Conversation

chiwwang
Copy link
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
Copy link
Member

@masahi masahi left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@comaniac comaniac left a comment

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?

Copy link
Contributor

@elvin-n elvin-n left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@echuraev echuraev left a comment

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
Copy link
Contributor Author

chiwwang commented Mar 1, 2022

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
Copy link
Member

masahi commented Mar 1, 2022

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
Copy link
Contributor

comaniac commented Mar 2, 2022

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