Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only call get_output_embeddings when tie_word_embeddings is set #16667

Merged
merged 1 commit into from
Apr 12, 2022
Merged

Only call get_output_embeddings when tie_word_embeddings is set #16667

merged 1 commit into from
Apr 12, 2022

Conversation

smelm
Copy link
Contributor

@smelm smelm commented Apr 8, 2022

What does this PR do?

This PR just changes the order in which two conditions in tie_weights in the PreTrainedModel 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 when tie_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

This avoids an unnecessary call and avoids problems during
initialization of class hierarchies.
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 8, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a reasonable change. Thanks for your PR!
Also pinging @LysandreJik since it touches the core model file.

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me!

@sgugger sgugger merged commit b9f12be into huggingface:main Apr 12, 2022
elusenji pushed a commit to elusenji/transformers that referenced this pull request Jun 12, 2022
…ingface#16667)

This avoids an unnecessary call and avoids problems during
initialization of class hierarchies.

Co-authored-by: Samuel Melm <samuel.melm@stud.uni-heidelberg.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants