-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Report convolution size mismatch #17436
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
Conversation
|
@fmassa I couldn't verify the fix locally for cuda due to logistic reasons. |
|
@fmassa could you please review? |
aten/src/ATen/native/Convolution.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I am wrong, I don't think we support negative stride on convolutional layers. If so, can you add an AT_CHECK for that? And if so, do you still need the output_shape check?
>>> c = nn.Conv1d(3, 2, kernel_size=7, stride=1)
>>> c(torch.zeros(2, 3, 10))
tensor([[[-0.1358, -0.1358, -0.1358, -0.1358],
[-0.0659, -0.0659, -0.0659, -0.0659]],
[[-0.1358, -0.1358, -0.1358, -0.1358],
[-0.0659, -0.0659, -0.0659, -0.0659]]], grad_fn=<SqueezeBackward1>)
>>> c = nn.Conv1d(3, 2, kernel_size=7, stride=-1)
>>> c(torch.zeros(2, 3, 10))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/shenli/project/pytorch/torch/nn/modules/module.py", line 491, in __call__
result = self.forward(*input, **kwargs)
File "/home/shenli/project/pytorch/torch/nn/modules/conv.py", line 188, in forward
self.padding, self.dilation, self.groups)
RuntimeError: Trying to create tensor with negative dimension -2: [2, 2, 1, -2]
>>> c = nn.Conv1d(3, 2, kernel_size=7, stride=-3)
>>> c(torch.zeros(2, 3, 10))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/shenli/project/pytorch/torch/nn/modules/module.py", line 491, in __call__
result = self.forward(*input, **kwargs)
File "/home/shenli/project/pytorch/torch/nn/modules/conv.py", line 188, in forward
self.padding, self.dilation, self.groups)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't support negative strides. Added check for it.
Handling dilation for computing kernel size which leads to no need of output shape hence removing.
aten/src/ATen/native/Convolution.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this two lines be moved into the check_input_shape_forward method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
test/test_nn.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To close #17247, could you please add all the reported failed use cases to the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have other test cases e.g. invalid_conv2d and 3d which does check for current error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Thanks for the PR!
I have a few questions, let me know what you think.
test/test_nn.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this print?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
aten/src/ATen/native/Convolution.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe dilation should also be taken into account here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmassa do we claim to support negative stride for convolutional layers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @mrshenli 's previous comment of not allowing negative stride which removes the need of output_shape only if we consider dilation for updating new kernel size and use it for input shape mismatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me
aten/src/ATen/native/Convolution.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output_padding is only used in transposed convolutions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropping comment
aten/src/ATen/native/Convolution.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to do similar checks for transposed as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. transposed convolution are not dependent on kernel size and input shape. output will determine on kernel size but not restricted on kernel size.
|
@pytorchbot rebase this please |
|
Sorry, I can't merge this because there are conflicts. To merge this yourself, run the commands below: (To learn more about this bot, see Bot commands.) |
|
@bhushan23 can you fix the conflicts? |
|
Thanks @fmassa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmassa has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only 2 nitpicks
aten/src/ATen/native/Convolution.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems we no longer need this header any more. Can we remove it?
aten/src/ATen/native/Convolution.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused var, please remove.
- Considering dilation and computing new kernel size for input checking - Refactored check_input_shape_forward as check_shape_forward as adding padding, stride check - Ensuring stride to be non-zero Test case added: - invalid_conv1d - relevant test cases for conv2d and conv3d exists - added test cases for negative stride
|
thanks @mrshenli |
|
@pytorchbot retest this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmassa has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmassa has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: 1. Kernel size is larger than input 2. Expected output size to be less than zero Test case added: - invalid_conv1d - Relevant test cases for conv2d and conv3d exists Fixes #17247 Pull Request resolved: pytorch/pytorch#17436 Reviewed By: mrshenli Differential Revision: D14354272 Pulled By: fmassa fbshipit-source-id: 94b98621aa03b1f60d151ef9399ed3da55d41b42
|
@bhushan23 @ezyang this PR removed support for using MIOpen on ROCm for depthwise convolutions (line 357). Hence, performance for models using them regressed on ROCm. How can we go about re-instantiating support and ensure support remains in? |
@iotamudelta we need ton add conditional miopen depthwise convolution back. |
|
@iotamudelta how much performance drop has been observed? |
Test case added:
Fixes #17247