Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
091027dd
提交
091027dd
authored
11月 27, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make DebugMode raise a better error when an optimization insert an op
that raise an error during computation.
上级
ab660ca3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
76 行增加
和
2 行删除
+76
-2
debugmode.py
theano/compile/debugmode.py
+43
-2
test_debugmode.py
theano/compile/tests/test_debugmode.py
+33
-0
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
091027dd
...
...
@@ -192,6 +192,10 @@ class BadThunkOutput(DebugModeError):
return
ret
class
OptimizationInsertError
(
DebugModeError
):
pass
class
BadOptimization
(
DebugModeError
):
"""Exception: some variable and its substitute take different
runtime values.
...
...
@@ -1792,6 +1796,26 @@ class _Linker(gof.link.LocalLinker):
# shouldn't have put it into the list in
# the first place
thunk_py
=
None
except
Exception
,
e
:
# I think that only 1 optimization can
# insert a given apply node. If that is not True,
# we would need to loop over all node outputs,
# But this make the output uglier.
reason
=
fgraph
.
equivalence_tracker
.
reasons
[
node
.
outputs
[
0
]]
opt
=
str
(
reason
[
0
][
0
])
msg
=
(
"An optimization (probably
%
s ) inserted an apply node that raise an error."
%
opt
+
"The information we have about this optimizations is:"
+
str
(
reason
)
+
"The original exception: "
+
str
(
e
))
new_e
=
OptimizationInsertError
(
msg
)
new_e
.
reason
=
opt
exc_type
,
exc_value
,
exc_trace
=
sys
.
exc_info
()
exc_type
=
OptimizationInsertError
exc_value
=
new_e
raise_with_op
(
node
,
thunk_c
,
(
exc_type
,
exc_value
,
exc_trace
))
if
thunk_py
:
# check output values for type-correctness
...
...
@@ -1869,8 +1893,25 @@ class _Linker(gof.link.LocalLinker):
## First time, with None in output_storage
try
:
thunk_c
()
except
Exception
:
raise_with_op
(
node
,
thunk_c
)
except
Exception
,
e
:
# I think that only 1 optimization can
# insert a given apply node. If that is not True,
# we would need to loop over all node outputs,
# But this make the output uglier.
reason
=
fgraph
.
equivalence_tracker
.
reasons
[
node
.
outputs
[
0
]]
opt
=
str
(
reason
[
0
][
0
])
msg
=
(
"An optimization (probably
%
s ) inserted an apply node that raise an error."
%
opt
+
"The information we have about this optimizations is:"
+
str
(
reason
)
+
"The original exception: "
+
str
(
e
))
new_e
=
OptimizationInsertError
(
msg
)
new_e
.
reason
=
opt
exc_type
,
exc_value
,
exc_trace
=
sys
.
exc_info
()
exc_type
=
OptimizationInsertError
exc_value
=
new_e
raise_with_op
(
node
,
thunk_c
,
(
exc_type
,
exc_value
,
exc_trace
))
for
r
in
node
.
outputs
:
# check output values for type-correctness
...
...
theano/compile/tests/test_debugmode.py
浏览文件 @
091027dd
...
...
@@ -248,6 +248,39 @@ def test_badoptimization():
assert
False
def
test_badoptimization_opt_err
():
"""This variant of test_badoptimization() replace the working code
with a new apply node that will raise an error.
"""
@gof.local_optimizer
([
theano
.
tensor
.
add
])
def
insert_bigger_b_add
(
node
):
if
node
.
op
==
theano
.
tensor
.
add
:
inputs
=
list
(
node
.
inputs
)
if
inputs
[
-
1
]
.
owner
is
None
:
inputs
[
-
1
]
=
theano
.
tensor
.
concatenate
((
inputs
[
-
1
],
inputs
[
-
1
]))
return
[
node
.
op
(
*
inputs
)]
return
False
edb
=
gof
.
EquilibriumDB
()
edb
.
register
(
'insert_bigger_b_add'
,
insert_bigger_b_add
,
'all'
)
opt
=
edb
.
query
(
'+all'
)
a
=
theano
.
tensor
.
dvector
()
b
=
theano
.
tensor
.
dvector
()
f
=
theano
.
function
([
a
,
b
],
a
+
b
,
mode
=
debugmode
.
DebugMode
(
optimizer
=
opt
))
try
:
f
([
1.0
,
2.0
,
3.0
],
[
2
,
3
,
4
],)
except
debugmode
.
OptimizationInsertError
,
e
:
assert
str
(
e
.
reason
)
==
'insert_bigger_b_add'
return
# TEST PASS
assert
False
def
test_stochasticoptimization
():
# this optimization alternates between triggering and not triggering.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论