Skip to content

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

Merged
LysandreJik merged 5 commits intohuggingface:masterfrom
patrickvonplaten:fix_init
May 12, 2021
Merged

[Lazy init] Force fall back to slow init for composite models#11705
LysandreJik merged 5 commits intohuggingface:masterfrom
patrickvonplaten:fix_init

Conversation

@patrickvonplaten
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/transformers/models/encoder_decoder/modeling_encoder_decoder.py Outdated
Comment thread src/transformers/models/rag/modeling_rag.py Outdated
Copy link
Copy Markdown
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.

patrickvonplaten and others added 2 commits May 12, 2021 15:34
…er.py

Co-authored-by: Lysandre Debut <lysandre@huggingface.co>
Co-authored-by: Lysandre Debut <lysandre@huggingface.co>
@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 <lysandre@huggingface.co>

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

Co-authored-by: Lysandre Debut <lysandre@huggingface.co>

Co-authored-by: Patrick von Platen <patrick@huggingface.co>
Co-authored-by: Lysandre Debut <lysandre@huggingface.co>
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