Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f635bd3e
提交
f635bd3e
authored
3月 23, 2009
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge.
上级
7bbb1d0d
571c92bb
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
85 行增加
和
3 行删除
+85
-3
debugmode.py
theano/compile/debugmode.py
+48
-3
test_debugmode.py
theano/compile/tests/test_debugmode.py
+37
-0
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
f635bd3e
...
@@ -20,6 +20,13 @@ from ..compile.function_module import (FunctionMaker,
...
@@ -20,6 +20,13 @@ from ..compile.function_module import (FunctionMaker,
Supervisor
)
Supervisor
)
from
..compile.mode
import
Mode
,
register_mode
from
..compile.mode
import
Mode
,
register_mode
########################
#
# Exceptions
#
########################
class
DebugModeError
(
Exception
):
class
DebugModeError
(
Exception
):
"""Generic Exception raised to indicate an internal theano problem"""
"""Generic Exception raised to indicate an internal theano problem"""
pass
pass
...
@@ -106,7 +113,7 @@ class BadOptimization(DebugModeError):
...
@@ -106,7 +113,7 @@ class BadOptimization(DebugModeError):
return
sio
.
getvalue
()
return
sio
.
getvalue
()
class
BadDestroyMap
(
DebugModeError
):
class
BadDestroyMap
(
DebugModeError
):
"""
TODO #318
"""
"""
Exception: Some perform() or c_code() modified an input that wasn't in the destroy_map
"""
def
__init__
(
self
,
node
,
idx
,
old_val
,
new_val
):
def
__init__
(
self
,
node
,
idx
,
old_val
,
new_val
):
super
(
BadDestroyMap
,
self
)
.
__init__
()
super
(
BadDestroyMap
,
self
)
.
__init__
()
self
.
node
=
node
self
.
node
=
node
...
@@ -124,7 +131,29 @@ class BadDestroyMap(DebugModeError):
...
@@ -124,7 +131,29 @@ class BadDestroyMap(DebugModeError):
print
>>
sio
,
" repr (old val):"
,
repr
(
self
.
old_val
)
print
>>
sio
,
" repr (old val):"
,
repr
(
self
.
old_val
)
print
>>
sio
,
" repr (new val):"
,
repr
(
self
.
new_val
)
print
>>
sio
,
" repr (new val):"
,
repr
(
self
.
new_val
)
print
>>
sio
,
""
print
>>
sio
,
""
print
>>
sio
,
" Hint: this can be caused by a deficient values_eq_approx() or __eq__() implementation that compares node input values"
print
>>
sio
,
" Hint: this can also be caused by a deficient values_eq_approx() or __eq__() implementation that compares node input values"
return
sio
.
getvalue
()
class
BadViewMap
(
DebugModeError
):
"""Exception: Some perform() or c_code() created a memory alias that wasn't in the view_map"""
def
__init__
(
self
,
node
,
idx
,
old_val
,
new_val
):
super
(
BadViewMap
,
self
)
.
__init__
()
self
.
node
=
node
self
.
idx
=
idx
self
.
old_val
=
old_val
self
.
new_val
=
new_val
def
__str__
(
self
):
sio
=
StringIO
()
print
>>
sio
,
" node:"
,
self
.
node
print
>>
sio
,
" node.inputs:"
,
[(
str
(
i
),
id
(
i
))
for
i
in
self
.
node
.
inputs
]
print
>>
sio
,
" view_map:"
,
getattr
(
self
.
node
.
op
,
'view_map'
,
{})
print
>>
sio
,
" changed input idx:"
,
self
.
idx
print
>>
sio
,
" changed input type:"
,
self
.
node
.
inputs
[
self
.
idx
]
.
type
print
>>
sio
,
" repr (old val):"
,
repr
(
self
.
old_val
)
print
>>
sio
,
" repr (new val):"
,
repr
(
self
.
new_val
)
print
>>
sio
,
""
print
>>
sio
,
" Hint: this can also be caused by a deficient values_eq_approx() or __eq__() implementation that compares node input values"
return
sio
.
getvalue
()
return
sio
.
getvalue
()
class
StochasticOrder
(
DebugModeError
):
class
StochasticOrder
(
DebugModeError
):
...
@@ -132,7 +161,10 @@ class StochasticOrder(DebugModeError):
...
@@ -132,7 +161,10 @@ class StochasticOrder(DebugModeError):
pass
pass
class
FloatError
(
DebugModeError
):
class
FloatError
(
DebugModeError
):
"""TODO #320"""
"""Exception: Inf or NaN has crept into calculations
:note: See #320 for what this exception is for
"""
pass
pass
class
InvalidValueError
(
DebugModeError
):
class
InvalidValueError
(
DebugModeError
):
...
@@ -147,6 +179,14 @@ class InvalidValueError(DebugModeError):
...
@@ -147,6 +179,14 @@ class InvalidValueError(DebugModeError):
return
"InvalidValueError: Variable
%
s, Type
%
s, type(Value)
%
s, Value
%
s"
\
return
"InvalidValueError: Variable
%
s, Type
%
s, type(Value)
%
s, Value
%
s"
\
%
(
str
(
r
),
str
(
r
.
type
),
str
(
type
(
v
)),
str
(
v
)[
0
:
100
])
%
(
str
(
r
),
str
(
r
.
type
),
str
(
type
(
v
)),
str
(
v
)[
0
:
100
])
########################
#
# Private Functions
#
########################
def
_debugprint
(
r
,
prefix
=
''
,
depth
=-
1
,
done
=
None
,
file
=
sys
.
stdout
):
def
_debugprint
(
r
,
prefix
=
''
,
depth
=-
1
,
done
=
None
,
file
=
sys
.
stdout
):
"""Print the graph leading to `r` to given depth.
"""Print the graph leading to `r` to given depth.
...
@@ -927,6 +967,11 @@ class _Maker(FunctionMaker): #inheritance buys a few helper functions
...
@@ -927,6 +967,11 @@ class _Maker(FunctionMaker): #inheritance buys a few helper functions
return
fn
return
fn
########################
#
# API symbol: DebugMode
#
########################
class
DebugMode
(
Mode
):
class
DebugMode
(
Mode
):
"""Evaluation Mode that detects internal theano errors.
"""Evaluation Mode that detects internal theano errors.
...
...
theano/compile/tests/test_debugmode.py
浏览文件 @
f635bd3e
...
@@ -219,3 +219,40 @@ def test_badoptimization():
...
@@ -219,3 +219,40 @@ def test_badoptimization():
assert
False
assert
False
def
test_baddestroymap
():
class
BadAdd
(
gof
.
Op
):
def
make_node
(
self
,
a
,
b
):
c
=
a
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,)):
c
[
0
]
=
a
c
[
0
]
+=
b
x
=
theano
.
tensor
.
dvector
()
y
=
theano
.
tensor
.
dvector
()
f
=
theano
.
function
([
x
,
y
],
BadAdd
()(
x
,
y
),
mode
=
'DEBUG_MODE'
)
try
:
f
([
1
,
2
],
[
3
,
4
])
assert
False
#failed to raise error
except
debugmode
.
BadDestroyMap
:
return
def
test_badviewmap
():
class
BadAdd
(
gof
.
Op
):
def
make_node
(
self
,
a
,
b
):
c
=
b
.
type
()
return
gof
.
Apply
(
self
,
[
a
,
b
],
[
c
])
def
perform
(
self
,
node
,
(
a
,
b
),
(
c
,)):
c
[
0
]
=
b
x
=
theano
.
tensor
.
dvector
()
y
=
theano
.
tensor
.
dvector
()
f
=
theano
.
function
([
x
,
y
],
BadAdd
()(
x
,
y
),
mode
=
'DEBUG_MODE'
)
try
:
f
([
1
,
2
],
[
3
,
4
])
assert
False
#failed to raise error
except
debugmode
.
BadViewMap
:
return
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论