From fa8bab9cbcdeb9ba544b23bbb78936ccc547cb87 Mon Sep 17 00:00:00 2001 From: FDInSky <48318485+FDInSky@users.noreply.github.com> Date: Mon, 30 Dec 2019 14:22:54 +0800 Subject: [PATCH] add fp64 check_grad for conv2d, conv3d (#21931) * test=develop add fp64 check_grad for conv2d, conv3d --- .../unittests/mkldnn/test_conv2d_mkldnn_op.py | 3 +++ .../unittests/mkldnn/test_conv3d_mkldnn_op.py | 19 ++++++++++++++++++- .../fluid/tests/unittests/test_conv2d_op.py | 4 ++-- .../fluid/tests/unittests/test_conv3d_op.py | 4 ++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_mkldnn_op.py b/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_mkldnn_op.py index 69d2d23b1ad..777b1a26742 100644 --- a/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_mkldnn_op.py +++ b/python/paddle/fluid/tests/unittests/mkldnn/test_conv2d_mkldnn_op.py @@ -44,6 +44,7 @@ class TestConv2dMKLDNNOp(TestConv2dOp): self.data_format = "NCHW" self.use_mkldnn = True self._cpu_only = True + self.dtype = np.float32 def init_test_case(self): self.pad = [0, 0] @@ -62,6 +63,7 @@ class TestConv2dMKLDNNOp(TestConv2dOp): self.fuse_brelu_threshold = 6.0 self.fuse_residual_connection = False self.input_residual_size = None + TestConv2dOp.setUp(self) output = self.outputs['Output'] @@ -179,6 +181,7 @@ class TestWithInput1x1Filter1x1(TestConv2dMKLDNNOp): class TestConv2dOp_AsyPadding_MKLDNN(TestConv2dOp_v2): def init_kernel_type(self): self.use_mkldnn = True + self.dtype = np.float32 def init_paddings(self): self.pad = [0, 0, 1, 2] diff --git a/python/paddle/fluid/tests/unittests/mkldnn/test_conv3d_mkldnn_op.py b/python/paddle/fluid/tests/unittests/mkldnn/test_conv3d_mkldnn_op.py index a54640da779..8f310946db2 100644 --- a/python/paddle/fluid/tests/unittests/mkldnn/test_conv3d_mkldnn_op.py +++ b/python/paddle/fluid/tests/unittests/mkldnn/test_conv3d_mkldnn_op.py @@ -15,7 +15,7 @@ from __future__ import print_function import unittest - +import numpy as np from paddle.fluid.tests.unittests.test_conv3d_op import TestConv3dOp, TestCase1, TestWithGroup1, TestWithGroup2, TestWith1x1, TestWithInput1x1Filter1x1, TestConv3dOp_2 @@ -23,42 +23,49 @@ class TestMKLDNN(TestConv3dOp): def init_kernel_type(self): self.use_mkldnn = True self.data_format = "NCHW" + self.dtype = np.float32 class TestMKLDNNCase1(TestCase1): def init_kernel_type(self): self.use_mkldnn = True self.data_format = "NCHW" + self.dtype = np.float32 class TestMKLDNNGroup1(TestWithGroup1): def init_kernel_type(self): self.use_mkldnn = True self.data_format = "NCHW" + self.dtype = np.float32 class TestMKLDNNGroup2(TestWithGroup2): def init_kernel_type(self): self.use_mkldnn = True self.data_format = "NCHW" + self.dtype = np.float32 class TestMKLDNNWith1x1(TestWith1x1): def init_kernel_type(self): self.use_mkldnn = True self.data_format = "NCHW" + self.dtype = np.float32 class TestMKLDNNWithInput1x1Filter1x1(TestWithInput1x1Filter1x1): def init_kernel_type(self): self.use_mkldnn = True self.data_format = "NCHW" + self.dtype = np.float32 class TestConv3dOp_AsyPadding_MKLDNN(TestConv3dOp): def init_kernel_type(self): self.use_mkldnn = True self.data_format = "NCHW" + self.dtype = np.float32 def init_paddings(self): self.pad = [1, 0, 1, 0, 0, 2] @@ -70,12 +77,22 @@ class TestConv3dOp_Same_MKLDNN(TestConv3dOp_AsyPadding_MKLDNN): self.pad = [0, 0, 0] self.padding_algorithm = "SAME" + def init_kernel_type(self): + self.use_mkldnn = True + self.data_format = "NCHW" + self.dtype = np.float32 + class TestConv3dOp_Valid_MKLDNN(TestConv3dOp_AsyPadding_MKLDNN): def init_paddings(self): self.pad = [1, 1, 1] self.padding_algorithm = "VALID" + def init_kernel_type(self): + self.use_mkldnn = True + self.data_format = "NCHW" + self.dtype = np.float32 + if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_conv2d_op.py b/python/paddle/fluid/tests/unittests/test_conv2d_op.py index 70dda1ccdcf..2285f3ee830 100644 --- a/python/paddle/fluid/tests/unittests/test_conv2d_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv2d_op.py @@ -298,7 +298,7 @@ class TestConv2dOp(OpTest): self.use_mkldnn = False self.fuse_relu_before_depthwise_conv = False self.data_format = "AnyLayout" - self.dtype = np.float32 + self.dtype = np.float64 self.init_kernel_type() self.init_group() self.init_dilation() @@ -723,7 +723,7 @@ class TestConv2dOp_v2(OpTest): self.use_cuda = False self.use_mkldnn = False self.fuse_relu_before_depthwise_conv = False - self.dtype = np.float32 + self.dtype = np.float64 self.init_kernel_type() self.init_group() self.init_dilation() diff --git a/python/paddle/fluid/tests/unittests/test_conv3d_op.py b/python/paddle/fluid/tests/unittests/test_conv3d_op.py index d83da2ce150..0f3677daa87 100644 --- a/python/paddle/fluid/tests/unittests/test_conv3d_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv3d_op.py @@ -234,7 +234,7 @@ class TestConv3dOp(OpTest): self.use_cudnn = False self.use_mkldnn = False self.data_format = "AnyLayout" - self.dtype = np.float32 + self.dtype = np.float64 self.init_kernel_type() self.init_group() self.init_dilation() @@ -525,7 +525,7 @@ class TestConv3dOp_2(OpTest): self.use_cudnn = False self.use_mkldnn = False self.data_format = "NCDHW" - self.dtype = np.float32 + self.dtype = np.float64 self.init_kernel_type() self.init_group() self.init_dilation() -- GitLab