-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Circular Convolution Function via circular padding #17240
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
b09b180 to
a88bb61
Compare
a88bb61 to
eb34f09
Compare
ezyang
left a comment
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.
This is a really good start. I think the big things for me are:
- Getting better test coverage for padding > 1 case. I don't really care if you have a reference implementation, but we should exercise it.
- Fixing the error checking in
circular_pad. My suggestion is to fold it into the existingpadfunction.
apaszke
left a comment
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.
Could we just have F.pad_circular to avoid having a blow up for every single dimensionality?
|
@apaszke I don't know how to write a generalized circular pad that works for arbitrary dimensionality, without writing the kernel out (which may eventually be a good idea, but I wouldn't block this PR on it.) Any ideas? :) |
|
I haven't actually thought about that, but it seems like the implementations for 1d and 3d look the same modulo the number of colons (which are equivalent to |
|
Thank you @apaszke and @ezyang ! I can play with the slice(None) to find a more elegant implementation for the dimensionality. After circular padding |
eb34f09 to
6832149
Compare
|
@ezyang and @apaszke , I've just pushed the implementation of pad_circular which works for arbitrary dimensions. |
6832149 to
2243484
Compare
2243484 to
36b07f3
Compare
36b07f3 to
dab9675
Compare
|
@pytorchbot rebase this please |
|
There's nothing to do! This branch is already up to date with master (d76b939). (To learn more about this bot, see Bot commands.) |
dab9675 to
93d1679
Compare
93d1679 to
12f0925
Compare
torch/nn/modules/conv.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.
We could also have a separate method to split left and right paddings.
12f0925 to
72f19e2
Compare
|
@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.) |
72f19e2 to
b46d343
Compare
b46d343 to
49d20e4
Compare
Summary: Pull Request resolved: pytorch#17240 Added circular padding in addition to zero padding to Conv1D, Conv2D and Conv3D based on the solution suggested in: pytorch#3858 Differential Revision: D14126416 fbshipit-source-id: 72cdb69b8c22e33b0ba9ae515c4d119f69ea45d9
49d20e4 to
0a877ca
Compare
|
|
||
|
|
||
| @weak_script | ||
| def pad_circular(input, padding): |
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.
question: why didn't we add this functionality to F.pad?
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.
| return F.conv1d(F.pad(input, expanded_padding, mode='circular'), | ||
| self.weight, self.bias, self.stride, | ||
| _single(0), self.dilation, self.groups) | ||
| return F.conv1d(input, self.weight, self.bias, self.stride, |
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 want to have the functional interface of conv also support the padding mode?
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.
In the documentation it appears padding_mode is supported, but when I try to use it tells me it is an unexpected argument. I will do the manual padding, as in the module, but it would be convenient if the operation is supported.
In my case, my filter is a tensor, not a parameter, and I would prefer not to use a module.
Thanks!
|
What version of PyTorch are you running?
Excerpts from Javier Zazo's message of 2019-07-05 02:41:34 -0700:
… jzazo commented on this pull request.
>
@weak_script_method
def forward(self, input):
+ if self.padding_mode == 'circular':
+ expanded_padding = ((self.padding[0] + 1) // 2, self.padding[0] // 2)
+ return F.conv1d(F.pad(input, expanded_padding, mode='circular'),
+ self.weight, self.bias, self.stride,
+ _single(0), self.dilation, self.groups)
return F.conv1d(input, self.weight, self.bias, self.stride,
In the documentation it appears padding_mode is supported, but when I try to use it tells me it is an unexpected argument. I will do the manual padding, as in the module, but it would be convenient if the operation is supported.
In my case, my filter is a tensor, not a parameter, and I would prefer not to use a module.
Thanks!
|
|
I am running 1.1.0. Thanks! |
|
If I try to run |
Summary: Added circular padding in addition to zero padding to Conv1D, Conv2D and Conv3D based on the solution suggested in: #3858
Differential Revision: D14126416