Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3220e103
提交
3220e103
authored
8月 04, 2016
作者:
Frédéric Bastien
提交者:
GitHub
8月 04, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4808 from nouiz/nanguardmode
Add the user stack trace printing in nanguardmode
上级
dac8f3ea
f97b10df
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
13 行删除
+21
-13
nanguardmode.py
theano/compile/nanguardmode.py
+21
-13
没有找到文件。
theano/compile/nanguardmode.py
浏览文件 @
3220e103
...
@@ -215,44 +215,47 @@ class NanGuardMode(Mode):
...
@@ -215,44 +215,47 @@ class NanGuardMode(Mode):
assert
nan_is_error
or
inf_is_error
or
big_is_error
assert
nan_is_error
or
inf_is_error
or
big_is_error
compile_gpu_func
(
nan_is_error
,
inf_is_error
,
big_is_error
)
compile_gpu_func
(
nan_is_error
,
inf_is_error
,
big_is_error
)
def
do_check_on
(
va
r
,
nd
):
def
do_check_on
(
va
lue
,
nd
,
var
=
None
):
"""
"""
Checks `va
r
` for NaNs / Infs. If detected, raises an exception
Checks `va
lue
` for NaNs / Infs. If detected, raises an exception
and / or prints information about `nd`, `f`, and `is_input` to
and / or prints information about `nd`, `f`, and `is_input` to
help the user determine the cause of the invalid values.
help the user determine the cause of the invalid values.
Parameters
Parameters
----------
----------
va
r
: numpy.ndarray
va
lue
: numpy.ndarray
The value to be checked.
The value to be checked.
nd : theano.gof.Apply
nd : theano.gof.Apply
The Apply node being executed.
The Apply node being executed.
var : theano.gof.Variable
Not used if nd is there. Otherwise, used to print the stack
trace for inputs of the graph.
"""
"""
error
=
False
error
=
False
sio
=
StringIO
()
sio
=
StringIO
()
if
nan_is_error
:
if
nan_is_error
:
if
contains_nan
(
va
r
,
nd
):
if
contains_nan
(
va
lue
,
nd
):
print
(
'NaN detected'
,
file
=
sio
)
print
(
'NaN detected'
,
file
=
sio
)
error
=
True
error
=
True
if
inf_is_error
:
if
inf_is_error
:
if
contains_inf
(
va
r
,
nd
):
if
contains_inf
(
va
lue
,
nd
):
print
(
'Inf detected'
,
file
=
sio
)
print
(
'Inf detected'
,
file
=
sio
)
error
=
True
error
=
True
if
big_is_error
:
if
big_is_error
:
err
=
False
err
=
False
if
isinstance
(
va
r
,
theano
.
gof
.
type
.
CDataType
.
_cdata_type
):
if
isinstance
(
va
lue
,
theano
.
gof
.
type
.
CDataType
.
_cdata_type
):
err
=
False
err
=
False
elif
isinstance
(
va
r
,
np
.
random
.
mtrand
.
RandomState
):
elif
isinstance
(
va
lue
,
np
.
random
.
mtrand
.
RandomState
):
err
=
False
err
=
False
elif
isinstance
(
va
r
,
slice
):
elif
isinstance
(
va
lue
,
slice
):
err
=
False
err
=
False
elif
va
r
.
size
==
0
:
elif
va
lue
.
size
==
0
:
err
=
False
err
=
False
elif
cuda
.
cuda_available
and
isinstance
(
va
r
,
cuda
.
CudaNdarray
):
elif
cuda
.
cuda_available
and
isinstance
(
va
lue
,
cuda
.
CudaNdarray
):
err
=
(
f_gpuabsmax
(
va
r
.
reshape
(
var
.
size
))
>
1e10
)
err
=
(
f_gpuabsmax
(
va
lue
.
reshape
(
value
.
size
))
>
1e10
)
else
:
else
:
err
=
(
np
.
abs
(
va
r
)
.
max
()
>
1e10
)
err
=
(
np
.
abs
(
va
lue
)
.
max
()
>
1e10
)
if
err
:
if
err
:
print
(
'Big value detected'
,
file
=
sio
)
print
(
'Big value detected'
,
file
=
sio
)
error
=
True
error
=
True
...
@@ -264,6 +267,11 @@ class NanGuardMode(Mode):
...
@@ -264,6 +267,11 @@ class NanGuardMode(Mode):
else
:
else
:
print
(
"NanGuardMode found an error in an input of the "
print
(
"NanGuardMode found an error in an input of the "
"graph."
,
file
=
sio
)
"graph."
,
file
=
sio
)
# Add the stack trace
if
nd
:
var
=
nd
.
outputs
[
0
]
print
(
theano
.
gof
.
utils
.
get_variable_trace_string
(
var
),
file
=
sio
)
msg
=
sio
.
getvalue
()
msg
=
sio
.
getvalue
()
if
config
.
NanGuardMode
.
action
==
'raise'
:
if
config
.
NanGuardMode
.
action
==
'raise'
:
raise
AssertionError
(
msg
)
raise
AssertionError
(
msg
)
...
@@ -281,7 +289,7 @@ class NanGuardMode(Mode):
...
@@ -281,7 +289,7 @@ class NanGuardMode(Mode):
def
nan_check_input
(
var
,
value
):
def
nan_check_input
(
var
,
value
):
if
getattr
(
var
.
tag
,
'nan_guard_mode_check'
,
True
):
if
getattr
(
var
.
tag
,
'nan_guard_mode_check'
,
True
):
do_check_on
(
value
,
None
)
do_check_on
(
value
,
None
,
var
=
var
)
wrap_linker
=
theano
.
gof
.
vm
.
VM_Linker
(
callback
=
nan_check
,
wrap_linker
=
theano
.
gof
.
vm
.
VM_Linker
(
callback
=
nan_check
,
callback_input
=
nan_check_input
)
callback_input
=
nan_check_input
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论