@@ -67,6 +67,7 @@ class ModelTesterMixin:
67
67
test_resize_position_embeddings = False
68
68
test_mismatched_shapes = True
69
69
test_missing_keys = True
70
+ test_model_compatibility_keys = False
70
71
use_test_inputs_embeds = False
71
72
use_test_model_name_list = True
72
73
is_encoder_decoder = False
@@ -542,6 +543,31 @@ def random_choice_pretrained_config_field(self) -> Optional[str]:
542
543
fields = [key for key , value in config .to_dict () if value ]
543
544
return random .choice (fields )
544
545
546
+ def test_for_missed_attribute (self ):
547
+ if not self .test_model_compatibility_keys :
548
+ self .skipTest (f"Do not test model_compatibility_keys on { self .base_model_class } " )
549
+ return
550
+
551
+ config , inputs_dict = self .model_tester .prepare_config_and_inputs_for_common ()
552
+ for model_class in self .all_model_classes :
553
+ if not model_class .constructed_from_pretrained_config ():
554
+ continue
555
+
556
+ model = self ._make_model_instance (config , model_class )
557
+
558
+ all_maps : dict = copy .deepcopy (model_class .config_class .attribute_map )
559
+ all_maps .update (model_class .config_class .standard_config_map )
560
+
561
+ for old_attribute , new_attribute in all_maps .items ():
562
+ old_value = getattr (model , old_attribute )
563
+ new_value = getattr (model , new_attribute )
564
+
565
+ # eg: dropout can be an instance of nn.Dropout, so we should check it attribute
566
+ if type (new_value ) != type (old_value ):
567
+ continue
568
+
569
+ self .assertEqual (old_value , new_value )
570
+
545
571
546
572
class ModelTesterPretrainedMixin :
547
573
base_model_class : PretrainedModel = None
0 commit comments