Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
fcefa200
Unverified
Commit
fcefa200
authored
Jul 12, 2022
by
Joao Gante
Committed by
GitHub
Jul 12, 2022
Browse files
TF: remove graph mode distinction when processing boolean options (#18102)
parent
bc34c211
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
36 deletions
+14
-36
src/transformers/modeling_tf_utils.py
src/transformers/modeling_tf_utils.py
+14
-36
No files found.
src/transformers/modeling_tf_utils.py
View file @
fcefa200
...
...
@@ -346,8 +346,7 @@ class TFNextSentencePredictionLoss:
def
booleans_processing
(
config
,
**
kwargs
):
"""
Process the input booleans of each model in order to be sure they are compliant with the execution mode (eager or
graph)
Process the input booleans of each model.
Args:
config ([`PretrainedConfig`]):
...
...
@@ -360,7 +359,6 @@ def booleans_processing(config, **kwargs):
"""
final_booleans
=
{}
if
tf
.
executing_eagerly
():
# Pure conv models (such as ConvNext) do not have `output_attentions`. If the signature has
# `output_attentions`, it will be present here in `kwargs`, even if unset (in that case, as `None`)
if
"output_attentions"
in
kwargs
:
...
...
@@ -368,34 +366,14 @@ def booleans_processing(config, **kwargs):
kwargs
[
"output_attentions"
]
if
kwargs
[
"output_attentions"
]
is
not
None
else
config
.
output_attentions
)
final_booleans
[
"output_hidden_states"
]
=
(
kwargs
[
"output_hidden_states"
]
if
kwargs
[
"output_hidden_states"
]
is
not
None
else
config
.
output_hidden_states
)
final_booleans
[
"return_dict"
]
=
(
kwargs
[
"return_dict"
]
if
kwargs
[
"return_dict"
]
is
not
None
else
config
.
return_dict
kwargs
[
"output_hidden_states"
]
if
kwargs
[
"output_hidden_states"
]
is
not
None
else
config
.
output_hidden_states
)
final_booleans
[
"return_dict"
]
=
kwargs
[
"return_dict"
]
if
kwargs
[
"return_dict"
]
is
not
None
else
config
.
return_dict
if
"use_cache"
in
kwargs
:
final_booleans
[
"use_cache"
]
=
(
kwargs
[
"use_cache"
]
if
kwargs
[
"use_cache"
]
is
not
None
else
getattr
(
config
,
"use_cache"
,
None
)
)
else
:
# Pure conv models (such as ConvNext) do not have `output_attentions`. If the signature has
# `output_attentions`, it will be present here in `kwargs`, even if unset (in that case, as `None`)
if
"output_attentions"
in
kwargs
:
final_booleans
[
"output_attentions"
]
=
config
.
output_attentions
final_booleans
[
"output_hidden_states"
]
=
config
.
output_hidden_states
if
kwargs
.
get
(
"return_dict"
,
None
)
not
in
(
None
,
True
):
tf_logger
.
warning
(
"The parameter `return_dict` cannot be set in graph mode and will always be set to `True`."
)
final_booleans
[
"return_dict"
]
=
True
if
"use_cache"
in
kwargs
:
final_booleans
[
"use_cache"
]
=
getattr
(
config
,
"use_cache"
,
None
)
return
final_booleans
...
...
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