Add support for Phi-1 and Phi 1.5 #3831
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.
In Transformers 4.36, the transformers library added support for Phi-1 and Phi-1.5 models from Microsoft. However, there are two caveats with using this model:
microsofot/phi-1
andmicosoft/phi-1.5
don't work out of the box since they requireremote_code
to be trusted because the tensor operations are implemented througheinops
instead of PyTorch. Instead, in the original PR that adds support for Phi based models, they add two models that are supported (https://github.com/huggingface/transformers/pull/26170/files#diff-88cb36bfb13c1dc5f52bb952b74697a1c79e286a1a57e4ed3f20ecd5e9f8749bR25):susnato/phi-1_dev
susnato/phi-1_5_dev
This is the recommendation from official phi model docs on huggingface as well: https://huggingface.co/docs/transformers/main/model_doc/phi
My understanding is that someone from the huggingface team has converted the official weights into huggingface compatible weights under the two new mappings. I've filed an issue here to understand what the expected behavior is supposed to be: huggingface/transformers#28049
susnato/phi-1_dev
andsusnato/phi-1_5_dev
don't support todevice_map
auto model load kwarg that we set when we load models in quantized state, say when initializing the model using 4 bit quantization. However, it seems that the model weights get correctly loaded onto the right device depending on the quantization kwargs anyway, so we just skip using this load kwarg for phi based models.Closes #3630