Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
49fc30bd
提交
49fc30bd
authored
3月 26, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added debugmode test for stochastic optimization
上级
32792a26
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
54 行增加
和
24 行删除
+54
-24
debugmode.py
theano/compile/debugmode.py
+21
-23
test_debugmode.py
theano/compile/tests/test_debugmode.py
+33
-1
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
49fc30bd
...
@@ -160,7 +160,14 @@ class BadViewMap(DebugModeError):
...
@@ -160,7 +160,14 @@ class BadViewMap(DebugModeError):
return
sio
.
getvalue
()
return
sio
.
getvalue
()
class
StochasticOrder
(
DebugModeError
):
class
StochasticOrder
(
DebugModeError
):
"""TODO #319"""
"""Exception: Repeated Optimizations of the same graph do not give identical results.
The most common cause is that an Optimization iterates over some objects in a
memory-address-dependent order (such as id() or object.hash()). If you see this error and
you think it is related to optimizations within Theano, email theano-dev with the message
attached to this exception.
"""
pass
pass
class
FloatError
(
DebugModeError
):
class
FloatError
(
DebugModeError
):
...
@@ -532,7 +539,7 @@ class _EnvEvent(object):
...
@@ -532,7 +539,7 @@ class _EnvEvent(object):
self
.
reason
,
self
.
reason
,
str
(
self
.
op
),
str
(
self
.
op
),
str
(
self
.
idx
),
str
(
self
.
idx
),
str
(
len
(
self
.
node
.
inputs
))])
str
(
len
(
self
.
node
.
inputs
))
if
(
self
.
op
!=
'output'
)
else
''
])
else
:
else
:
return
str
(
self
.
__dict__
)
return
str
(
self
.
__dict__
)
...
@@ -980,21 +987,21 @@ class _Maker(FunctionMaker): #inheritance buys a few helper functions
...
@@ -980,21 +987,21 @@ class _Maker(FunctionMaker): #inheritance buys a few helper functions
li
=
env
.
equivalence_tracker
.
event_list
li
=
env
.
equivalence_tracker
.
event_list
l0
=
env0
.
equivalence_tracker
.
event_list
l0
=
env0
.
equivalence_tracker
.
event_list
if
li
!=
l0
:
if
li
!=
l0
:
print
>>
mode
.
diagnostic
,
"WARNING: Optimization process is unstable"
infolog
=
StringIO
()
print
>>
infolog
,
"WARNING: Optimization process is unstable..."
print
>>
infolog
,
"(event index) (one event trace) (other event trace)"
print
>>
infolog
,
"-----------------------------------------------------"
for
j
in
xrange
(
max
(
len
(
li
),
len
(
l0
))):
for
j
in
xrange
(
max
(
len
(
li
),
len
(
l0
))):
if
li
[
j
]
!=
l0
[
j
]:
if
j
>=
len
(
li
)
or
j
>=
len
(
l0
)
or
li
[
j
]
!=
l0
[
j
]:
print
>>
mode
.
diagnostic
,
"* "
,
j
print
>>
infolog
,
"* "
,
j
,
print
>>
mode
.
diagnostic
,
" "
,
str
(
li
[
j
])
if
j
<
len
(
li
)
else
'-'
print
>>
infolog
,
" "
,
str
(
li
[
j
])
if
j
<
len
(
li
)
else
'-'
,
print
>>
mode
.
diagnostic
,
" "
,
str
(
l0
[
j
])
if
j
<
len
(
l0
)
else
'-'
print
>>
infolog
,
" "
,
str
(
l0
[
j
])
if
j
<
len
(
l0
)
else
'-'
else
:
else
:
pass
pass
raise
StochasticOrder
(
infolog
.
getvalue
())
print
>>
sys
.
stderr
,
"EXITING"
sys
.
exit
(
1
)
#there is a ticket related to not calling sys.exit here.
break
else
:
else
:
if
self
.
verbose
:
if
self
.
verbose
:
print
>>
sys
.
std
out
,
"OPTCHECK: optimization"
,
i
,
"of"
,
len
(
li
),
"events was stable."
print
>>
sys
.
std
err
,
"OPTCHECK: optimization"
,
i
,
"of"
,
len
(
li
),
"events was stable."
else
:
else
:
env0
=
env
env0
=
env
...
@@ -1145,8 +1152,7 @@ class DebugMode(Mode):
...
@@ -1145,8 +1152,7 @@ class DebugMode(Mode):
If there are no internal errors, this mode behaves like FAST_RUN or FAST_COMPILE, but takes
If there are no internal errors, this mode behaves like FAST_RUN or FAST_COMPILE, but takes
a little longer and uses more memory.
a little longer and uses more memory.
If there are internal errors, this mode will raise an `DebugModeError` exception and write
If there are internal errors, this mode will raise an `DebugModeError` exception.
diagnostic information to a file.
:remark: The work of debugging is implemented by the `_Maker`, `_Linker`, and
:remark: The work of debugging is implemented by the `_Maker`, `_Linker`, and
`_VariableEquivalenceTracker` classes.
`_VariableEquivalenceTracker` classes.
...
@@ -1168,12 +1174,6 @@ class DebugMode(Mode):
...
@@ -1168,12 +1174,6 @@ class DebugMode(Mode):
Should we evaluate (and check) the `perform` implementations?
Should we evaluate (and check) the `perform` implementations?
"""
"""
diagnostic
=
None
"""
Log diagnostic information to this file.
"""
# This function will be used to create a FunctionMaker in
# This function will be used to create a FunctionMaker in
# function_module.function
# function_module.function
def
function_maker
(
self
,
i
,
o
,
m
,
*
args
,
**
kwargs
):
def
function_maker
(
self
,
i
,
o
,
m
,
*
args
,
**
kwargs
):
...
@@ -1185,8 +1185,7 @@ class DebugMode(Mode):
...
@@ -1185,8 +1185,7 @@ class DebugMode(Mode):
optimizer
=
'fast_run'
,
optimizer
=
'fast_run'
,
stability_patience
=
10
,
stability_patience
=
10
,
check_c_code
=
True
,
check_c_code
=
True
,
check_py_code
=
True
,
check_py_code
=
True
):
diagnostic
=
sys
.
stderr
):
"""Initialize member variables
"""Initialize member variables
"""
"""
if
not
(
check_c_code
or
check_py_code
):
if
not
(
check_c_code
or
check_py_code
):
...
@@ -1197,6 +1196,5 @@ class DebugMode(Mode):
...
@@ -1197,6 +1196,5 @@ class DebugMode(Mode):
self
.
stability_patience
=
stability_patience
self
.
stability_patience
=
stability_patience
self
.
check_c_code
=
check_c_code
self
.
check_c_code
=
check_c_code
self
.
check_py_code
=
check_py_code
self
.
check_py_code
=
check_py_code
self
.
diagnostic
=
diagnostic
register_mode
(
'DEBUG_MODE'
,
DebugMode
(
optimizer
=
'fast_run'
))
register_mode
(
'DEBUG_MODE'
,
DebugMode
(
optimizer
=
'fast_run'
))
theano/compile/tests/test_debugmode.py
浏览文件 @
49fc30bd
...
@@ -309,6 +309,38 @@ def test_badoptimization():
...
@@ -309,6 +309,38 @@ def test_badoptimization():
assert
False
assert
False
def
test_stochasticoptimization
():
# this optimization alternates between triggering and not triggering.
last_time_replaced
=
[
False
]
@gof.local_optimizer
([
theano
.
sparse
.
sd_csc
])
def
insert_broken_csc_sometimes
(
node
):
if
node
.
op
==
theano
.
sparse
.
sd_csc
:
last_time_replaced
[
0
]
=
not
last_time_replaced
[
0
]
if
last_time_replaced
[
0
]:
return
[
off_by_half
(
*
node
.
inputs
)]
return
False
edb
=
gof
.
EquilibriumDB
()
edb
.
register
(
'insert_broken_csc_sometimes'
,
insert_broken_csc_sometimes
,
'all'
)
opt
=
edb
.
query
(
'+all'
)
vals
=
theano
.
tensor
.
dvector
()
inds
=
theano
.
tensor
.
ivector
()
ptrs
=
theano
.
tensor
.
ivector
()
nrows
=
theano
.
tensor
.
iscalar
()
b
=
theano
.
tensor
.
dmatrix
()
try
:
f
=
theano
.
function
([
vals
,
inds
,
ptrs
,
nrows
,
b
],
theano
.
sparse
.
sd_csc
(
vals
,
inds
,
ptrs
,
nrows
,
b
),
mode
=
debugmode
.
DebugMode
(
optimizer
=
opt
,
check_c_code
=
True
))
except
debugmode
.
StochasticOrder
:
return
#TEST PASS
assert
False
def
test_just_c_code
():
def
test_just_c_code
():
x
=
theano
.
tensor
.
dvector
()
x
=
theano
.
tensor
.
dvector
()
f
=
theano
.
function
([
x
],
wb2
(
x
),
mode
=
debugmode
.
DebugMode
(
check_py_code
=
False
))
f
=
theano
.
function
([
x
],
wb2
(
x
),
mode
=
debugmode
.
DebugMode
(
check_py_code
=
False
))
...
@@ -331,7 +363,7 @@ def test_baddestroymap():
...
@@ -331,7 +363,7 @@ def test_baddestroymap():
f
([
1
,
2
],
[
3
,
4
])
f
([
1
,
2
],
[
3
,
4
])
assert
False
#failed to raise error
assert
False
#failed to raise error
except
debugmode
.
BadDestroyMap
:
except
debugmode
.
BadDestroyMap
:
return
pass
def
test_baddestroymap_c
():
def
test_baddestroymap_c
():
x
=
theano
.
tensor
.
dvector
()
x
=
theano
.
tensor
.
dvector
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论