Add has_attentions to TFModelTesterMixin as done on PyTorch side (#16259)

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
Yih-Dar 2022-03-19 11:44:17 +01:00 committed by GitHub
parent 8d7420768c
commit f466936476
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 5 deletions

View File

@ -114,6 +114,7 @@ class TFModelTesterMixin:
test_resize_embeddings = True
test_head_masking = True
is_encoder_decoder = False
has_attentions = True
def _prepare_for_class(self, inputs_dict, model_class, return_labels=False) -> dict:
inputs_dict = copy.deepcopy(inputs_dict)
@ -539,9 +540,7 @@ class TFModelTesterMixin:
# Output all for aggressive testing
config.output_hidden_states = True
# Pure convolutional models have no attention
# TODO: use a better and general criteria
if "TFConvNext" not in model_class.__name__:
if self.has_attentions:
config.output_attentions = True
for k in ["attention_mask", "encoder_attention_mask", "decoder_attention_mask"]:
@ -567,8 +566,6 @@ class TFModelTesterMixin:
pt_model_class_name = model_class.__name__[2:] # Skip the "TF" at the beginning
pt_model_class = getattr(transformers, pt_model_class_name)
config.output_hidden_states = True
tf_model = model_class(config)
pt_model = pt_model_class(config)