Add get_output_embeddings
When load model using from_pretrained method, output embedding weights will not be loaded if it is shared with other weights, like input embedding.
hi, could you provide more details add these two lines can solve the issue you mentioned?
To extend the model's vocabulary, I performed the following steps:
First, I used the from_pretrained() method to load both the model and the image processing processor. Then, I used the tokenizer.add_tokens() method within the processor to add the extended Chinese vocabulary. After that, I expanded the model’s embedding layer by calling model.resize_token_embeddings(). Then, after initializing the weights for the new embeddings, I saved the weights with the expanded vocabulary using model.save_pretrained().
However, since the Florence2ForConditionalGeneration class does not implement the get_output_embeddingsmethod, it will call the get_output_embeddings method from its parent class PreTrainedModel. The parent method returns None, which prevents the embedding weights from being saved correctly. To address this, I added two lines to the Florence2ForConditionalGeneration class.
The process of identifying this issue was quite complex and involved a lot of tracking. I believe adding these two lines will resolve the issue of saving the weights after expanding the vocabulary. Therefore, I have submitted PRs for all four open models. You might want to verify the issue I mentioned.