Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e4404a6f
提交
e4404a6f
authored
9月 10, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make NanGuardMode work with array of size 0 and refactoring
上级
3b77021a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
72 行增加
和
55 行删除
+72
-55
nanguardmode.py
theano/compile/nanguardmode.py
+72
-55
没有找到文件。
theano/compile/nanguardmode.py
浏览文件 @
e4404a6f
...
@@ -80,6 +80,17 @@ def contains_nan(arr):
...
@@ -80,6 +80,17 @@ def contains_nan(arr):
return
False
return
False
elif
isinstance
(
arr
,
np
.
random
.
mtrand
.
RandomState
):
elif
isinstance
(
arr
,
np
.
random
.
mtrand
.
RandomState
):
return
False
return
False
elif
arr
.
size
==
0
:
return
False
elif
cuda
.
cuda_available
and
isinstance
(
arr
,
cuda
.
CudaNdarray
):
compile_gpu_func
(
True
,
False
,
False
)
if
(
not
hasattr
(
theano
.
sandbox
,
'rng_mrg'
)
or
not
isinstance
(
nd
.
op
,
# It store ints in float container
theano
.
sandbox
.
rng_mrg
.
GPU_mrg_uniform
)):
return
np
.
isnan
(
f_gpumin
(
arr
.
reshape
(
arr
.
size
)))
return
np
.
isnan
(
np
.
min
(
arr
))
return
np
.
isnan
(
np
.
min
(
arr
))
...
@@ -109,8 +120,62 @@ def contains_inf(arr):
...
@@ -109,8 +120,62 @@ def contains_inf(arr):
return
False
return
False
elif
isinstance
(
arr
,
np
.
random
.
mtrand
.
RandomState
):
elif
isinstance
(
arr
,
np
.
random
.
mtrand
.
RandomState
):
return
False
return
False
elif
arr
.
size
==
0
:
return
False
elif
cuda
.
cuda_available
and
isinstance
(
arr
,
cuda
.
CudaNdarray
):
compile_gpu_func
(
False
,
True
,
False
)
return
(
np
.
isinf
(
f_gpumin
(
arr
.
reshape
(
arr
.
size
)))
or
np
.
isinf
(
f_gpumax
(
arr
.
reshape
(
arr
.
size
))))
return
np
.
isinf
(
np
.
nanmax
(
arr
))
or
np
.
isinf
(
np
.
nanmin
(
arr
))
return
np
.
isinf
(
np
.
nanmax
(
arr
))
or
np
.
isinf
(
np
.
nanmin
(
arr
))
f_gpumin
=
None
f_gpumax
=
None
f_gpuabsmax
=
None
def
compile_gpu_func
(
nan_is_error
,
inf_is_error
,
big_is_error
):
""" compile utility function used by contains_nan and contains_inf
"""
global
f_gpumin
,
f_gpumax
,
f_gpuabsmax
if
not
cuda
.
cuda_available
:
return
guard_input
=
cuda
.
fvector
(
'nan_guard'
)
cuda_compile_failed
=
False
if
(
nan_is_error
or
inf_is_error
)
and
f_gpumin
is
None
:
try
:
f_gpumin
=
theano
.
function
(
[
guard_input
],
T
.
min
(
guard_input
),
mode
=
'FAST_RUN'
)
except
RuntimeError
:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed
=
True
if
inf_is_error
and
not
cuda_compile_failed
and
f_gpumax
is
None
:
try
:
f_gpumax
=
theano
.
function
(
[
guard_input
],
T
.
max
(
guard_input
),
mode
=
'FAST_RUN'
)
except
RuntimeError
:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed
=
True
if
big_is_error
and
not
cuda_compile_failed
and
f_gpuabsmax
is
None
:
try
:
f_gpuabsmax
=
theano
.
function
(
[
guard_input
],
T
.
max
(
T
.
abs_
(
guard_input
)),
mode
=
'FAST_RUN'
)
except
RuntimeError
:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed
=
True
class
NanGuardMode
(
Mode
):
class
NanGuardMode
(
Mode
):
"""
"""
...
@@ -137,7 +202,6 @@ class NanGuardMode(Mode):
...
@@ -137,7 +202,6 @@ class NanGuardMode(Mode):
def
__init__
(
self
,
nan_is_error
=
None
,
inf_is_error
=
None
,
big_is_error
=
None
,
def
__init__
(
self
,
nan_is_error
=
None
,
inf_is_error
=
None
,
big_is_error
=
None
,
optimizer
=
None
,
linker
=
None
):
optimizer
=
None
,
linker
=
None
):
self
.
provided_optimizer
=
optimizer
self
.
provided_optimizer
=
optimizer
cuda_compile_failed
=
False
if
nan_is_error
is
None
:
if
nan_is_error
is
None
:
nan_is_error
=
config
.
NanGuardMode
.
nan_is_error
nan_is_error
=
config
.
NanGuardMode
.
nan_is_error
if
inf_is_error
is
None
:
if
inf_is_error
is
None
:
...
@@ -146,42 +210,7 @@ class NanGuardMode(Mode):
...
@@ -146,42 +210,7 @@ class NanGuardMode(Mode):
big_is_error
=
config
.
NanGuardMode
.
big_is_error
big_is_error
=
config
.
NanGuardMode
.
big_is_error
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
)
if
cuda
.
cuda_available
:
self
.
guard_input
=
cuda
.
fvector
(
'nan_guard'
)
if
nan_is_error
or
inf_is_error
:
try
:
self
.
gpumin
=
theano
.
function
(
[
self
.
guard_input
],
T
.
min
(
self
.
guard_input
),
mode
=
'FAST_RUN'
)
except
RuntimeError
:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed
=
True
if
inf_is_error
and
not
cuda_compile_failed
:
try
:
self
.
gpumax
=
theano
.
function
(
[
self
.
guard_input
],
T
.
max
(
self
.
guard_input
),
mode
=
'FAST_RUN'
)
except
RuntimeError
:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed
=
True
if
big_is_error
and
not
cuda_compile_failed
:
try
:
self
.
gpuabsmax
=
theano
.
function
(
[
self
.
guard_input
],
T
.
max
(
T
.
abs_
(
self
.
guard_input
)),
mode
=
'FAST_RUN'
)
except
RuntimeError
:
# This can happen if cuda is available, but the
# device is in exclusive mode and used by another
# process.
cuda_compile_failed
=
True
def
do_check_on
(
var
,
nd
,
f
,
is_input
):
def
do_check_on
(
var
,
nd
,
f
,
is_input
):
"""
"""
...
@@ -204,31 +233,19 @@ class NanGuardMode(Mode):
...
@@ -204,31 +233,19 @@ class NanGuardMode(Mode):
"""
"""
error
=
False
error
=
False
if
nan_is_error
:
if
nan_is_error
:
err
=
False
if
contains_nan
(
var
):
if
cuda
.
cuda_available
and
isinstance
(
var
,
cuda
.
CudaNdarray
):
if
not
isinstance
(
nd
.
op
,
# It store ints in float container
theano
.
sandbox
.
rng_mrg
.
GPU_mrg_uniform
):
err
=
np
.
isnan
(
self
.
gpumin
(
var
.
reshape
(
var
.
size
)))
else
:
err
=
contains_nan
(
var
)
if
err
:
logger
.
error
(
'NaN detected'
)
logger
.
error
(
'NaN detected'
)
error
=
True
error
=
True
if
inf_is_error
:
if
inf_is_error
:
err
=
False
if
contains_inf
(
var
):
if
cuda
.
cuda_available
and
isinstance
(
var
,
cuda
.
CudaNdarray
):
err
=
(
np
.
isinf
(
self
.
gpumin
(
var
.
reshape
(
var
.
size
)))
or
np
.
isinf
(
self
.
gpumax
(
var
.
reshape
(
var
.
size
))))
else
:
err
=
contains_inf
(
var
)
if
err
:
logger
.
error
(
'Inf detected'
)
logger
.
error
(
'Inf detected'
)
error
=
True
error
=
True
if
big_is_error
:
if
big_is_error
:
err
=
False
err
=
False
if
cuda
.
cuda_available
and
isinstance
(
var
,
cuda
.
CudaNdarray
):
if
var
.
size
==
0
:
err
=
(
self
.
gpuabsmax
(
var
.
reshape
(
var
.
size
))
>
1e10
)
err
=
False
elif
cuda
.
cuda_available
and
isinstance
(
var
,
cuda
.
CudaNdarray
):
err
=
(
f_gpuabsmax
(
var
.
reshape
(
var
.
size
))
>
1e10
)
elif
isinstance
(
var
,
theano
.
gof
.
type
.
CDataType
.
_cdata_type
):
elif
isinstance
(
var
,
theano
.
gof
.
type
.
CDataType
.
_cdata_type
):
err
=
False
err
=
False
elif
isinstance
(
var
,
np
.
random
.
mtrand
.
RandomState
):
elif
isinstance
(
var
,
np
.
random
.
mtrand
.
RandomState
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论