From f4379a9149f38e2bb3f29ab9b02e3a173fd745de Mon Sep 17 00:00:00 2001 From: juncaipeng <52520497+juncaipeng@users.noreply.github.com> Date: Fri, 20 Dec 2019 10:55:23 +0800 Subject: [PATCH] Update the precision of some op tests from fp32 to fp64 (#21847) --- .../tests/unittests/test_sequence_concat.py | 4 +-- .../tests/unittests/test_sequence_expand.py | 28 +++++++-------- .../unittests/test_sequence_expand_as.py | 16 ++++----- .../tests/unittests/test_sequence_pad_op.py | 16 ++++----- .../tests/unittests/test_sequence_reshape.py | 12 +++---- .../unittests/test_sequence_scatter_op.py | 4 +-- .../unittests/test_sequence_softmax_op.py | 4 +-- .../tests/unittests/test_sequence_unpad_op.py | 4 +-- ...st_sigmoid_cross_entropy_with_logits_op.py | 28 +++++++-------- .../unittests/test_sigmoid_focal_loss_op.py | 4 +-- .../fluid/tests/unittests/test_sign_op.py | 2 +- .../fluid/tests/unittests/test_slice_op.py | 36 +++++++++---------- .../fluid/tests/unittests/test_softmax_op.py | 2 +- .../test_softmax_with_cross_entropy_op.py | 6 ++-- .../tests/unittests/test_space_to_depth_op.py | 16 ++++----- .../tests/unittests/test_spectral_norm_op.py | 6 ++-- .../fluid/tests/unittests/test_split_op.py | 10 +++--- .../fluid/tests/unittests/test_spp_op.py | 6 ++-- 18 files changed, 102 insertions(+), 102 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_sequence_concat.py b/python/paddle/fluid/tests/unittests/test_sequence_concat.py index 52757719986..2dacbb5ae99 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_concat.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_concat.py @@ -26,8 +26,8 @@ class TestSequenceConcat(OpTest): self.out_lod = [19, 11] def setUp(self): - x1 = np.random.random(size=(10, 80)).astype('float32') - x2 = np.random.random(size=(20, 80)).astype('float32') + x1 = np.random.random(size=(10, 80)).astype('float64') + x2 = np.random.random(size=(20, 80)).astype('float64') self.setLoD() out = np.concatenate((x1[0:self.lod1[0]], x2[0:self.lod2[0]], diff --git a/python/paddle/fluid/tests/unittests/test_sequence_expand.py b/python/paddle/fluid/tests/unittests/test_sequence_expand.py index 8c5202e3a75..41d2b8bea49 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_expand.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_expand.py @@ -21,8 +21,8 @@ from op_test import OpTest class TestSequenceExpand(OpTest): def set_data(self): - x_data = np.random.uniform(0.1, 1, [3, 40]).astype('float32') - y_data = np.random.uniform(0.1, 1, [8, 1]).astype('float32') + x_data = np.random.uniform(0.1, 1, [3, 40]).astype('float64') + y_data = np.random.uniform(0.1, 1, [8, 1]).astype('float64') y_lod = [[1, 3, 4]] self.inputs = {'X': x_data, 'Y': (y_data, y_lod)} @@ -80,8 +80,8 @@ class TestSequenceExpand(OpTest): class TestSequenceExpandCase1(TestSequenceExpand): def set_data(self): - x_data = np.random.uniform(0.1, 1, [5, 1]).astype('float32') - y_data = np.random.uniform(0.1, 1, [13, 1]).astype('float32') + x_data = np.random.uniform(0.1, 1, [5, 1]).astype('float64') + y_data = np.random.uniform(0.1, 1, [13, 1]).astype('float64') y_lod = [[2, 3], [2, 2, 3, 3, 3]] self.inputs = {'X': x_data, 'Y': (y_data, y_lod)} self.attrs = {'ref_level': 1} @@ -89,9 +89,9 @@ class TestSequenceExpandCase1(TestSequenceExpand): class TestSequenceExpandCase2(TestSequenceExpand): def set_data(self): - x_data = np.random.uniform(0.1, 1, [1, 2, 2]).astype('float32') + x_data = np.random.uniform(0.1, 1, [1, 2, 2]).astype('float64') x_lod = [[1]] - y_data = np.random.uniform(0.1, 1, [2, 2, 2]).astype('float32') + y_data = np.random.uniform(0.1, 1, [2, 2, 2]).astype('float64') y_lod = [[2], [1, 1]] self.inputs = {'X': (x_data, x_lod), 'Y': (y_data, y_lod)} self.attrs = {'ref_level': 0} @@ -99,9 +99,9 @@ class TestSequenceExpandCase2(TestSequenceExpand): class TestSequenceExpandCase3(TestSequenceExpand): def set_data(self): - x_data = np.random.uniform(0.1, 1, [4, 1]).astype('float32') + x_data = np.random.uniform(0.1, 1, [4, 1]).astype('float64') x_lod = [[1, 1, 1, 1]] - y_data = np.random.uniform(0.1, 1, [8, 1]).astype('float32') + y_data = np.random.uniform(0.1, 1, [8, 1]).astype('float64') y_lod = [[2, 2, 2, 2]] self.inputs = {'X': (x_data, x_lod), 'Y': (y_data, y_lod)} @@ -109,17 +109,17 @@ class TestSequenceExpandCase3(TestSequenceExpand): class TestSequenceExpandCase4(TestSequenceExpand): def set_data(self): data = np.random.uniform(0.1, 1, [5 * 2, 1]) - x_data = np.array(data).reshape([5, 2]).astype('float32') + x_data = np.array(data).reshape([5, 2]).astype('float64') x_lod = [[2, 3]] - y_data = np.random.uniform(0.1, 1, [5, 1]).astype('float32') + y_data = np.random.uniform(0.1, 1, [5, 1]).astype('float64') y_lod = [[2], [2, 3]] self.inputs = {'X': (x_data, x_lod), 'Y': (y_data, y_lod)} class TestSequenceExpandCase5(TestSequenceExpand): def set_data(self): - x_data = np.random.uniform(0.1, 1, [6, 1]).astype('float32') - y_data = np.random.uniform(0.1, 1, [13, 1]).astype('float32') + x_data = np.random.uniform(0.1, 1, [6, 1]).astype('float64') + y_data = np.random.uniform(0.1, 1, [13, 1]).astype('float64') y_lod = [[2, 4], [2, 2, 3, 0, 3, 3]] self.inputs = {'X': x_data, 'Y': (y_data, y_lod)} self.attrs = {'ref_level': 1} @@ -127,9 +127,9 @@ class TestSequenceExpandCase5(TestSequenceExpand): class TestSequenceExpandCase6(TestSequenceExpand): def set_data(self): - x_data = np.random.uniform(0.1, 1, [4, 1]).astype('float32') + x_data = np.random.uniform(0.1, 1, [4, 1]).astype('float64') x_lod = [[1, 1, 0, 1, 1]] - y_data = np.random.uniform(0.1, 1, [8, 1]).astype('float32') + y_data = np.random.uniform(0.1, 1, [8, 1]).astype('float64') y_lod = [[0, 2, 4, 2, 0]] self.inputs = {'X': (x_data, x_lod), 'Y': (y_data, y_lod)} diff --git a/python/paddle/fluid/tests/unittests/test_sequence_expand_as.py b/python/paddle/fluid/tests/unittests/test_sequence_expand_as.py index 913eaf377e2..f3b9f3897c1 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_expand_as.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_expand_as.py @@ -26,8 +26,8 @@ class TestSequenceExpandAs(OpTest): self.compute() def set_data(self): - x_data = np.random.uniform(0.1, 1, [3, 40]).astype('float32') - y_data = np.random.uniform(0.1, 1, [8, 1]).astype('float32') + x_data = np.random.uniform(0.1, 1, [3, 40]).astype('float64') + y_data = np.random.uniform(0.1, 1, [8, 1]).astype('float64') y_lod = [[1, 3, 4]] self.inputs = {'X': x_data, 'Y': (y_data, y_lod)} @@ -57,27 +57,27 @@ class TestSequenceExpandAs(OpTest): class TestSequenceExpandAsCase1(TestSequenceExpandAs): def set_data(self): - x_data = np.random.uniform(0.1, 1, [5, 1]).astype('float32') + x_data = np.random.uniform(0.1, 1, [5, 1]).astype('float64') x_lod = [[2, 3]] - y_data = np.random.uniform(0.1, 1, [10, 1]).astype('float32') + y_data = np.random.uniform(0.1, 1, [10, 1]).astype('float64') y_lod = [[2, 2, 0, 3, 3]] self.inputs = {'X': (x_data, x_lod), 'Y': (y_data, y_lod)} class TestSequenceExpandAsCase2(TestSequenceExpandAs): def set_data(self): - x_data = np.random.uniform(0.1, 1, [5, 1]).astype('float32') + x_data = np.random.uniform(0.1, 1, [5, 1]).astype('float64') x_lod = [[2, 3]] - y_data = np.random.uniform(0.1, 1, [10, 1]).astype('float32') + y_data = np.random.uniform(0.1, 1, [10, 1]).astype('float64') y_lod = [[0, 4, 0, 6, 0]] self.inputs = {'X': (x_data, x_lod), 'Y': (y_data, y_lod)} class TestSequenceExpandAsCase3(TestSequenceExpandAs): def set_data(self): - x_data = np.random.uniform(0.1, 1, [1, 2, 2]).astype('float32') + x_data = np.random.uniform(0.1, 1, [1, 2, 2]).astype('float64') x_lod = [[1]] - y_data = np.random.uniform(0.1, 1, [2, 2, 2]).astype('float32') + y_data = np.random.uniform(0.1, 1, [2, 2, 2]).astype('float64') y_lod = [[2]] self.inputs = {'X': (x_data, x_lod), 'Y': (y_data, y_lod)} diff --git a/python/paddle/fluid/tests/unittests/test_sequence_pad_op.py b/python/paddle/fluid/tests/unittests/test_sequence_pad_op.py index f3b2ce2b094..dfb7b7e7745 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_pad_op.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_pad_op.py @@ -23,7 +23,7 @@ class TestSequencePadOp(OpTest): self.x_len_lod = [[2, 3, 4, 3]] self.pad_value = [1.0] self.padded_length = -1 - self.dtype = 'float32' + self.dtype = 'float64' def set_data(self): x_data = np.random.uniform(0.1, 0.5, self.x_shape).astype(self.dtype) @@ -84,7 +84,7 @@ class TestSequencePadOp2(TestSequencePadOp): self.x_len_lod = [[2, 3, 4, 3]] self.pad_value = [1.0, 2.0, 3.0, 4.0] self.padded_length = -1 - self.dtype = 'float32' + self.dtype = 'float64' class TestSequencePadOp3(TestSequencePadOp): @@ -93,7 +93,7 @@ class TestSequencePadOp3(TestSequencePadOp): self.x_len_lod = [[2, 3, 4, 3]] self.pad_value = [1.0] self.padded_length = 7 - self.dtype = 'float32' + self.dtype = 'float64' class TestSequencePadOp4(TestSequencePadOp): @@ -102,7 +102,7 @@ class TestSequencePadOp4(TestSequencePadOp): self.x_len_lod = [[2, 3, 4, 3]] self.pad_value = [1.0, 2.0, 3.0, 4.0] self.padded_length = 7 - self.dtype = 'float32' + self.dtype = 'float64' class TestSequencePadOp5(TestSequencePadOp): @@ -111,7 +111,7 @@ class TestSequencePadOp5(TestSequencePadOp): self.x_len_lod = [[2, 3, 4, 3]] self.pad_value = [1.0] self.padded_length = -1 - self.dtype = 'float32' + self.dtype = 'float64' class TestSequencePadOp6(TestSequencePadOp): @@ -120,7 +120,7 @@ class TestSequencePadOp6(TestSequencePadOp): self.x_len_lod = [[2, 3, 4, 3]] self.pad_value = [[1.0, 2.0], [3.0, 4.0]] self.padded_length = -1 - self.dtype = 'float32' + self.dtype = 'float64' class TestSequencePadOp7(TestSequencePadOp): @@ -129,7 +129,7 @@ class TestSequencePadOp7(TestSequencePadOp): self.x_len_lod = [[2, 3, 4, 3]] self.pad_value = [1.0] self.padded_length = 7 - self.dtype = 'float32' + self.dtype = 'float64' class TestSequencePadOp8(TestSequencePadOp): @@ -138,7 +138,7 @@ class TestSequencePadOp8(TestSequencePadOp): self.x_len_lod = [[0, 8, 0, 4, 0]] self.pad_value = [1.0] self.padded_length = 10 - self.dtype = 'float32' + self.dtype = 'float64' if __name__ == '__main__': diff --git a/python/paddle/fluid/tests/unittests/test_sequence_reshape.py b/python/paddle/fluid/tests/unittests/test_sequence_reshape.py index e2e7837dac7..c72e5dbaf80 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_reshape.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_reshape.py @@ -24,7 +24,7 @@ class TestSequenceReshape(OpTest): def init_data(self): self.dimension = 12 self.x_lod = [[4, 1, 3, 3]] - self.x = np.random.uniform(0.1, 1, [11, 24]).astype('float32') + self.x = np.random.uniform(0.1, 1, [11, 24]).astype('float64') def setUp(self): self.init_data() @@ -42,7 +42,7 @@ class TestSequenceReshape(OpTest): offset = (seq_len * x_width) / dimension assert int(offset) * dimension == seq_len * x_width out_lod[0].append(int(offset)) - out = np.zeros(shape=(sum(out_lod[0]), dimension)).astype('float32') + out = np.zeros(shape=(sum(out_lod[0]), dimension)).astype('float64') out.ravel()[:] = x.ravel()[:] return out, out_lod @@ -57,28 +57,28 @@ class TestSequenceReshape_reduce(TestSequenceReshape): def init_data(self): self.dimension = 24 self.x_lod = [[4, 2, 2, 4]] - self.x = np.random.uniform(0.1, 1, [12, 12]).astype('float32') + self.x = np.random.uniform(0.1, 1, [12, 12]).astype('float64') class TestSequenceReshape_same(TestSequenceReshape): def init_data(self): self.dimension = 12 self.x_lod = [[4, 2, 2, 4]] - self.x = np.random.uniform(0.1, 1, [12, 12]).astype('float32') + self.x = np.random.uniform(0.1, 1, [12, 12]).astype('float64') class TestSequenceReshape_reduce_seq_len0(TestSequenceReshape): def init_data(self): self.dimension = 24 self.x_lod = [[0, 6, 0, 2, 4]] - self.x = np.random.uniform(0.1, 1, [12, 12]).astype('float32') + self.x = np.random.uniform(0.1, 1, [12, 12]).astype('float64') class TestSequenceReshape_reduce_seq_len0_case1(TestSequenceReshape): def init_data(self): self.dimension = 24 self.x_lod = [[0, 2, 8, 2, 0]] - self.x = np.random.uniform(0.1, 1, [12, 12]).astype('float32') + self.x = np.random.uniform(0.1, 1, [12, 12]).astype('float64') if __name__ == '__main__': diff --git a/python/paddle/fluid/tests/unittests/test_sequence_scatter_op.py b/python/paddle/fluid/tests/unittests/test_sequence_scatter_op.py index d3ad734d818..44fece075a4 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_scatter_op.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_scatter_op.py @@ -24,12 +24,12 @@ class TestSequenceScatterOp(OpTest): def setUp(self): self.op_type = "sequence_scatter" - X_data = np.random.uniform(0.1, 1.0, [3, 6]).astype('float32') + X_data = np.random.uniform(0.1, 1.0, [3, 6]).astype('float64') Ids_data = np.array([[0], [1], [2], [5], [4], [3], [0], [1], [3], [2], [5], [4]]).astype('int64') Ids_lod = self.init_lod() - Updates_data = np.random.uniform(0.1, 1.0, [12, 1]).astype('float32') + Updates_data = np.random.uniform(0.1, 1.0, [12, 1]).astype('float64') Updates_lod = Ids_lod Out_data = np.copy(X_data) diff --git a/python/paddle/fluid/tests/unittests/test_sequence_softmax_op.py b/python/paddle/fluid/tests/unittests/test_sequence_softmax_op.py index eb956484de0..0ff8c5330fd 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_softmax_op.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_softmax_op.py @@ -27,9 +27,9 @@ class TestSequenceSoftmaxOp(OpTest): self.use_cudnn = False self.init_op_type() - x = np.random.uniform(0.1, 1, (110, 1)).astype("float32") + x = np.random.uniform(0.1, 1, (110, 1)).astype("float64") self.init_lod() - out = np.zeros((110, 1)).astype("float32") + out = np.zeros((110, 1)).astype("float64") offset = 0 for i in range(len(self.lod[0])): if (self.lod[0][i] == 0): diff --git a/python/paddle/fluid/tests/unittests/test_sequence_unpad_op.py b/python/paddle/fluid/tests/unittests/test_sequence_unpad_op.py index c4e4495841d..3905d7bf3cf 100644 --- a/python/paddle/fluid/tests/unittests/test_sequence_unpad_op.py +++ b/python/paddle/fluid/tests/unittests/test_sequence_unpad_op.py @@ -22,7 +22,7 @@ class TestSequenceUnpadOp(OpTest): def init(self): self.length = [2, 3, 4] self.x_shape = (3, 40) - self.dtype = "float32" + self.dtype = "float64" def compute(self): assert len(self.length) == self.x_shape[0] @@ -58,7 +58,7 @@ class TestSequenceUnpadOp2(TestSequenceUnpadOp): def init(self): self.length = [2, 3, 4] self.x_shape = (3, 5, 4, 3) - self.dtype = "float32" + self.dtype = "float64" class TestSequenceUnpadOp3(TestSequenceUnpadOp): diff --git a/python/paddle/fluid/tests/unittests/test_sigmoid_cross_entropy_with_logits_op.py b/python/paddle/fluid/tests/unittests/test_sigmoid_cross_entropy_with_logits_op.py index ec10b634091..e1f7e9c03f2 100644 --- a/python/paddle/fluid/tests/unittests/test_sigmoid_cross_entropy_with_logits_op.py +++ b/python/paddle/fluid/tests/unittests/test_sigmoid_cross_entropy_with_logits_op.py @@ -33,9 +33,9 @@ class TestSigmoidCrossEntropyWithLogitsOp1(OpTest): self.inputs = { 'X': logit( np.random.uniform(0, 1, (batch_size, num_classes)) - .astype("float32")), + .astype("float64")), 'Label': np.random.randint(0, 2, (batch_size, num_classes)) - .astype("float32") + .astype("float64") } # Fw Pass is implemented as elementwise sigmoid followed by @@ -65,9 +65,9 @@ class TestSigmoidCrossEntropyWithLogitsOp2(OpTest): self.inputs = { 'X': logit( np.random.uniform(0, 1, (batch_size, num_classes)) - .astype("float32")), + .astype("float64")), 'Label': np.random.randint(-1, 2, (batch_size, num_classes)) - .astype("float32") + .astype("float64") } self.attrs = {'ignore_index': ignore_index, } # Fw Pass is implemented as elementwise sigmoid followed by @@ -98,9 +98,9 @@ class TestSigmoidCrossEntropyWithLogitsOp3(OpTest): self.inputs = { 'X': logit( np.random.uniform(0, 1, (batch_size, num_classes)) - .astype("float32")), + .astype("float64")), 'Label': np.random.uniform(0, 1, (batch_size, num_classes)) - .astype("float32") + .astype("float64") } # Fw Pass is implemented as elementwise sigmoid followed by @@ -127,9 +127,9 @@ class TestSigmoidCrossEntropyWithNorm(OpTest): self.inputs = { 'X': logit( np.random.uniform(0, 1, (batch_size, num_classes)) - .astype("float32")), + .astype("float64")), 'Label': np.random.randint(-1, 2, (batch_size, num_classes)) - .astype("float32") + .astype("float64") } self.attrs = {'ignore_index': ignore_index, 'normalize': True} sigmoid_X = expit(self.inputs['X']) @@ -160,9 +160,9 @@ class TestSigmoidCrossEntropyWithLogitsOp5(OpTest): self.inputs = { 'X': logit( np.random.uniform(0, 1, tuple(batch_size + [num_classes])) - .astype("float32")), + .astype("float64")), 'Label': np.random.uniform(0, 1, tuple(batch_size + [num_classes])) - .astype("float32") + .astype("float64") } # Fw Pass is implemented as elementwise sigmoid followed by @@ -189,9 +189,9 @@ class TestSigmoidCrossEntropyWithNorm2(OpTest): self.inputs = { 'X': logit( np.random.uniform(0, 1, tuple(batch_size + [num_classes])) - .astype("float32")), + .astype("float64")), 'Label': np.random.randint(-1, 2, tuple(batch_size + [num_classes])) - .astype("float32") + .astype("float64") } self.attrs = {'ignore_index': ignore_index, 'normalize': True} sigmoid_X = expit(self.inputs['X']) @@ -222,9 +222,9 @@ class TestSigmoidCrossEntropyWithLogitsOp6(OpTest): self.inputs = { 'X': logit( np.random.uniform(0, 1, tuple(batch_size + [num_classes])) - .astype("float32")), + .astype("float64")), 'Label': np.random.randint(0, 2, tuple(batch_size + [num_classes])) - .astype("float32") + .astype("float64") } # Fw Pass is implemented as elementwise sigmoid followed by diff --git a/python/paddle/fluid/tests/unittests/test_sigmoid_focal_loss_op.py b/python/paddle/fluid/tests/unittests/test_sigmoid_focal_loss_op.py index 0e846521d0a..1ab9770df1a 100644 --- a/python/paddle/fluid/tests/unittests/test_sigmoid_focal_loss_op.py +++ b/python/paddle/fluid/tests/unittests/test_sigmoid_focal_loss_op.py @@ -65,7 +65,7 @@ class TestSigmoidFocalLossOp1(OpTest): self.set_argument() dims = (self.num_anchors, self.num_classes) - X = np.random.standard_normal(dims).astype("float32") + X = np.random.standard_normal(dims).astype("float64") L = np.random.randint(0, self.num_classes + 1, (dims[0], 1)).astype("int32") F = np.zeros(1) @@ -85,7 +85,7 @@ class TestSigmoidFocalLossOp1(OpTest): loss = sigmoid_focal_loss_forward( self.inputs['X'], self.inputs['Label'], self.inputs['FgNum'], self.gamma, self.alpha, self.num_classes) - self.outputs = {'Out': loss.astype('float32')} + self.outputs = {'Out': loss.astype('float64')} def test_check_output(self): self.check_output() diff --git a/python/paddle/fluid/tests/unittests/test_sign_op.py b/python/paddle/fluid/tests/unittests/test_sign_op.py index 0ff348d0de6..96718ab458d 100644 --- a/python/paddle/fluid/tests/unittests/test_sign_op.py +++ b/python/paddle/fluid/tests/unittests/test_sign_op.py @@ -25,7 +25,7 @@ class TestSignOp(OpTest): def setUp(self): self.op_type = "sign" self.inputs = { - 'X': np.random.uniform(-10, 10, (10, 10)).astype("float32") + 'X': np.random.uniform(-10, 10, (10, 10)).astype("float64") } self.outputs = {'Out': np.sign(self.inputs['X'])} diff --git a/python/paddle/fluid/tests/unittests/test_slice_op.py b/python/paddle/fluid/tests/unittests/test_slice_op.py index 3f51d433344..95ea757a916 100644 --- a/python/paddle/fluid/tests/unittests/test_slice_op.py +++ b/python/paddle/fluid/tests/unittests/test_slice_op.py @@ -37,7 +37,7 @@ class TestSliceOp(OpTest): } def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [3, 3, 4] self.axes = [0, 1, 2] @@ -53,7 +53,7 @@ class TestSliceOp(OpTest): class TestCase1(TestSliceOp): def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [-3, 0, 2] self.ends = [3, 100, -1] self.axes = [0, 1, 2] @@ -63,7 +63,7 @@ class TestCase1(TestSliceOp): class TestCase2(TestSliceOp): def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [-3, 0, 2] self.ends = [3, 100, -1] self.axes = [0, 1, 3] @@ -87,7 +87,7 @@ class TestSliceOp_decs_dim(OpTest): } def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [2, 3, 4] self.axes = [0, 1, 2] @@ -104,7 +104,7 @@ class TestSliceOp_decs_dim(OpTest): class TestSliceOp_decs_dim_2(TestSliceOp_decs_dim): def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [2, 1, 4] self.axes = [0, 1, 2] @@ -115,7 +115,7 @@ class TestSliceOp_decs_dim_2(TestSliceOp_decs_dim): class TestSliceOp_decs_dim_3(TestSliceOp_decs_dim): def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [-1, 0, 2] self.ends = [1000000, 1, 4] self.axes = [0, 1, 2] @@ -126,7 +126,7 @@ class TestSliceOp_decs_dim_3(TestSliceOp_decs_dim): class TestSliceOp_decs_dim_4(TestSliceOp_decs_dim): def config(self): - self.input = np.random.random([3, 4, 5, 7]).astype("float32") + self.input = np.random.random([3, 4, 5, 7]).astype("float64") self.starts = [0, 1, 2, 3] self.ends = [1, 2, 3, 4] self.axes = [0, 1, 2, 3] @@ -137,7 +137,7 @@ class TestSliceOp_decs_dim_4(TestSliceOp_decs_dim): class TestSliceOp_decs_dim_5(TestSliceOp_decs_dim): def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [-1] self.ends = [1000000] self.axes = [3] @@ -148,7 +148,7 @@ class TestSliceOp_decs_dim_5(TestSliceOp_decs_dim): class TestSliceOp_decs_dim_6(TestSliceOp_decs_dim): def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [0, 1, 2, 3] self.ends = [1, 2, 3, 4] self.axes = [0, 1, 2, 3] @@ -179,7 +179,7 @@ class TestSliceOp_starts_ListTensor(OpTest): } def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [3, 3, 4] self.axes = [0, 1, 2] @@ -219,7 +219,7 @@ class TestSliceOp_decs_dim_starts_ListTensor(OpTest): } def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [2, 3, 4] self.axes = [0, 1, 2] @@ -239,7 +239,7 @@ class TestSliceOp_decs_dim_starts_ListTensor(OpTest): class TestSliceOp_decs_dim_5_starts_ListTensor( TestSliceOp_decs_dim_starts_ListTensor): def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [-1] self.ends = [1000000] self.axes = [3] @@ -271,7 +271,7 @@ class TestSliceOp_decs_dim_starts_OneTensor(OpTest): } def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [2, 3, 4] self.axes = [0, 1, 2] @@ -309,7 +309,7 @@ class TestSliceOp_starts_OneTensor_ends_OneTensor(OpTest): } def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [3, 3, 4] self.axes = [0, 1, 2] @@ -346,7 +346,7 @@ class TestSliceOp_decs_dim_starts_and_ends_OneTensor(OpTest): } def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [2, 1, 4] self.axes = [0, 1, 2] @@ -388,7 +388,7 @@ class TestSliceOp_starts_OneTensor_ends_ListTensor(OpTest): } def config(self): - self.input = np.random.random([3, 4, 5, 6]).astype("float32") + self.input = np.random.random([3, 4, 5, 6]).astype("float64") self.starts = [1, 0, 2] self.ends = [3, 3, 4] self.axes = [0, 1, 2] @@ -483,7 +483,7 @@ class TestFP16_2(OpTest): # Test python API class TestSliceAPI(unittest.TestCase): def test_1(self): - input = np.random.random([3, 4, 5, 6]).astype("float32") + input = np.random.random([3, 4, 5, 6]).astype("float64") minus_1 = fluid.layers.fill_constant([1], "int32", -1) minus_3 = fluid.layers.fill_constant([1], "int32", -3) starts = fluid.layers.data( @@ -495,7 +495,7 @@ class TestSliceAPI(unittest.TestCase): name="x", shape=[3, 4, 5, 6], append_batch_size=False, - dtype="float32") + dtype="float64") out_1 = fluid.layers.slice( x, axes=[0, 1, 2], starts=[-3, 0, 2], ends=[3, 100, -1]) diff --git a/python/paddle/fluid/tests/unittests/test_softmax_op.py b/python/paddle/fluid/tests/unittests/test_softmax_op.py index 71d6215f72b..e36d35fef01 100644 --- a/python/paddle/fluid/tests/unittests/test_softmax_op.py +++ b/python/paddle/fluid/tests/unittests/test_softmax_op.py @@ -42,7 +42,7 @@ class TestSoftmaxOp(OpTest): self.op_type = "softmax" self.use_cudnn = False self.use_mkldnn = False - self.dtype = np.float32 + self.dtype = np.float64 self.init_kernel_type() self.shape = self.get_x_shape() self.axis = self.get_axis() diff --git a/python/paddle/fluid/tests/unittests/test_softmax_with_cross_entropy_op.py b/python/paddle/fluid/tests/unittests/test_softmax_with_cross_entropy_op.py index 4db3e4d9464..ce28253491c 100644 --- a/python/paddle/fluid/tests/unittests/test_softmax_with_cross_entropy_op.py +++ b/python/paddle/fluid/tests/unittests/test_softmax_with_cross_entropy_op.py @@ -126,7 +126,7 @@ class TestSoftmaxWithCrossEntropyOpFp16(TestSoftmaxWithCrossEntropyOp): # NOTE: numpy float16 have very low accuracy, use float32 for numpy check. logits = getattr( self, "logits", - np.random.uniform(0.1, 1.0, self.shape).astype(np.float32)) + np.random.uniform(0.1, 1.0, self.shape).astype(np.float64)) softmax = np.apply_along_axis(stable_softmax, self.axis, logits) axis_dim = self.shape[self.axis] @@ -425,7 +425,7 @@ class TestSoftmaxWithCrossEntropyOpBoundary0(TestSoftmaxWithCrossEntropyOp): self.shape = [3, 5, 7, 11] self.axis = -1 self.ignore_index = -1 - self.dtype = np.float32 + self.dtype = np.float64 self.logits = np.full(self.shape, -500.0).astype(self.dtype) @@ -442,7 +442,7 @@ class TestSoftmaxWithCrossEntropyOpBoundary1(TestSoftmaxWithCrossEntropyOp): self.shape = [3, 5, 7, 11] self.axis = -1 self.ignore_index = -1 - self.dtype = np.float32 + self.dtype = np.float64 self.logits = np.full(self.shape, 1000.0).astype(self.dtype) self.logits[:, :, 0, :] = -1000.0 diff --git a/python/paddle/fluid/tests/unittests/test_space_to_depth_op.py b/python/paddle/fluid/tests/unittests/test_space_to_depth_op.py index 5fdad44f124..75e1c16231c 100644 --- a/python/paddle/fluid/tests/unittests/test_space_to_depth_op.py +++ b/python/paddle/fluid/tests/unittests/test_space_to_depth_op.py @@ -58,9 +58,9 @@ class TestSpaceToDepthOp(OpTest): self.one_d_len = 32 * 48 * 3 * 3 self.blocksize = 2 - self.x = np.random.random(self.ori_shape).astype('float32') + self.x = np.random.random(self.ori_shape).astype('float64') self.x_1d = np.reshape(self.x, self.one_d_len) - self.out = np.zeros(self.infered_shape).astype('float32') + self.out = np.zeros(self.infered_shape).astype('float64') self.out_1d = np.reshape(self.out, self.one_d_len) self.forward = 1 @@ -82,9 +82,9 @@ class TestSpaceToDepthOpBasic(TestSpaceToDepthOp): self.one_d_len = 32 * 32 * 3 * 3 self.blocksize = 2 - self.x = np.random.random(self.ori_shape).astype('float32') + self.x = np.random.random(self.ori_shape).astype('float64') self.x_1d = np.reshape(self.x, self.one_d_len) - self.out = np.zeros(self.infered_shape).astype('float32') + self.out = np.zeros(self.infered_shape).astype('float64') self.out_1d = np.reshape(self.out, self.one_d_len) self.forward = 1 @@ -110,9 +110,9 @@ class TestSpaceToDepthOpWithStride3(TestSpaceToDepthOp): self.one_d_len = 32 * 81 * 2 * 2 self.blocksize = 3 - self.x = np.random.random(self.ori_shape).astype('float32') + self.x = np.random.random(self.ori_shape).astype('float64') self.x_1d = np.reshape(self.x, self.one_d_len) - self.out = np.zeros(self.infered_shape).astype('float32') + self.out = np.zeros(self.infered_shape).astype('float64') self.out_1d = np.reshape(self.out, self.one_d_len) self.forward = 1 @@ -124,9 +124,9 @@ class TestSpaceToDepthOpWithNotSquare(TestSpaceToDepthOp): self.one_d_len = 32 * 81 * 3 * 2 self.blocksize = 3 - self.x = np.random.random(self.ori_shape).astype('float32') + self.x = np.random.random(self.ori_shape).astype('float64') self.x_1d = np.reshape(self.x, self.one_d_len) - self.out = np.zeros(self.infered_shape).astype('float32') + self.out = np.zeros(self.infered_shape).astype('float64') self.out_1d = np.reshape(self.out, self.one_d_len) self.forward = 1 diff --git a/python/paddle/fluid/tests/unittests/test_spectral_norm_op.py b/python/paddle/fluid/tests/unittests/test_spectral_norm_op.py index e38a3f22fef..104df2efed0 100644 --- a/python/paddle/fluid/tests/unittests/test_spectral_norm_op.py +++ b/python/paddle/fluid/tests/unittests/test_spectral_norm_op.py @@ -49,9 +49,9 @@ class TestSpectralNormOpNoGrad(OpTest): def setUp(self): self.initTestCase() self.op_type = 'spectral_norm' - weight = np.random.random(self.weight_shape).astype('float32') - u = np.random.normal(0., 1., self.u_shape).astype('float32') - v = np.random.normal(0., 1., self.v_shape).astype('float32') + weight = np.random.random(self.weight_shape).astype('float64') + u = np.random.normal(0., 1., self.u_shape).astype('float64') + v = np.random.normal(0., 1., self.v_shape).astype('float64') self.attrs = { "dim": self.dim, diff --git a/python/paddle/fluid/tests/unittests/test_split_op.py b/python/paddle/fluid/tests/unittests/test_split_op.py index ef86ba7f889..714843bb8b2 100644 --- a/python/paddle/fluid/tests/unittests/test_split_op.py +++ b/python/paddle/fluid/tests/unittests/test_split_op.py @@ -34,7 +34,7 @@ class TestSplitOp(OpTest): for i in range(len(out))]} def get_dtype(self): - return "float32" + return "float64" def _set_op_type(self): self.op_type = "split" @@ -71,7 +71,7 @@ class TestSplitOp_2(OpTest): self.indices_or_sections = 3 def get_dtype(self): - return "float32" + return "float64" def _set_op_type(self): self.op_type = "split" @@ -107,7 +107,7 @@ class TestSplitOp_AxisTensor(OpTest): self.indices_or_sections = 3 def get_dtype(self): - return "float32" + return "float64" def _set_op_type(self): self.op_type = "split" @@ -153,7 +153,7 @@ class TestSplitOp_SectionsTensor(OpTest): self.indices_or_sections = [2, 3] def get_dtype(self): - return "float32" + return "float64" def _set_op_type(self): self.op_type = "split" @@ -189,7 +189,7 @@ class TestSplitOp_unk_section(OpTest): self.indices_or_sections = [2, 3] def get_dtype(self): - return "float32" + return "float64" def _set_op_type(self): self.op_type = "split" diff --git a/python/paddle/fluid/tests/unittests/test_spp_op.py b/python/paddle/fluid/tests/unittests/test_spp_op.py index 1864ca82e2d..ad077236c82 100644 --- a/python/paddle/fluid/tests/unittests/test_spp_op.py +++ b/python/paddle/fluid/tests/unittests/test_spp_op.py @@ -25,7 +25,7 @@ class TestSppOp(OpTest): def setUp(self): self.op_type = "spp" self.init_test_case() - input = np.random.random(self.shape).astype("float32") + input = np.random.random(self.shape).astype("float64") nsize, csize, hsize, wsize = input.shape out_level_flatten = [] for i in range(self.pyramid_height): @@ -50,13 +50,13 @@ class TestSppOp(OpTest): else: output = np.concatenate((output, out_level_flatten[i]), 1) # output = np.concatenate(out_level_flatten.tolist(), 0); - self.inputs = {'X': input.astype('float32'), } + self.inputs = {'X': input.astype('float64'), } self.attrs = { 'pyramid_height': self.pyramid_height, 'pooling_type': self.pool_type } - self.outputs = {'Out': output.astype('float32')} + self.outputs = {'Out': output.astype('float64')} def test_check_output(self): self.check_output() -- GitLab