Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@ def __init__(self, config: PreTrainedConfig, *inputs, **kwargs):
# when a different component (e.g. language_model) is used.
self._keep_in_fp32_modules = copy.copy(self.__class__._keep_in_fp32_modules)
self._keep_in_fp32_modules_strict = copy.copy(self.__class__._keep_in_fp32_modules_strict)
self._tied_weights_keys = copy.copy(self.__class__._tied_weights_keys)
Comment thread
zucchini-nlp marked this conversation as resolved.
Comment thread
zucchini-nlp marked this conversation as resolved.
self.dtype_plan = {}

if isinstance(self._keep_in_fp32_modules, list):
Expand Down
19 changes: 19 additions & 0 deletions tests/models/deformable_detr/test_modeling_deformable_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ def test_deformable_detr_object_detection_head_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_deformable_detr_object_detection_head_model(*config_and_inputs)

def test_tie_weights_is_not_modified(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
config.tie_word_embeddings = True

config.with_box_refine = True
config.two_stage = True

model = DeformableDetrForObjectDetection(config)
self.assertTrue("model.decoder.bbox_embed" in model._tied_weights_keys)
self.assertTrue("model.decoder.class_embed" in model._tied_weights_keys)

# if we update config attr, model's tied weights keys also change
config.with_box_refine = False
config.two_stage = False

model = DeformableDetrForObjectDetection(config)
self.assertFalse("model.decoder.bbox_embed" in model._tied_weights_keys)
self.assertFalse("model.decoder.class_embed" in model._tied_weights_keys)
Comment thread
zucchini-nlp marked this conversation as resolved.

@unittest.skip(reason="Deformable DETR does not use inputs_embeds")
def test_inputs_embeds(self):
pass
Expand Down
13 changes: 13 additions & 0 deletions tests/models/grounding_dino/test_modeling_grounding_dino.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,19 @@ def test_feed_forward_chunking(self):
def test_load_save_without_tied_weights(self):
pass

def test_tie_weights_is_not_modified(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
config.tie_word_embeddings = True

config.decoder_bbox_embed_share = False
model = GroundingDinoForObjectDetection(config)
self.assertFalse(r"bbox_embed.(?![0])\d+" in model._tied_weights_keys)

# if we update config attr, model's tied weights keys also change
config.decoder_bbox_embed_share = True
model = GroundingDinoForObjectDetection(config)
self.assertTrue(r"bbox_embed.(?![0])\d+" in model._tied_weights_keys)

def test_attention_outputs(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
config.return_dict = True
Expand Down