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
d735b074
Unverified
Commit
d735b074
authored
Jan 04, 2021
by
Julien Plu
Committed by
GitHub
Jan 04, 2021
Browse files
Fix Flaubert (#9292)
parent
5dd389d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
9 deletions
+6
-9
src/transformers/models/flaubert/modeling_tf_flaubert.py
src/transformers/models/flaubert/modeling_tf_flaubert.py
+6
-9
No files found.
src/transformers/models/flaubert/modeling_tf_flaubert.py
View file @
d735b074
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
"""
"""
import
itertools
import
itertools
import
random
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
Optional
,
Tuple
from
typing
import
Optional
,
Tuple
...
@@ -596,15 +597,15 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer):
...
@@ -596,15 +597,15 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer):
tensor
=
tensor
*
mask
[...,
tf
.
newaxis
]
tensor
=
tensor
*
mask
[...,
tf
.
newaxis
]
# hidden_states and attentions cannot be None in graph mode.
# hidden_states and attentions cannot be None in graph mode.
hidden_states
=
()
hidden_states
=
()
if
inputs
[
"output_hidden_states"
]
else
None
attentions
=
()
attentions
=
()
if
inputs
[
"output_attentions"
]
else
None
# transformer layers
# transformer layers
for
i
in
range
(
self
.
n_layers
):
for
i
in
range
(
self
.
n_layers
):
# LayerDrop
# LayerDrop
dropout_probability
=
tf
.
random
.
uniform
(
[
1
],
0
,
1
)
dropout_probability
=
random
.
uniform
(
0
,
1
)
if
inputs
[
"training"
]
and
tf
.
less
(
dropout_probability
,
self
.
layerdrop
):
if
inputs
[
"training"
]
and
(
dropout_probability
<
self
.
layerdrop
):
continue
continue
if
inputs
[
"output_hidden_states"
]:
if
inputs
[
"output_hidden_states"
]:
...
@@ -642,7 +643,7 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer):
...
@@ -642,7 +643,7 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer):
)
)
attn
=
attn_outputs
[
0
]
attn
=
attn_outputs
[
0
]
if
output_attentions
:
if
inputs
[
"
output_attentions
"
]
:
attentions
=
attentions
+
(
attn_outputs
[
1
],)
attentions
=
attentions
+
(
attn_outputs
[
1
],)
attn
=
self
.
dropout
(
attn
,
training
=
inputs
[
"training"
])
attn
=
self
.
dropout
(
attn
,
training
=
inputs
[
"training"
])
...
@@ -676,10 +677,6 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer):
...
@@ -676,10 +677,6 @@ class TFFlaubertMainLayer(tf.keras.layers.Layer):
# move back sequence length to dimension 0
# move back sequence length to dimension 0
# tensor = tensor.transpose(0, 1)
# tensor = tensor.transpose(0, 1)
# Set to None here if the output booleans are at False
hidden_states
=
hidden_states
if
inputs
[
"output_hidden_states"
]
else
None
attentions
=
attentions
if
inputs
[
"output_attentions"
]
else
None
if
not
inputs
[
"return_dict"
]:
if
not
inputs
[
"return_dict"
]:
return
tuple
(
v
for
v
in
[
tensor
,
hidden_states
,
attentions
]
if
v
is
not
None
)
return
tuple
(
v
for
v
in
[
tensor
,
hidden_states
,
attentions
]
if
v
is
not
None
)
...
...
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