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
chenpangpang
transformers
Commits
8bdee1cb
Commit
8bdee1cb
authored
Sep 11, 2019
by
Zili Wang
Browse files
fixed: hard coding for max and min number will out of range in fp16, which will cause nan.
parent
7424b284
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
+26
-15
pytorch_transformers/modeling_transfo_xl.py
pytorch_transformers/modeling_transfo_xl.py
+21
-13
pytorch_transformers/modeling_utils.py
pytorch_transformers/modeling_utils.py
+5
-2
No files found.
pytorch_transformers/modeling_transfo_xl.py
View file @
8bdee1cb
...
@@ -451,9 +451,17 @@ class RelPartialLearnableMultiHeadAttn(RelMultiHeadAttn):
...
@@ -451,9 +451,17 @@ class RelPartialLearnableMultiHeadAttn(RelMultiHeadAttn):
if
attn_mask
is
not
None
and
torch
.
sum
(
attn_mask
).
item
():
if
attn_mask
is
not
None
and
torch
.
sum
(
attn_mask
).
item
():
attn_mask
=
(
attn_mask
==
1
)
# Switch to bool
attn_mask
=
(
attn_mask
==
1
)
# Switch to bool
if
attn_mask
.
dim
()
==
2
:
if
attn_mask
.
dim
()
==
2
:
if
next
(
self
.
parameters
()).
dtype
==
torch
.
float16
:
attn_score
=
attn_score
.
float
().
masked_fill
(
attn_mask
[
None
,:,:,
None
],
-
65000
).
type_as
(
attn_score
)
else
:
attn_score
=
attn_score
.
float
().
masked_fill
(
attn_score
=
attn_score
.
float
().
masked_fill
(
attn_mask
[
None
,:,:,
None
],
-
1e30
).
type_as
(
attn_score
)
attn_mask
[
None
,:,:,
None
],
-
1e30
).
type_as
(
attn_score
)
elif
attn_mask
.
dim
()
==
3
:
elif
attn_mask
.
dim
()
==
3
:
if
next
(
self
.
parameters
()).
dtype
==
torch
.
float16
:
attn_score
=
attn_score
.
float
().
masked_fill
(
attn_mask
[:,:,:,
None
],
-
65000
).
type_as
(
attn_score
)
else
:
attn_score
=
attn_score
.
float
().
masked_fill
(
attn_score
=
attn_score
.
float
().
masked_fill
(
attn_mask
[:,:,:,
None
],
-
1e30
).
type_as
(
attn_score
)
attn_mask
[:,:,:,
None
],
-
1e30
).
type_as
(
attn_score
)
...
...
pytorch_transformers/modeling_utils.py
View file @
8bdee1cb
...
@@ -434,6 +434,9 @@ class PoolerStartLogits(nn.Module):
...
@@ -434,6 +434,9 @@ class PoolerStartLogits(nn.Module):
x
=
self
.
dense
(
hidden_states
).
squeeze
(
-
1
)
x
=
self
.
dense
(
hidden_states
).
squeeze
(
-
1
)
if
p_mask
is
not
None
:
if
p_mask
is
not
None
:
if
next
(
self
.
parameters
()).
dtype
==
torch
.
float16
:
x
=
x
*
(
1
-
p_mask
)
-
65500
*
p_mask
else
:
x
=
x
*
(
1
-
p_mask
)
-
1e30
*
p_mask
x
=
x
*
(
1
-
p_mask
)
-
1e30
*
p_mask
return
x
return
x
...
...
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