提交 2046b190 authored 作者: Frederic's avatar Frederic

fix pydotprint in ProfileMode.

上级 95778c8f
...@@ -382,7 +382,8 @@ pprint.assign(lambda pstate, r: hasattr(pstate, 'target') and pstate.target is n ...@@ -382,7 +382,8 @@ pprint.assign(lambda pstate, r: hasattr(pstate, 'target') and pstate.target is n
pp = pprint pp = pprint
# colors not used: orange, ambre#FFBF00, purple, pink,
# used by default: green, bug, grey, red
default_colorCodes = {'GpuFromHost' : 'red', default_colorCodes = {'GpuFromHost' : 'red',
'HostFromGpu' : 'red', 'HostFromGpu' : 'red',
'Scan' : 'yellow', 'Scan' : 'yellow',
...@@ -391,8 +392,6 @@ default_colorCodes = {'GpuFromHost' : 'red', ...@@ -391,8 +392,6 @@ default_colorCodes = {'GpuFromHost' : 'red',
'Elemwise': '#FFAABB', 'Elemwise': '#FFAABB',
'Subtensor': '#FFAAFF'} 'Subtensor': '#FFAAFF'}
def pydotprint(fct, outfile=None, def pydotprint(fct, outfile=None,
compact=True, format='png', with_ids=False, compact=True, format='png', with_ids=False,
high_contrast=True, cond_highlight=None, colorCodes=None, high_contrast=True, cond_highlight=None, colorCodes=None,
...@@ -428,15 +427,15 @@ def pydotprint(fct, outfile=None, ...@@ -428,15 +427,15 @@ def pydotprint(fct, outfile=None,
we will print only the variable name. we will print only the variable name.
Otherwise, we concatenate the type to the var name. Otherwise, we concatenate the type to the var name.
In the graph, box are an Apply Node(the execution of an op) and ellipse are variable. In the graph, ellipse are an Apply Node(the execution of an op) and box are variable.
If variable have name they are used as the text(if multiple var have the same name, they will be merged in the graph). If variable have name they are used as the text(if multiple var have the same name, they will be merged in the graph).
Otherwise, if the variable is constant, we print the value and finaly we print the type + an uniq number to don't have multiple var merged. Otherwise, if the variable is constant, we print the value and finaly we print the type + an uniq number to don't have multiple var merged.
We print the op of the apply in the Apply box with a number that represent the toposort order of application of those Apply. We print the op of the apply in the Apply box with a number that represent the toposort order of application of those Apply.
If an Apply have more then 1 input, print add a label to the edge that in the index of the inputs. If an Apply have more then 1 input, print add a label to the edge that in the index of the inputs.
green ellipses are inputs to the graph green box are inputs to the graph
blue ellipses are outputs of the graph blue box are outputs of the graph
grey ellipses are var generated by the graph that are not output and are not used. grey box are var generated by the graph that are not output and are not used.
red ellipses are transfer to/from the gpu. red ellipses are transfer to/from the gpu.
op with those name GpuFromHost, HostFromGpu op with those name GpuFromHost, HostFromGpu
""" """
...@@ -450,7 +449,7 @@ def pydotprint(fct, outfile=None, ...@@ -450,7 +449,7 @@ def pydotprint(fct, outfile=None,
if isinstance(fct, Function): if isinstance(fct, Function):
mode = fct.maker.mode mode = fct.maker.mode
fct_env = fct.maker.env fct_env = fct.maker.env
if not isinstance(mode,ProfileMode) or not mode.fct_call.has_key(fct): if not isinstance(mode,ProfileMode) or not mode.profile_stats.has_key(fct):
mode=None mode=None
elif isinstance(fct, gof.Env): elif isinstance(fct, gof.Env):
mode = None mode = None
...@@ -542,14 +541,14 @@ def pydotprint(fct, outfile=None, ...@@ -542,14 +541,14 @@ def pydotprint(fct, outfile=None,
return apply_name_cache[node] return apply_name_cache[node]
prof_str='' prof_str=''
if mode: if mode:
time = mode.apply_time.get((topo.index(node),node),0) time = mode.profile_stats[fct].apply_time.get(node,0)
#second, % total time in profiler, %fct time in profiler #second, % total time in profiler, %fct time in profiler
if mode.local_time[0]==0: if mode.local_time==0:
pt=0 pt=0
else: pt=time*100/mode.local_time[0] else: pt=time*100/mode.local_time
if mode.fct_call[fct]==0: if mode.profile_stats[fct].fct_callcount==0:
pf=0 pf=0
else: pf = time*100/mode.fct_call_time[fct] else: pf = time*100/mode.profile_stats[fct].fct_call_time
prof_str=' (%.3fs,%.3f%%,%.3f%%)'%(time,pt,pf) prof_str=' (%.3fs,%.3f%%,%.3f%%)'%(time,pt,pf)
applystr = str(node.op).replace(':','_') applystr = str(node.op).replace(':','_')
applystr += prof_str applystr += prof_str
......
...@@ -36,6 +36,12 @@ def test_pydotprint_cond_highlight(): ...@@ -36,6 +36,12 @@ def test_pydotprint_cond_highlight():
assert s.getvalue() == 'pydotprint: cond_highlight is set but there is no IfElse node in the graph\n' assert s.getvalue() == 'pydotprint: cond_highlight is set but there is no IfElse node in the graph\n'
def test_pydotprint_profile():
""" Just check that pydotprint don't crash with ProfileMode"""
A = tensor.matrix()
f = theano.function([A],A+1,mode='ProfileMode')
theano.printing.pydotprint(f)
def test_min_informative_str(): def test_min_informative_str():
""" evaluates a reference output to make sure the """ evaluates a reference output to make sure the
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论