提交 c2cd739b authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #3229 from nouiz/nanguardmode

[CRASH]Nanguardmode
...@@ -54,6 +54,8 @@ def contains_nan(arr): ...@@ -54,6 +54,8 @@ def contains_nan(arr):
alternative, calling `np.any(np.isnan(ndarray))`, which requires the alternative, calling `np.any(np.isnan(ndarray))`, which requires the
construction of a boolean array with the same shape as the input array. construction of a boolean array with the same shape as the input array.
""" """
if isinstance(arr, theano.gof.type.CDataType._cdata_type):
return False
return np.isnan(np.min(arr)) return np.isnan(np.min(arr))
...@@ -78,6 +80,8 @@ def contains_inf(arr): ...@@ -78,6 +80,8 @@ def contains_inf(arr):
calling `np.any(np.isinf(ndarray))`, which requires the construction of a calling `np.any(np.isinf(ndarray))`, which requires the construction of a
boolean array with the same shape as the input array. boolean array with the same shape as the input array.
""" """
if isinstance(arr, theano.gof.type.CDataType._cdata_type):
return False
return np.isinf(np.nanmax(arr)) or np.isinf(np.nanmin(arr)) return np.isinf(np.nanmax(arr)) or np.isinf(np.nanmin(arr))
...@@ -158,6 +162,8 @@ class NanGuardMode(Mode): ...@@ -158,6 +162,8 @@ class NanGuardMode(Mode):
err = False err = False
if cuda.cuda_available and isinstance(var, cuda.CudaNdarray): if cuda.cuda_available and isinstance(var, cuda.CudaNdarray):
err = (self.gpuabsmax(var.reshape(var.size)) > 1e10) err = (self.gpuabsmax(var.reshape(var.size)) > 1e10)
elif isinstance(var, theano.gof.type.CDataType._cdata_type):
err = False
else: else:
err = (np.abs(var).max() > 1e10) err = (np.abs(var).max() > 1e10)
if err: if err:
...@@ -201,7 +207,7 @@ class NanGuardMode(Mode): ...@@ -201,7 +207,7 @@ class NanGuardMode(Mode):
for j, x in enumerate(flatten(outputs)): for j, x in enumerate(flatten(outputs)):
do_check_on(x, node, fn, False) do_check_on(x, node, fn, False)
wrap_linker = theano.gof.WrapLinkerMany([theano.gof.OpWiseCLinker()], wrap_linker = theano.gof.WrapLinker([theano.gof.OpWiseCLinker()],
[nan_check]) nan_check)
super(NanGuardMode, self).__init__(wrap_linker, super(NanGuardMode, self).__init__(wrap_linker,
optimizer=theano.config.optimizer) optimizer=theano.config.optimizer)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论