Commit 8300a521 authored by ngimel's avatar ngimel Committed by Myle Ott
Browse files

use implicit padding when possible

parent ae2585d9
...@@ -123,9 +123,9 @@ class FConvEncoder(FairseqEncoder): ...@@ -123,9 +123,9 @@ class FConvEncoder(FairseqEncoder):
self.projections.append(Linear(in_channels, out_channels) self.projections.append(Linear(in_channels, out_channels)
if in_channels != out_channels else None) if in_channels != out_channels else None)
if kernel_size % 2 == 1: if kernel_size % 2 == 1:
padding = kernel_size // 2 padding = kernel_size //2
else: else:
padding = 0 padding = 0
self.convolutions.append( self.convolutions.append(
ConvTBC(in_channels, out_channels * 2, kernel_size, ConvTBC(in_channels, out_channels * 2, kernel_size,
dropout=dropout, padding=padding) dropout=dropout, padding=padding)
...@@ -161,7 +161,7 @@ class FConvEncoder(FairseqEncoder): ...@@ -161,7 +161,7 @@ class FConvEncoder(FairseqEncoder):
if conv.kernel_size[0] % 2 == 1: if conv.kernel_size[0] % 2 == 1:
# padding is implicit in the conv # padding is implicit in the conv
x = conv(x) x = conv(x)
else: else:
padding_l = (conv.kernel_size[0] - 1) // 2 padding_l = (conv.kernel_size[0] - 1) // 2
padding_r = conv.kernel_size[0] // 2 padding_r = conv.kernel_size[0] // 2
x = F.pad(x, (0, 0, 0, 0, padding_l, padding_r)) x = F.pad(x, (0, 0, 0, 0, padding_l, padding_r))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment