Skip to content

Commit

Permalink
Restore the warning but with the TF logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jplu committed Jan 26, 2021
1 parent d27f266 commit 7657bd2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/transformers/modeling_tf_utils.py
Expand Up @@ -44,6 +44,7 @@


logger = logging.get_logger(__name__)
tf_logger = tf.get_logger()


class TFModelUtilsMixin:
Expand Down Expand Up @@ -278,9 +279,23 @@ def booleans_processing(config, **kwargs):

if "use_cache" in kwargs:
final_booleans["use_cache"] = kwargs["use_cache"] if kwargs["use_cache"] is not None else config.use_cache

else:
if (
kwargs["output_attentions"] is not None
or kwargs["output_hidden_states"] is not None
or ("use_cache" in kwargs and kwargs["use_cache"] is not None)
):
tf_logger.warn(
"The parameters `output_attentions`, `output_hidden_states` and `use_cache` cannot be updated when calling a model."
"They have to be set to True/False in the config object (i.e.: `config=XConfig.from_pretrained('name', output_attentions=True)`)."
)

final_booleans["output_attentions"] = config.output_attentions
final_booleans["output_hidden_states"] = config.output_hidden_states

if kwargs["return_dict"] is not None:
tf_logger.warn("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:
Expand Down

0 comments on commit 7657bd2

Please sign in to comment.