Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix div 0 error in conv1/2/3 #49999

Merged
merged 6 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions paddle/phi/kernels/impl/conv_kernel_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ void ConvKernelImpl(const Context& dev_ctx,
filter.numel() / filter.dims()[0]};
filter.Resize(filter_matrix_shape);

PADDLE_ENFORCE_NE(
transformed_output.dims()[0] * transformed_output.dims()[1],
0,
phi::errors::InvalidArgument("The Output size should not be 0."));

DDim output_matrix_shape = {
transformed_output.dims()[1],
transformed_output.numel() /
Expand Down
12 changes: 12 additions & 0 deletions python/paddle/fluid/tests/unittests/test_functional_conv1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,17 @@ def setUp(self):
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()
14 changes: 14 additions & 0 deletions python/paddle/fluid/tests/unittests/test_functional_conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,20 @@ def setUp(self):
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()
14 changes: 14 additions & 0 deletions python/paddle/fluid/tests/unittests/test_functional_conv3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,20 @@ def setUp(self):
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()