提交 2cae7176 authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix some tests in DebugMode. Shapes where cause nan, division by zeros. precison…

Fix some tests in DebugMode. Shapes where cause nan, division by zeros. precison check was too high due to different order of operation on the GPU.
上级 19656a1f
...@@ -1451,7 +1451,7 @@ def test_dnn_batchnorm_train(): ...@@ -1451,7 +1451,7 @@ def test_dnn_batchnorm_train():
bn.AbstractBatchNormTrainGrad)) for n bn.AbstractBatchNormTrainGrad)) for n
in f_abstract.maker.fgraph.toposort()]) in f_abstract.maker.fgraph.toposort()])
# run # run
for data_shape in ((5, 10, 30, 4, 10, 5), (4, 3, 1, 1, 1, 1), (1, 1, 5, 5, 5, 5)): for data_shape in ((5, 10, 30, 4, 10, 5), (4, 3, 1, 1, 1, 1), (2, 3, 5, 5, 5, 5)):
data_shape = data_shape[:ndim] data_shape = data_shape[:ndim]
param_shape = tuple(1 if d in axes else s param_shape = tuple(1 if d in axes else s
for d, s in enumerate(data_shape)) for d, s in enumerate(data_shape))
......
...@@ -3705,6 +3705,19 @@ def local_gpu_batch_norm_inference_inplace(node): ...@@ -3705,6 +3705,19 @@ def local_gpu_batch_norm_inference_inplace(node):
inplace=True)(*node.inputs)] inplace=True)(*node.inputs)]
def values_eq_approx_high_tol(a, b):
"""
This fct is needed to don't have DebugMode raise useless
error due to ronding error.
This happen as We reduce on the two last dimensions, so this
can raise the absolute error if the number of element we
reduce on is significant.
"""
return tensor.TensorType.values_eq_approx(a, b, atol=0.015)
@local_optimizer([bn.AbstractBatchNormTrainGrad]) @local_optimizer([bn.AbstractBatchNormTrainGrad])
def local_abstract_batch_norm_train_grad_cudnn(node): def local_abstract_batch_norm_train_grad_cudnn(node):
if not isinstance(node.op, bn.AbstractBatchNormTrainGrad): if not isinstance(node.op, bn.AbstractBatchNormTrainGrad):
...@@ -3781,6 +3794,9 @@ def local_abstract_batch_norm_train_grad_cudnn(node): ...@@ -3781,6 +3794,9 @@ def local_abstract_batch_norm_train_grad_cudnn(node):
if isinstance(node.outputs[2].type, tensor.TensorType): if isinstance(node.outputs[2].type, tensor.TensorType):
g_wrt_bias = tensor.as_tensor_variable(g_wrt_bias) g_wrt_bias = tensor.as_tensor_variable(g_wrt_bias)
# TODO copy_stack_trace? # TODO copy_stack_trace?
g_wrt_inputs.tag.values_eq_approx = values_eq_approx_high_tol
g_wrt_scale.tag.values_eq_approx = values_eq_approx_high_tol
return [g_wrt_inputs, g_wrt_scale, g_wrt_bias] return [g_wrt_inputs, g_wrt_scale, g_wrt_bias]
......
...@@ -801,7 +801,7 @@ def test_batchnorm_train(): ...@@ -801,7 +801,7 @@ def test_batchnorm_train():
bn.AbstractBatchNormTrainGrad)) for n bn.AbstractBatchNormTrainGrad)) for n
in f_abstract.maker.fgraph.toposort()]) in f_abstract.maker.fgraph.toposort()])
# run # run
for data_shape in ((5, 2, 30, 4, 10, 5), (4, 3, 1, 1, 1, 1), (1, 1, 5, 5, 5, 5)): for data_shape in ((5, 2, 30, 4, 10, 5), (4, 3, 1, 1, 1, 1), (2, 3, 5, 5, 5, 5)):
data_shape = data_shape[:ndim] data_shape = data_shape[:ndim]
param_shape = tuple(1 if d in axes else s param_shape = tuple(1 if d in axes else s
for d, s in enumerate(data_shape)) for d, s in enumerate(data_shape))
...@@ -980,7 +980,7 @@ def test_batchnorm_inference(): ...@@ -980,7 +980,7 @@ def test_batchnorm_inference():
bn.AbstractBatchNormTrainGrad)) for n bn.AbstractBatchNormTrainGrad)) for n
in f_abstract.maker.fgraph.toposort()]) in f_abstract.maker.fgraph.toposort()])
# run # run
for data_shape in ((10, 2, 30, 4, 10, 5), (4, 3, 1, 1, 1, 1), (1, 1, 5, 5, 5, 5)): for data_shape in ((10, 2, 15, 4, 6, 5), (4, 3, 1, 1, 1, 1), (1, 1, 5, 5, 5, 5)):
data_shape = data_shape[:ndim] data_shape = data_shape[:ndim]
param_shape = tuple(1 if d in axes else s param_shape = tuple(1 if d in axes else s
for d, s in enumerate(data_shape)) for d, s in enumerate(data_shape))
......
...@@ -201,7 +201,7 @@ def test_batch_normalization_train(): ...@@ -201,7 +201,7 @@ def test_batch_normalization_train():
bn.AbstractBatchNormTrainGrad)) bn.AbstractBatchNormTrainGrad))
for n in f.maker.fgraph.toposort()]) for n in f.maker.fgraph.toposort()])
# run # run
for data_shape in ((5, 10, 30, 40, 10), (4, 3, 1, 1, 1), (1, 1, 5, 5, 5)): for data_shape in ((5, 10, 30, 40, 10), (4, 3, 1, 1, 1), (2, 3, 5, 5, 5)):
data_shape = data_shape[:ndim] data_shape = data_shape[:ndim]
param_shape = tuple(1 if d in axes2 else s param_shape = tuple(1 if d in axes2 else s
for d, s in enumerate(data_shape)) for d, s in enumerate(data_shape))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论