mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
Improve error message for non-positive groups in convolution (#165669)
Prevents from segmentation fault for invalid groups value in convolution. Fixes #142835 Pull Request resolved: https://github.com/pytorch/pytorch/pull/165669 Approved by: https://github.com/mikaylagawarecki
This commit is contained in:
committed by
PyTorch MergeBot
parent
08c97b4a1f
commit
9c12651417
@ -230,6 +230,55 @@ class TestConvolutionNN(NNTestCase):
|
||||
with self.assertRaisesRegex(ValueError, "groups must be a positive integer"):
|
||||
torch.nn.Conv3d(1, 1, kernel_size=3, dilation=2, stride=2, groups=-2)
|
||||
|
||||
def test_conv_aten_invalid_groups(self):
|
||||
# test low-level aten ops with invalid groups parameter
|
||||
grad_output = torch.randn(2, 4, 8, dtype=torch.double)
|
||||
input = torch.randn(2, 5, 8, dtype=torch.double)
|
||||
weight = torch.randn(5, 4, 3, dtype=torch.double)
|
||||
bias_sizes = [4]
|
||||
stride = [1]
|
||||
padding = [1]
|
||||
dilation = [1]
|
||||
transposed = True
|
||||
output_padding = [0]
|
||||
output_mask = [True, True, True]
|
||||
|
||||
# test groups=0
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError, "expected groups to be greater than 0, but got groups=0"
|
||||
):
|
||||
torch.ops.aten.convolution_backward(
|
||||
grad_output,
|
||||
input,
|
||||
weight,
|
||||
bias_sizes,
|
||||
stride,
|
||||
padding,
|
||||
dilation,
|
||||
transposed,
|
||||
output_padding,
|
||||
0,
|
||||
output_mask,
|
||||
)
|
||||
|
||||
# test groups=-1
|
||||
with self.assertRaisesRegex(
|
||||
RuntimeError, "expected groups to be greater than 0, but got groups=-1"
|
||||
):
|
||||
torch.ops.aten.convolution_backward(
|
||||
grad_output,
|
||||
input,
|
||||
weight,
|
||||
bias_sizes,
|
||||
stride,
|
||||
padding,
|
||||
dilation,
|
||||
transposed,
|
||||
output_padding,
|
||||
-1,
|
||||
output_mask,
|
||||
)
|
||||
|
||||
def test_conv3d_overflow_values(self):
|
||||
input = torch.full(
|
||||
(
|
||||
|
Reference in New Issue
Block a user