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
d6be0c7e
Commit
d6be0c7e
authored
Apr 07, 2018
by
Myle Ott
Browse files
Use FP32 for multi-head attention softmax
parent
2d27ae08
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
1 deletion
+1
-1
fairseq/modules/multihead_attention.py
fairseq/modules/multihead_attention.py
+1
-1
No files found.
fairseq/modules/multihead_attention.py
View file @
d6be0c7e
...
@@ -129,7 +129,7 @@ class MultiheadAttention(nn.Module):
...
@@ -129,7 +129,7 @@ class MultiheadAttention(nn.Module):
float
(
'-inf'
),
float
(
'-inf'
),
).
type_as
(
attn_weights
)
# FP16 support: cast to float and back
).
type_as
(
attn_weights
)
# FP16 support: cast to float and back
attn_weights
=
attn_weights
.
view
(
bsz
*
self
.
num_heads
,
tgt_len
,
src_len
)
attn_weights
=
attn_weights
.
view
(
bsz
*
self
.
num_heads
,
tgt_len
,
src_len
)
attn_weights
=
F
.
softmax
(
attn_weights
,
dim
=-
1
)
attn_weights
=
F
.
softmax
(
attn_weights
.
float
()
,
dim
=-
1
)
.
type_as
(
attn_weights
)
attn_weights
=
F
.
dropout
(
attn_weights
,
p
=
self
.
dropout
,
training
=
self
.
training
)
attn_weights
=
F
.
dropout
(
attn_weights
,
p
=
self
.
dropout
,
training
=
self
.
training
)
attn
=
torch
.
bmm
(
attn_weights
,
v
)
attn
=
torch
.
bmm
(
attn_weights
,
v
)
...
...
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