Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Fairseq
Commits
48c4c6d3
Commit
48c4c6d3
authored
May 09, 2018
by
ngimel
Committed by
Myle Ott
May 09, 2018
Browse files
use implicit padding when possible (#152)
parent
66ee3df9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
fairseq/models/fconv.py
fairseq/models/fconv.py
+13
-5
No files found.
fairseq/models/fconv.py
View file @
48c4c6d3
...
@@ -98,9 +98,13 @@ class FConvEncoder(FairseqEncoder):
...
@@ -98,9 +98,13 @@ class FConvEncoder(FairseqEncoder):
for
(
out_channels
,
kernel_size
)
in
convolutions
:
for
(
out_channels
,
kernel_size
)
in
convolutions
:
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
:
padding
=
kernel_size
//
2
else
:
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
)
dropout
=
dropout
,
padding
=
padding
)
)
)
in_channels
=
out_channels
in_channels
=
out_channels
self
.
fc2
=
Linear
(
in_channels
,
embed_dim
)
self
.
fc2
=
Linear
(
in_channels
,
embed_dim
)
...
@@ -121,10 +125,14 @@ class FConvEncoder(FairseqEncoder):
...
@@ -121,10 +125,14 @@ class FConvEncoder(FairseqEncoder):
for
proj
,
conv
in
zip
(
self
.
projections
,
self
.
convolutions
):
for
proj
,
conv
in
zip
(
self
.
projections
,
self
.
convolutions
):
residual
=
x
if
proj
is
None
else
proj
(
x
)
residual
=
x
if
proj
is
None
else
proj
(
x
)
x
=
F
.
dropout
(
x
,
p
=
self
.
dropout
,
training
=
self
.
training
)
x
=
F
.
dropout
(
x
,
p
=
self
.
dropout
,
training
=
self
.
training
)
padding_l
=
(
conv
.
kernel_size
[
0
]
-
1
)
//
2
if
conv
.
kernel_size
[
0
]
%
2
==
1
:
padding_r
=
conv
.
kernel_size
[
0
]
//
2
# padding is implicit in the conv
x
=
F
.
pad
(
x
,
(
0
,
0
,
0
,
0
,
padding_l
,
padding_r
))
x
=
conv
(
x
)
x
=
conv
(
x
)
else
:
padding_l
=
(
conv
.
kernel_size
[
0
]
-
1
)
//
2
padding_r
=
conv
.
kernel_size
[
0
]
//
2
x
=
F
.
pad
(
x
,
(
0
,
0
,
0
,
0
,
padding_l
,
padding_r
))
x
=
conv
(
x
)
x
=
F
.
glu
(
x
,
dim
=
2
)
x
=
F
.
glu
(
x
,
dim
=
2
)
x
=
(
x
+
residual
)
*
math
.
sqrt
(
0.5
)
x
=
(
x
+
residual
)
*
math
.
sqrt
(
0.5
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment