-
Notifications
You must be signed in to change notification settings - Fork 384
Add support for 'same' and 'valid' for padding in conv #451
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
Add support for 'same' and 'valid' for padding in conv #451
Conversation
|
This pull request was exported from Phabricator. Differential Revision: D37811390 |
|
This pull request was exported from Phabricator. Differential Revision: D37811390 |
) Summary: Pull Request resolved: meta-pytorch#451 Differential Revision: D37811390 fbshipit-source-id: 589ffe6c043e5566ed32dcca9cf853fb7cfc72cf
|
So the reason for the failing tests in that All numerical values of padding in convolution layers pad equally from both sides, which we assumed to be the case when writing grad sampler for opacus. I've prototyped the solution in #456 - it's based on your commit, I've fixed 1d and 2d cases. Still pending is:
|
|
This pull request was exported from Phabricator. Differential Revision: D37811390 |
|
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@ashkan-software do you know why |
|
@ashkan-software For ExpandedWeights tests failures, I don't think they should be blocking for merging this. For now you can disable this particular combination of input arguments (we have @samdow, do we have an issue created for this, so we can link it for future tracking? |
Summary: Pull Request resolved: #451 Differential Revision: D37811390 Pulled By: ashkan-software fbshipit-source-id: 1bbf21c9dffba9dc1fe776a95f9ec8283ad42a8d
|
This pull request was exported from Phabricator. Differential Revision: D37811390 |
|
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@ffuuugor thanks a lot for your recommendations. I applied them all and we are good to go! |
No but I'm planning to add this today thanks to talk with @ashkan-software! If I don't get to it today, I'll file an issue 😄 Thanks for flagging this and doing the heavy lifting of the implementation |
Co-authored-by: Ashkan <yousefpour@fb.com> Adds "same" and "valid" padding support, as Opacus (well @ashkan-software) did meta-pytorch/opacus#451 Basics of it are this: - during forward pass, if there's "same" padding, we manually pad the input (NB: this will cause a small perf hit, haven't benchmarked yet) - during backward pass, the gradient wrt input needs to be cut down to the correct size if the original padding was same (conv_transpose doesn't accept string padding). Because conv_transpose will give us a gradient wrt the padded shape, we cut down the gradient to the correct size (we know how much padding we added to the left and right) - then, for the per sample gradients wrt weights, the input is already padded so neither the unfold nor group convolution have any padding Pull Request resolved: #83345 Approved by: https://github.com/zou3519
Co-authored-by: Ashkan <yousefpour@fb.com> Adds "same" and "valid" padding support, as Opacus (well @ashkan-software) did meta-pytorch/opacus#451 Basics of it are this: - during forward pass, if there's "same" padding, we manually pad the input (NB: this will cause a small perf hit, haven't benchmarked yet) - during backward pass, the gradient wrt input needs to be cut down to the correct size if the original padding was same (conv_transpose doesn't accept string padding). Because conv_transpose will give us a gradient wrt the padded shape, we cut down the gradient to the correct size (we know how much padding we added to the left and right) - then, for the per sample gradients wrt weights, the input is already padded so neither the unfold nor group convolution have any padding Pull Request resolved: #83345 Approved by: https://github.com/zou3519
…83345) Summary: Adds "same" and "valid" padding support, as Opacus (well ashkan-software) did meta-pytorch/opacus#451 Basics of it are this: - during forward pass, if there's "same" padding, we manually pad the input (NB: this will cause a small perf hit, haven't benchmarked yet) - during backward pass, the gradient wrt input needs to be cut down to the correct size if the original padding was same (conv_transpose doesn't accept string padding). Because conv_transpose will give us a gradient wrt the padded shape, we cut down the gradient to the correct size (we know how much padding we added to the left and right) - then, for the per sample gradients wrt weights, the input is already padded so neither the unfold nor group convolution have any padding Pull Request resolved: #83345 Approved by: https://github.com/zou3519 Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/3a511e83549d86ce9a2a8de2b64be340d2a23e4e Reviewed By: seemethere, atalman Differential Revision: D38770030 Pulled By: samdow fbshipit-source-id: 8be29c56ee84dce49a9fd765d7005c647b10862d Co-authored-by: Ashkan <yousefpour@fb.com>
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.
Looks great, thanks a lot for the amazing work!
| groups=groups, | ||
| ) | ||
| self.run_test(x, conv, batch_first=True, atol=10e-5, rtol=10e-4) | ||
| is_ew_compatible = padding != 'same' # TODO add support for padding = 'same' with EW |
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.
does "valid" padding work fine with EW?
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.
Good question. It should since it's basically zero padding. But let me run a test locally and verify this. Good catch!
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.
well, actually on line 37 of this file we have unit tests for both "valid" and "same". So it should work just fine 😎
|
This pull request was exported from Phabricator. Differential Revision: D37811390 |
Differential Revision: D37811390