KEMBAR78
Report convolution size mismatch by bhushan23 · Pull Request #17436 · pytorch/pytorch · GitHub
Skip to content

Conversation

@bhushan23
Copy link
Contributor

@bhushan23 bhushan23 commented Feb 23, 2019

  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

@bhushan23
Copy link
Contributor Author

@fmassa I couldn't verify the fix locally for cuda due to logistic reasons.
Is it possible for you to pull this and validate?

@bhushan23
Copy link
Contributor Author

@fmassa could you please review?

@mrshenli mrshenli self-requested a review February 26, 2019 17:28
Copy link
Contributor

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)

Copy link
Contributor Author

@bhushan23 bhushan23 Mar 1, 2019

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Member

@fmassa fmassa left a 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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropping comment

Copy link
Member

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?

Copy link
Contributor Author

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.

@bhushan23 bhushan23 closed this Mar 1, 2019
@bhushan23 bhushan23 reopened this Mar 1, 2019
@fmassa
Copy link
Member

fmassa commented Mar 6, 2019

@pytorchbot rebase this please

@pytorchbot
Copy link
Collaborator

Sorry, I can't merge this because there are conflicts. To merge this yourself, run the commands below:

git fetch origin master
git fetch git@github.com:bhushan23/pytorch.git conv
git checkout FETCH_HEAD
git merge origin/master
git push git@github.com:bhushan23/pytorch.git HEAD:conv

(To learn more about this bot, see Bot commands.)

@fmassa
Copy link
Member

fmassa commented Mar 6, 2019

@bhushan23 can you fix the conflicts?

@bhushan23
Copy link
Contributor Author

Thanks @fmassa
conflit resolved

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@mrshenli mrshenli left a 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

Copy link
Contributor

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?

Copy link
Contributor

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
@bhushan23
Copy link
Contributor Author

thanks @mrshenli
I totally missed unused var and include. Removed now.

@mrshenli
Copy link
Contributor

mrshenli commented Mar 7, 2019

@pytorchbot retest this please

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Mar 14, 2019
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
@iotamudelta
Copy link
Contributor

@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?

@bhushan23
Copy link
Contributor Author

@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.
back in time, we thought of using one path for conv.

@bhushan23
Copy link
Contributor Author

@iotamudelta how much performance drop has been observed?
It is good time to access and understand perf gain we are getting with the miopen implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convolution layer cann't report size error when padded input size is less than kernel size

7 participants