-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using nn.Conv2d with padding="same" supports a stride of 2, however it currently fails due to an error message #67551
Comments
@ProGamerGov This was done to move forward with some support while avoiding violating the expectations of those who expect the exact same behavior that TensorFlow has when TensorFlow's behavior is controversial but may need to be provided as an option. I previously suggested implementing both TensorFlow's behavior and the current input-size-independent approach as two separate modes. Out of curiosity, do you need the exact same behavior as TensorFlow for your use case or is the current approach that conceptually accomplishes the same thing acceptable for you? |
@jbschlosser Thank you for the quick reply! I'm currently using a custom wrapper over the
The solution was written by a previous researcher before same padding was added to |
Great - thanks for the additional info on your use case! Sounds like it's important that we provide an option for TF-exact same padding. FYI I'm going to close this issue to consolidate discussion on the original issue #3867. |
bug fix: ValueError: padding='same' is not supported for strided convolutions. See: pytorch/pytorch#67551
However, be cautious with this solution. It will cause extra GPU memory cost for a padded x. This will cause CUDA out of memory problem if x is very large. Therefore, it is suggested to be used only for stride>1. if still OOM, replace Conv2dSame(stride=2) with maxpooling. |
馃悰 Bug
The error message for
_ConvNd
indicates thatnn.Conv2d
does not currently support a stride of2
when using same padding. However, upon disabling the error it seems to work correctly, which leads me to wonder if the error checking needs to be adjusted.This line here appears to be the root cause of the issue: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py#L93-L94
To Reproduce
Trying to specify a
stride=(2, 2)
withpadding="same"
for ann.Conv2d
layer, results in the following error message:I pulled the actual code for the same padding from here: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py#L110-L123, and setup a test to showcase that it works.
Expected behavior
Creating an
nn.Conv2d
layer withpadding=same
andstride=(2, 2)
should work without issue.Environment
The environment was a Colab instance, but the issue should occur with all PyTorch versions that support
nn.Conv2d
withpadding="same"
.Additional context
It's not clear why this working feature is blocked by an error message at the moment.
cc @albanD @mruberry @jbschlosser @walterddr
The text was updated successfully, but these errors were encountered: