Skip to content

Commit

Permalink
1. Import IPython only if SVG is requested. This is required to fix a…
Browse files Browse the repository at this point in the history
… tutorial publishing faliure. 2. Fix test about IPython availability check.
  • Loading branch information
yongfeng-nv committed Feb 11, 2020
1 parent bb8752d commit 17d3796
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 3 additions & 2 deletions python/tvm/contrib/tedd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=import-outside-toplevel
"""Tensor Expression Debug Display (TEDD), visualizing Tensor Expression"""
import html
import json
import warnings
from graphviz import Digraph
from graphviz import Source
from IPython.display import display
from IPython.display import SVG
import tvm

TVMDD_TABLE_BODY_WIDTH = 30
Expand Down Expand Up @@ -208,6 +207,8 @@ def dump_graph(dot_string,
except IOError:
print('Cannot open file: ' + dot_file_path)
if show_svg:
from IPython.display import display
from IPython.display import SVG
src = Source(dot_string)
display(SVG(src.pipe(format='svg')))
if output_dot_string:
Expand Down
2 changes: 1 addition & 1 deletion tests/python/contrib/test_tedd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def findany(pattern, str):

def checkdepdency():
import pkg_resources
return not {'graphviz', 'IPython'} - {pkg.key for pkg in pkg_resources.working_set}
return not {'graphviz', 'ipython'} - {pkg.key for pkg in pkg_resources.working_set}

def test_dfg():
A = tvm.placeholder((1024, 4096), dtype='float32', name='A')
Expand Down
22 changes: 17 additions & 5 deletions tutorials/language/tedd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.
"""
Use Tensor Expression Debug Display (TEDD) for Visualization
=============================================
============================================================
**Author**: `Yongfeng Gu <https://github.com/yongfeng-nv>`_
This is an introduction about using TEDD to visualize tensor expressions.
Expand Down Expand Up @@ -47,10 +47,11 @@

######################################################################
# Define and Schedule Convolution with Bias and ReLU
# ----------------------------
# --------------------------------------------------
# Let's build an example Tensor Expression for a convolution followed by Bias and ReLU.
# We first connect conv2d, add, and relu TOPIs. Then, we create a TOPI generic schedule.
#

batch = 1
in_channel = 256
in_size = 32
Expand All @@ -70,11 +71,12 @@

######################################################################
# Render Graphs with TEDD
# -------------------
# -----------------------
# We render graphs to see the computation
# and how it is scheduled.
# If you run the tutorial in a Jupyter notebook, you can use the following commented lines
# to render SVG figures showing in notebook directly.
#

tedd.viz_dataflow_graph(s, dot_file_path = '/tmp/dfg.dot')
#tedd.viz_dataflow_graph(s, show_svg = True)
Expand All @@ -83,18 +85,22 @@
# .. image:: https://github.com/dmlc/web-data/raw/master/tvm/tutorial/tedd_dfg.png
# :align: center
# :scale: 100%
#
# The first one is a dataflow graph. Every node represents a stage with name and memory
# scope shown in the middle and inputs/outputs information on the sides.
# Edges show nodes' dependency.
#

tedd.viz_schedule_tree(s, dot_file_path = '/tmp/scheduletree.dot')
#tedd.viz_schedule_tree(s, show_svg = True)

######################################################################
# We just rendered the schedule tree graph. You may notice an warning about ranges not
# available.
# The message also suggests to call normalize() to infer range information. We will
# skip inspecting the first schedule tree and encourage you to compare the graphs before
# and and after normalize() for its impact.
# and after normalize() for its impact.
#

s = s.normalize()
tedd.viz_schedule_tree(s, dot_file_path = '/tmp/scheduletree2.dot')
Expand All @@ -104,6 +110,7 @@
# .. image:: https://github.com/dmlc/web-data/raw/master/tvm/tutorial/tedd_st.png
# :align: center
# :scale: 100%
#
# Now, let us take a close look at the second schedule tree. Every block under ROOT
# represents a
# stage. Stage name shows in the top row and compute shows in the bottom row.
Expand All @@ -120,13 +127,15 @@
# If a stage doesn't compute_at any other stage, it has an edge directly to the
# ROOT node. Otherwise, it has an edge pointing to the IterVar it attaches to,
# such as W.shared attaches to rx.outer in the middle compute stage.
#

######################################################################
# .. note::
#
# By definition, IterVars are internal nodes and computes are leaf nodes in
# a schedule tree. The edges among IterVars and compute within one stage are
# omitted, making every stage a block, for better readability.
#

tedd.viz_itervar_relationship_graph(s, dot_file_path = '/tmp/itervar.dot')
#tedd.viz_itervar_relationship_graph(s, show_svg = True)
Expand All @@ -135,18 +144,21 @@
# .. image:: https://github.com/dmlc/web-data/raw/master/tvm/tutorial/tedd_itervar_rel.png
# :align: center
# :scale: 100%
#
# The last one is an IterVar Relationship Graph. Every subgraph represents a
# stage and contains IterVar nodes and transformation nodes. For example,
# W.shared has three split nodes and three fuse nodes. The rest are IterVar
# nodes of the same format as the IterVar rows in Schedule Trees. Root
# IterVars are those not driven by any transformation node, such as ax0; leaf
# IterVars don't drive any transformation node and have non-negative indices,
# such as ax0.ax1.fused.ax2.fused.ax3.fused.outer with index of 0.
#


######################################################################
# Summary
# -------
# This tutorial demonstrates the usage of TEDD. We use an example built
# with TOPI to show the schedules under the hood. You can also use
# it before and after any schedule primitive to inspect the impact.
# it before and after any schedule primitive to inspect its effect.
#

0 comments on commit 17d3796

Please sign in to comment.