Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
641b8143
提交
641b8143
authored
4月 29, 2016
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make a parameter to debugprint() to print the clients.
上级
6104d3f9
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
34 行增加
和
11 行删除
+34
-11
debugmode.py
theano/compile/debugmode.py
+16
-6
printing.py
theano/printing.py
+17
-4
test_printing.py
theano/tests/test_printing.py
+1
-1
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
641b8143
...
@@ -513,7 +513,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
...
@@ -513,7 +513,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
stop_on_name
=
False
,
prefix_child
=
None
,
stop_on_name
=
False
,
prefix_child
=
None
,
scan_ops
=
None
,
profile
=
None
,
scan_ops
=
None
,
profile
=
None
,
scan_inner_to_outer_inputs
=
None
,
smap
=
None
,
scan_inner_to_outer_inputs
=
None
,
smap
=
None
,
used_ids
=
None
):
used_ids
=
None
,
print_clients
=
False
):
"""
"""
Print the graph leading to `r` to given depth.
Print the graph leading to `r` to given depth.
...
@@ -526,7 +526,8 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
...
@@ -526,7 +526,8 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
depth
depth
Maximum recursion depth (Default -1 for unlimited).
Maximum recursion depth (Default -1 for unlimited).
done
done
dict of Apply instances that have already been printed and their
Internal. Used to pass information when recursing.
Dict of Apply instances that have already been printed and their
associated printed ids.
associated printed ids.
print_type
print_type
Whether to print the Variable type after the other infos.
Whether to print the Variable type after the other infos.
...
@@ -555,6 +556,12 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
...
@@ -555,6 +556,12 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
inputs (outer inputs) for printing purposes.
inputs (outer inputs) for printing purposes.
smap
smap
None or the storage_map when printing an Theano function.
None or the storage_map when printing an Theano function.
used_ids
Internal. Used to pass information when recursing.
It is a dict from obj to the id used for it.
It wasn't always printed, but at least a reference to it was printed.
print_clients
If True, we will print the clients of nodes when they have more then one clients.
"""
"""
if
depth
==
0
:
if
depth
==
0
:
return
return
...
@@ -637,7 +644,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
...
@@ -637,7 +644,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
if
smap
:
if
smap
:
data
=
" "
+
str
(
smap
.
get
(
a
.
outputs
[
0
],
''
))
data
=
" "
+
str
(
smap
.
get
(
a
.
outputs
[
0
],
''
))
clients
=
''
clients
=
''
if
len
(
getattr
(
r
,
'clients'
,
[]))
>
1
:
if
print_clients
and
len
(
getattr
(
r
,
'clients'
,
[]))
>
1
:
def
get_index
(
c
):
def
get_index
(
c
):
try
:
try
:
return
order
.
index
(
c
)
return
order
.
index
(
c
)
...
@@ -700,7 +707,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
...
@@ -700,7 +707,7 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
prefix_child
=
new_prefix_child
,
scan_ops
=
scan_ops
,
prefix_child
=
new_prefix_child
,
scan_ops
=
scan_ops
,
profile
=
profile
,
profile
=
profile
,
scan_inner_to_outer_inputs
=
scan_inner_to_outer_inputs
,
scan_inner_to_outer_inputs
=
scan_inner_to_outer_inputs
,
smap
=
smap
,
used_ids
=
used_ids
)
smap
=
smap
,
used_ids
=
used_ids
,
print_clients
=
print_clients
)
else
:
else
:
if
scan_inner_to_outer_inputs
is
not
None
and
\
if
scan_inner_to_outer_inputs
is
not
None
and
\
r
in
scan_inner_to_outer_inputs
:
r
in
scan_inner_to_outer_inputs
:
...
@@ -1688,13 +1695,16 @@ class _VariableEquivalenceTracker(object):
...
@@ -1688,13 +1695,16 @@ class _VariableEquivalenceTracker(object):
# N.B. compute the debugprint now, because future
# N.B. compute the debugprint now, because future
# optimizations will change the graph
# optimizations will change the graph
done
=
dict
()
done
=
dict
()
used_ids
=
dict
()
self
.
reasons
[
new_r
]
.
append
(
self
.
reasons
[
new_r
]
.
append
(
(
reason
,
(
reason
,
r
,
r
,
debugprint
(
r
,
prefix
=
' '
,
depth
=
6
,
debugprint
(
r
,
prefix
=
' '
,
depth
=
6
,
file
=
StringIO
(),
done
=
done
)
.
getvalue
(),
file
=
StringIO
(),
done
=
done
,
used_ids
=
used_ids
)
.
getvalue
(),
debugprint
(
new_r
,
prefix
=
' '
,
depth
=
6
,
debugprint
(
new_r
,
prefix
=
' '
,
depth
=
6
,
file
=
StringIO
(),
done
=
done
)
.
getvalue
()))
file
=
StringIO
(),
done
=
done
,
used_ids
=
used_ids
)
.
getvalue
()))
self
.
replaced_by
[
r
]
.
append
((
reason
,
new_r
))
self
.
replaced_by
[
r
]
.
append
((
reason
,
new_r
))
if
r
in
self
.
equiv
:
if
r
in
self
.
equiv
:
...
...
theano/printing.py
浏览文件 @
641b8143
...
@@ -50,7 +50,8 @@ VALID_ASSOC = set(['left', 'right', 'either'])
...
@@ -50,7 +50,8 @@ VALID_ASSOC = set(['left', 'right', 'either'])
def
debugprint
(
obj
,
depth
=-
1
,
print_type
=
False
,
def
debugprint
(
obj
,
depth
=-
1
,
print_type
=
False
,
file
=
None
,
ids
=
'CHAR'
,
stop_on_name
=
False
,
file
=
None
,
ids
=
'CHAR'
,
stop_on_name
=
False
,
done
=
None
,
print_storage
=
False
):
done
=
None
,
print_storage
=
False
,
print_clients
=
False
,
used_ids
=
None
):
"""Print a computation graph as text to stdout or a file.
"""Print a computation graph as text to stdout or a file.
:type obj: Variable, Apply, or Function instance
:type obj: Variable, Apply, or Function instance
...
@@ -76,6 +77,13 @@ def debugprint(obj, depth=-1, print_type=False,
...
@@ -76,6 +77,13 @@ def debugprint(obj, depth=-1, print_type=False,
:param print_storage: If True, this will print the storage map
:param print_storage: If True, this will print the storage map
for Theano functions. Combined with allow_gc=False, after the
for Theano functions. Combined with allow_gc=False, after the
execution of a Theano function, we see the intermediate result.
execution of a Theano function, we see the intermediate result.
:type print_clients: bool
:param print_clients: If True, this will print for Apply node that
have more then 1 clients its clients. This help find who use
an Apply node.
:type used_ids: dict or None
:param used_ids: the id to use for some object, but maybe we only
refered to it yet.
:returns: string if `file` == 'str', else file arg
:returns: string if `file` == 'str', else file arg
...
@@ -105,6 +113,8 @@ def debugprint(obj, depth=-1, print_type=False,
...
@@ -105,6 +113,8 @@ def debugprint(obj, depth=-1, print_type=False,
_file
=
file
_file
=
file
if
done
is
None
:
if
done
is
None
:
done
=
dict
()
done
=
dict
()
if
used_ids
is
None
:
used_ids
=
dict
()
used_ids
=
dict
()
used_ids
=
dict
()
results_to_print
=
[]
results_to_print
=
[]
profile_list
=
[]
profile_list
=
[]
...
@@ -186,7 +196,8 @@ N.B.:
...
@@ -186,7 +196,8 @@ N.B.:
debugmode
.
debugprint
(
r
,
depth
=
depth
,
done
=
done
,
print_type
=
print_type
,
debugmode
.
debugprint
(
r
,
depth
=
depth
,
done
=
done
,
print_type
=
print_type
,
file
=
_file
,
order
=
o
,
ids
=
ids
,
file
=
_file
,
order
=
o
,
ids
=
ids
,
scan_ops
=
scan_ops
,
stop_on_name
=
stop_on_name
,
scan_ops
=
scan_ops
,
stop_on_name
=
stop_on_name
,
profile
=
p
,
smap
=
s
,
used_ids
=
used_ids
)
profile
=
p
,
smap
=
s
,
used_ids
=
used_ids
,
print_clients
=
print_clients
)
if
len
(
scan_ops
)
>
0
:
if
len
(
scan_ops
)
>
0
:
print
(
""
,
file
=
_file
)
print
(
""
,
file
=
_file
)
...
@@ -216,7 +227,8 @@ N.B.:
...
@@ -216,7 +227,8 @@ N.B.:
file
=
_file
,
ids
=
ids
,
file
=
_file
,
ids
=
ids
,
scan_ops
=
scan_ops
,
scan_ops
=
scan_ops
,
stop_on_name
=
stop_on_name
,
stop_on_name
=
stop_on_name
,
scan_inner_to_outer_inputs
=
inner_to_outer_inputs
)
scan_inner_to_outer_inputs
=
inner_to_outer_inputs
,
print_clients
=
print_clients
,
used_ids
=
used_ids
)
if
hasattr
(
s
.
owner
.
op
,
'fn'
):
if
hasattr
(
s
.
owner
.
op
,
'fn'
):
# If the op was compiled, print the optimized version.
# If the op was compiled, print the optimized version.
outputs
=
s
.
owner
.
op
.
fn
.
maker
.
fgraph
.
outputs
outputs
=
s
.
owner
.
op
.
fn
.
maker
.
fgraph
.
outputs
...
@@ -235,7 +247,8 @@ N.B.:
...
@@ -235,7 +247,8 @@ N.B.:
ids
=
ids
,
stop_on_name
=
stop_on_name
,
ids
=
ids
,
stop_on_name
=
stop_on_name
,
prefix_child
=
new_prefix_child
,
prefix_child
=
new_prefix_child
,
scan_ops
=
scan_ops
,
scan_ops
=
scan_ops
,
scan_inner_to_outer_inputs
=
inner_to_outer_inputs
)
scan_inner_to_outer_inputs
=
inner_to_outer_inputs
,
print_clients
=
print_clients
,
used_ids
=
used_ids
)
if
file
is
_file
:
if
file
is
_file
:
return
file
return
file
...
...
theano/tests/test_printing.py
浏览文件 @
641b8143
...
@@ -274,7 +274,7 @@ def test_debugprint():
...
@@ -274,7 +274,7 @@ def test_debugprint():
# test clients
# test clients
s
=
StringIO
()
s
=
StringIO
()
f
=
theano
.
function
([
A
,
B
,
D
],
[
A
+
B
,
A
+
B
-
D
])
f
=
theano
.
function
([
A
,
B
,
D
],
[
A
+
B
,
A
+
B
-
D
])
debugprint
(
f
,
file
=
s
)
debugprint
(
f
,
file
=
s
,
print_clients
=
True
)
s
=
s
.
getvalue
()
s
=
s
.
getvalue
()
# The additional white space are needed!
# The additional white space are needed!
reference
=
'
\n
'
.
join
([
reference
=
'
\n
'
.
join
([
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论