提交 7d09193b authored 作者: Frederic Bastien's avatar Frederic Bastien

In the old back-end, for float32 for tests

上级 6e45042c
...@@ -732,7 +732,7 @@ def test_batchnorm_train(): ...@@ -732,7 +732,7 @@ def test_batchnorm_train():
raise SkipTest("batch normalization requires cudnn v5+") raise SkipTest("batch normalization requires cudnn v5+")
utt.seed_rng() utt.seed_rng()
tensor6 = T.TensorType(theano.config.floatX, (False,) * 6) tensor6 = T.TensorType('float32', (False,) * 6)
for mode in ('per-activation', 'spatial'): for mode in ('per-activation', 'spatial'):
for vartype in (tensor6, T.ftensor5, T.ftensor4, T.ftensor3, T.fmatrix, T.fvector): for vartype in (tensor6, T.ftensor5, T.ftensor4, T.ftensor3, T.fmatrix, T.fvector):
...@@ -766,7 +766,7 @@ def test_batchnorm_train(): ...@@ -766,7 +766,7 @@ def test_batchnorm_train():
x_invstd_ref = T.inv(T.sqrt(x_var_ref + eps)) x_invstd_ref = T.inv(T.sqrt(x_var_ref + eps))
scale_ref = T.addbroadcast(scale, *axes) scale_ref = T.addbroadcast(scale, *axes)
bias_ref = T.addbroadcast(bias, *axes) bias_ref = T.addbroadcast(bias, *axes)
m = T.cast(T.prod(x.shape) / T.prod(scale.shape), theano.config.floatX) m = T.cast(T.prod(x.shape) / T.prod(scale.shape), 'float32')
out_ref = (x - x_mean_ref) * (scale_ref * x_invstd_ref) + bias_ref out_ref = (x - x_mean_ref) * (scale_ref * x_invstd_ref) + bias_ref
out_running_mean_ref = running_mean * (1 - running_average_factor) + \ out_running_mean_ref = running_mean * (1 - running_average_factor) + \
x_mean_ref * running_average_factor x_mean_ref * running_average_factor
...@@ -805,12 +805,12 @@ def test_batchnorm_train(): ...@@ -805,12 +805,12 @@ def test_batchnorm_train():
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))
X = 4 + 3 * numpy.random.randn(*data_shape).astype(theano.config.floatX) X = 4 + 3 * numpy.random.randn(*data_shape).astype('float32')
Dy = -1 + 2 * numpy.random.randn(*data_shape).astype(theano.config.floatX) Dy = -1 + 2 * numpy.random.randn(*data_shape).astype('float32')
Scale = numpy.random.randn(*param_shape).astype(theano.config.floatX) Scale = numpy.random.randn(*param_shape).astype('float32')
Bias = numpy.random.randn(*param_shape).astype(theano.config.floatX) Bias = numpy.random.randn(*param_shape).astype('float32')
Running_mean = numpy.random.randn(*param_shape).astype(theano.config.floatX) Running_mean = numpy.random.randn(*param_shape).astype('float32')
Running_var = numpy.random.randn(*param_shape).astype(theano.config.floatX) Running_var = numpy.random.randn(*param_shape).astype('float32')
outputs_gpu = f_gpu(X, Scale, Bias, Running_mean, Running_var, Dy) outputs_gpu = f_gpu(X, Scale, Bias, Running_mean, Running_var, Dy)
outputs_abstract = f_abstract(X, Scale, Bias, Running_mean, Running_var, Dy) outputs_abstract = f_abstract(X, Scale, Bias, Running_mean, Running_var, Dy)
outputs_ref = f_ref(X, Scale, Bias, Running_mean, Running_var, Dy) outputs_ref = f_ref(X, Scale, Bias, Running_mean, Running_var, Dy)
...@@ -844,7 +844,7 @@ def test_dnn_batchnorm_train_without_running_averages(): ...@@ -844,7 +844,7 @@ def test_dnn_batchnorm_train_without_running_averages():
raise SkipTest("batch normalization requires cudnn v5+") raise SkipTest("batch normalization requires cudnn v5+")
utt.seed_rng() utt.seed_rng()
x, scale, bias, dy = T.tensor4('x'), T.tensor4('scale'), T.tensor4('bias'), T.tensor4('dy') x, scale, bias, dy = T.ftensor4('x'), T.ftensor4('scale'), T.ftensor4('bias'), T.ftensor4('dy')
data_shape = (5, 10, 30, 25) data_shape = (5, 10, 30, 25)
param_shape = (1, 10, 30, 25) param_shape = (1, 10, 30, 25)
...@@ -875,10 +875,10 @@ def test_dnn_batchnorm_train_without_running_averages(): ...@@ -875,10 +875,10 @@ def test_dnn_batchnorm_train_without_running_averages():
bn.AbstractBatchNormTrainGrad)) bn.AbstractBatchNormTrainGrad))
for n in f_abstract.maker.fgraph.toposort()]) for n in f_abstract.maker.fgraph.toposort()])
# run # run
X = 4 + 3 * numpy.random.randn(*data_shape).astype(theano.config.floatX) X = 4 + 3 * numpy.random.randn(*data_shape).astype('float32')
Dy = -1 + 2 * numpy.random.randn(*data_shape).astype(theano.config.floatX) Dy = -1 + 2 * numpy.random.randn(*data_shape).astype('float32')
Scale = numpy.random.randn(*param_shape).astype(theano.config.floatX) Scale = numpy.random.randn(*param_shape).astype('float32')
Bias = numpy.random.randn(*param_shape).astype(theano.config.floatX) Bias = numpy.random.randn(*param_shape).astype('float32')
f_gpu(X, Scale, Bias, Dy) f_gpu(X, Scale, Bias, Dy)
f_abstract(X, Scale, Bias, Dy) f_abstract(X, Scale, Bias, Dy)
...@@ -891,14 +891,14 @@ def test_dnn_batchnorm_train_inplace(): ...@@ -891,14 +891,14 @@ def test_dnn_batchnorm_train_inplace():
raise SkipTest("batch normalization requires cudnn v5+") raise SkipTest("batch normalization requires cudnn v5+")
utt.seed_rng() utt.seed_rng()
x, scale, bias = T.tensor4('x'), T.tensor4('scale'), T.tensor4('bias') x, scale, bias = T.ftensor4('x'), T.ftensor4('scale'), T.ftensor4('bias')
data_shape = (5, 10, 30, 25) data_shape = (5, 10, 30, 25)
param_shape = (1, 10, 30, 25) param_shape = (1, 10, 30, 25)
running_mean = shared( running_mean = shared(
numpy.random.randn(*param_shape).astype(theano.config.floatX), numpy.random.randn(*param_shape).astype('float32'),
broadcastable=(True, False, False, False)) broadcastable=(True, False, False, False))
running_var = shared( running_var = shared(
numpy.random.randn(*param_shape).astype(theano.config.floatX), numpy.random.randn(*param_shape).astype('float32'),
broadcastable=(True, False, False, False)) broadcastable=(True, False, False, False))
# forward pass # forward pass
...@@ -923,9 +923,9 @@ def test_dnn_batchnorm_train_inplace(): ...@@ -923,9 +923,9 @@ def test_dnn_batchnorm_train_inplace():
assert nodes[0].op.inplace_running_var assert nodes[0].op.inplace_running_var
assert nodes[0].op.inplace_output assert nodes[0].op.inplace_output
# run # run
X = 4 + 3 * numpy.random.randn(*data_shape).astype(theano.config.floatX) X = 4 + 3 * numpy.random.randn(*data_shape).astype('float32')
Scale = numpy.random.randn(*param_shape).astype(theano.config.floatX) Scale = numpy.random.randn(*param_shape).astype('float32')
Bias = numpy.random.randn(*param_shape).astype(theano.config.floatX) Bias = numpy.random.randn(*param_shape).astype('float32')
f(X, Scale, Bias) f(X, Scale, Bias)
...@@ -936,10 +936,10 @@ def test_batchnorm_inference(): ...@@ -936,10 +936,10 @@ def test_batchnorm_inference():
raise SkipTest("batch normalization requires cudnn v5+") raise SkipTest("batch normalization requires cudnn v5+")
utt.seed_rng() utt.seed_rng()
tensor6 = T.TensorType(theano.config.floatX, (False,) * 6) tensor6 = T.TensorType('float32', (False,) * 6)
for mode in ('per-activation', 'spatial'): for mode in ('per-activation', 'spatial'):
for vartype in (tensor6, T.tensor5, T.tensor4, T.tensor3, T.matrix, T.vector): for vartype in (tensor6, T.ftensor5, T.ftensor4, T.ftensor3, T.fmatrix, T.fvector):
x, scale, bias, mean, var = (vartype(n) x, scale, bias, mean, var = (vartype(n)
for n in ('x', 'scale', 'bias', 'mean', 'var')) for n in ('x', 'scale', 'bias', 'mean', 'var'))
ndim = x.ndim ndim = x.ndim
...@@ -984,12 +984,12 @@ def test_batchnorm_inference(): ...@@ -984,12 +984,12 @@ def test_batchnorm_inference():
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))
X = 4 + 3 * numpy.random.randn(*data_shape).astype(theano.config.floatX) X = 4 + 3 * numpy.random.randn(*data_shape).astype('float32')
Dy = -1 + 2 * numpy.random.randn(*data_shape).astype(theano.config.floatX) Dy = -1 + 2 * numpy.random.randn(*data_shape).astype('float32')
Scale = numpy.random.randn(*param_shape).astype(theano.config.floatX) Scale = numpy.random.randn(*param_shape).astype('float32')
Bias = numpy.random.randn(*param_shape).astype(theano.config.floatX) Bias = numpy.random.randn(*param_shape).astype('float32')
Mean = numpy.random.randn(*param_shape).astype(theano.config.floatX) Mean = numpy.random.randn(*param_shape).astype('float32')
Var = numpy.random.rand(*param_shape).astype(theano.config.floatX) Var = numpy.random.rand(*param_shape).astype('float32')
outputs_gpu = f_gpu(X, Scale, Bias, Mean, Var, Dy) outputs_gpu = f_gpu(X, Scale, Bias, Mean, Var, Dy)
outputs_abstract = f_abstract(X, Scale, Bias, Mean, Var, Dy) outputs_abstract = f_abstract(X, Scale, Bias, Mean, Var, Dy)
outputs_ref = f_ref(X, Scale, Bias, Mean, Var, Dy) outputs_ref = f_ref(X, Scale, Bias, Mean, Var, Dy)
...@@ -1017,7 +1017,7 @@ def test_batchnorm_inference_inplace(): ...@@ -1017,7 +1017,7 @@ def test_batchnorm_inference_inplace():
raise SkipTest("batch normalization requires cudnn v5+") raise SkipTest("batch normalization requires cudnn v5+")
utt.seed_rng() utt.seed_rng()
x, scale, bias, mean, var = (T.tensor4(n) for n in ('x', 'scale', 'bias', 'mean', 'var')) x, scale, bias, mean, var = (T.ftensor4(n) for n in ('x', 'scale', 'bias', 'mean', 'var'))
data_shape = (5, 10, 30, 25) data_shape = (5, 10, 30, 25)
param_shape = (1, 10, 30, 25) param_shape = (1, 10, 30, 25)
...@@ -1031,11 +1031,11 @@ def test_batchnorm_inference_inplace(): ...@@ -1031,11 +1031,11 @@ def test_batchnorm_inference_inplace():
assert nodes[0].op.inplace assert nodes[0].op.inplace
# run # run
X = 4 + 3 * numpy.random.randn(*data_shape).astype(theano.config.floatX) X = 4 + 3 * numpy.random.randn(*data_shape).astype('float32')
Scale = numpy.random.randn(*param_shape).astype(theano.config.floatX) Scale = numpy.random.randn(*param_shape).astype('float32')
Bias = numpy.random.randn(*param_shape).astype(theano.config.floatX) Bias = numpy.random.randn(*param_shape).astype('float32')
Mean = numpy.random.randn(*param_shape).astype(theano.config.floatX) Mean = numpy.random.randn(*param_shape).astype('float32')
Var = numpy.random.rand(*param_shape).astype(theano.config.floatX) Var = numpy.random.rand(*param_shape).astype('float32')
f(X, Scale, Bias, Mean, Var) f(X, Scale, Bias, Mean, Var)
...@@ -1045,7 +1045,7 @@ def test_dnn_batchnorm_valid_and_invalid_axes(): ...@@ -1045,7 +1045,7 @@ def test_dnn_batchnorm_valid_and_invalid_axes():
if cuda.dnn.version() < (5000, 5000): if cuda.dnn.version() < (5000, 5000):
raise SkipTest("batch normalization requires cudnn v5+") raise SkipTest("batch normalization requires cudnn v5+")
for vartype in (T.tensor5, T.tensor4, T.tensor3, T.matrix): for vartype in (T.ftensor5, T.ftensor4, T.ftensor3, T.fmatrix):
x, scale, bias, mean, var, dy = (vartype(n) x, scale, bias, mean, var, dy = (vartype(n)
for n in ('x', 'scale', 'bias', 'mean', 'var', 'dy')) for n in ('x', 'scale', 'bias', 'mean', 'var', 'dy'))
ndim = x.ndim ndim = x.ndim
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论