diff --git a/paddle/phi/infermeta/binary.cc b/paddle/phi/infermeta/binary.cc index 3ca56e0602c1d2413ef5ceef36ecbffe047ecf8a..7551c51d6476f08b5f14b1f96c3dc1c702cf9fa7 100644 --- a/paddle/phi/infermeta/binary.cc +++ b/paddle/phi/infermeta/binary.cc @@ -467,6 +467,13 @@ void ConvInferMeta(const MetaTensor& input, const bool channel_last = (config.is_run_mkldnn_kernel == false) && (data_format == "NHWC" || data_format == "NDHWC"); + for (int i = 0; i < 2; ++i) { + PADDLE_ENFORCE_NE(in_dims[i], + 0, + phi::errors::InvalidArgument( + "The size of Op(Conv) inputs should not be 0.")); + } + PADDLE_ENFORCE_EQ( in_dims.size() == 4 || in_dims.size() == 5, true, diff --git a/python/paddle/fluid/tests/unittests/test_functional_conv1d.py b/python/paddle/fluid/tests/unittests/test_functional_conv1d.py index 0bd7fa1878d414776e2f48eedf58c8c2842edab5..d050c6163900b1673259aac8fab9efa5d51da4f3 100644 --- a/python/paddle/fluid/tests/unittests/test_functional_conv1d.py +++ b/python/paddle/fluid/tests/unittests/test_functional_conv1d.py @@ -70,5 +70,17 @@ class TestFunctionalConv1DErrorCase1(TestFunctionalConv1DError): self.data_format = "NCL" +class TestFunctionalConv1DErrorCase2(TestFunctionalConv1DError): + def setUp(self): + self.input = np.random.randn(0, 0, 0) + self.filter = np.random.randn(1, 0, 0) + self.bias = None + self.padding = 0 + self.stride = 1 + self.dilation = 1 + self.groups = 1 + self.data_format = "NCL" + + if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_functional_conv2d.py b/python/paddle/fluid/tests/unittests/test_functional_conv2d.py index 00cc6c07aac8bca521bad0e59e84e0db046db2ce..c78f6c35b06316f79124dc905bea7ef6d835e6da 100644 --- a/python/paddle/fluid/tests/unittests/test_functional_conv2d.py +++ b/python/paddle/fluid/tests/unittests/test_functional_conv2d.py @@ -569,6 +569,20 @@ class TestFunctionalConv2DErrorCase13(TestFunctionalConv2DErrorCase12): self.data_format = "NCHW" +class TestFunctionalConv2DErrorCase14(TestFunctionalConv2DErrorCase12): + def setUp(self): + self.input = np.random.randn(0, 0, 0, 0) + self.filter = np.random.randn(1, 0, 0, 0) + self.num_filters = 0 + self.filter_size = 0 + self.bias = None + self.padding = 0 + self.stride = 1 + self.dilation = 1 + self.groups = 1 + self.data_format = "NCHW" + + if __name__ == "__main__": paddle.enable_static() unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_functional_conv3d.py b/python/paddle/fluid/tests/unittests/test_functional_conv3d.py index 62322f8e3dc8f9114502ef4d1140fb12cf3dc7a4..5e867036dd477f4171e47a3f8e7fd26493b6b1c9 100644 --- a/python/paddle/fluid/tests/unittests/test_functional_conv3d.py +++ b/python/paddle/fluid/tests/unittests/test_functional_conv3d.py @@ -544,6 +544,20 @@ class TestFunctionalConv3DErrorCase12(TestFunctionalConv3DErrorCase11): self.data_format = "NCDHW" +class TestFunctionalConv3DErrorCase13(TestFunctionalConv3DErrorCase11): + def setUp(self): + self.input = np.random.randn(0, 0, 0, 0, 0) + self.filter = np.random.randn(1, 0, 0, 0, 0) + self.num_filters = 1 + self.filter_size = 1 + self.bias = None + self.padding = 0 + self.stride = 1 + self.dilation = 1 + self.groups = 1 + self.data_format = "NCDHW" + + if __name__ == "__main__": paddle.enable_static() unittest.main()