Add accelerate support for M2M100#19912
Merged
younesbelkada merged 2 commits intohuggingface:mainfrom Oct 27, 2022
Merged
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
sgugger
approved these changes
Oct 27, 2022
Collaborator
sgugger
left a comment
There was a problem hiding this comment.
LGTM, thanks for fixing!
Comment on lines
+782
to
+783
| if embed_pos.device != inputs_embeds.device: | ||
| embed_pos = embed_pos.to(inputs_embeds.device) |
Collaborator
There was a problem hiding this comment.
I don't think you need the test, it's already done inside the to method to default to a noop :-)
Comment on lines
+1017
to
+1018
| if positions.device != inputs_embeds.device: | ||
| positions = positions.to(inputs_embeds.device) |
a2171bf to
208e9e6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 adds
acceleratesupport toM2M100, therefore this enables loading NLLB models in 8-bit usingload_in_8bit=True.This might contain a breaking change but I am not sure.
When initializing the model in the meta device using
acceleratethe moduleself.sharedis intialized and set to the correct device usingset_tensor_to_devicethrice - since it is shared by 3 modules (base model, encoder, decoder) - so it somehow ends up being on themetadevice.Therefore manually assigning a new module with the weights that correspond to the weights of the
sharedmodule should do the trick. But I am wondering if this is a breaking change since thesharedmodule of the Encoder & Decoder won't be "shared" anymore. It should not be a problem at inference time, but can be problematic when training the model.cc @sgugger
Also I know T5 also supports
accelerateand usessharedembeddings. The only difference I see from both implementations are the_keys_to_ignore_on_load_missingthat contains thesharedweights forT5and doesn't contain the shared weights for M2M100