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

[Lazy init] Force fall back to slow init for composite models #11705

Merged
merged 5 commits into from
May 12, 2021

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented May 12, 2021

What does this PR do?

Thanks to the great issue #11704 it was discovered that fast initialization currently breaks for all models whose XXXPreTrainedModel does not implement a _init_weights function and for which parts of the weights are missing when using .from_pretrained(...). This includes essentially all composite models, being Rag and EncoderDecoder.

This PR does the vanilla fix of forcing those models to fall back on _slow_init since a better fix requires a careful re-design which is left for a future PR.

Future PR

  • Remove hacky from_pretrained(...) methods in RAG and EncoderDecoder
  • Refactor the way "fast_init" calls model._init_weights for composite models. For Composite models, each part has to be called directly =>
model.encoder._init_weigths(all_missing_keys_of_encoder)
model.decoder._init_weigths(all_missing_keys_of_decoder)
  • Add more tests for RAG & EncoderDecoder

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Eventually would be nice to add a test for this, as this is an issue that should have been caught by the tests!

Thanks for the hotfix.

src/transformers/models/rag/modeling_rag.py Outdated Show resolved Hide resolved
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.

LGTM for a hotfix.

@LysandreJik LysandreJik merged commit fd6204b into huggingface:master May 12, 2021
Iwontbecreative pushed a commit to Iwontbecreative/transformers that referenced this pull request Jul 15, 2021
…gface#11705)

* fix encoder-decoder & RAG

* finalize

* Update src/transformers/models/encoder_decoder/modeling_encoder_decoder.py

Co-authored-by: Lysandre Debut <[email protected]>

* Update src/transformers/models/rag/modeling_rag.py

Co-authored-by: Lysandre Debut <[email protected]>

Co-authored-by: Patrick von Platen <[email protected]>
Co-authored-by: Lysandre Debut <[email protected]>
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.

[RAG] official facebook example code for RAG is not working anymore.
3 participants