Persist embedding type of BART and mBART models after resize (#32242)
* fix: persist embedding type of MBartConditonalGeneration after resize * fix: persist embedding type of BartConditonalGeneration after resize
This commit is contained in:
@@ -518,6 +518,18 @@ class BartModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin
|
||||
def test_load_save_without_tied_weights(self):
|
||||
pass
|
||||
|
||||
def test_resize_embeddings_persists_embeddings_type(self):
|
||||
config, inputs_dict = self.model_tester.prepare_config_and_inputs()
|
||||
|
||||
config.scale_embedding = True
|
||||
model = BartForConditionalGeneration(config)
|
||||
old_type = type(model.model.decoder.embed_tokens)
|
||||
|
||||
model.resize_token_embeddings(new_num_tokens=config.vocab_size)
|
||||
|
||||
new_type = type(model.model.decoder.embed_tokens)
|
||||
self.assertIs(old_type, new_type)
|
||||
|
||||
|
||||
def assert_tensors_close(a, b, atol=1e-12, prefix=""):
|
||||
"""If tensors have different shapes, different values or a and b are not both tensors, raise a nice Assertion error."""
|
||||
|
||||
Reference in New Issue
Block a user