Add accelerate support for M2M100
#19912
Merged
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