Only call get_output_embeddings when tie_word_embeddings is set #16667
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR just changes the order in which two conditions in
tie_weights
in thePreTrainedModel
class are checked. This would allow us (and probably others) to avoid problems when initializing child classes of models.In our (maybe somewhat specific use case) we encounter a problem when initializing a child class of a model. During the call of the parent constructor (
PreTrainedModel
)get_ourput_embeddings
of the child class is called when it is not completely initialized. This also happens whentie_word_embeddings=False
and the output embeddings are not even needed. Changing the order of the conditions fixes the problem without changing the functionality.Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@patrickvonplaten, @thomwolf, @sgugger