-
Notifications
You must be signed in to change notification settings - Fork 687
Add Phi-4-mini README.md #9302
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
Merged
Merged
Add Phi-4-mini README.md #9302
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad63a2d
Create README.md
jackzhxng ee1058e
Merge branch 'main' into jz/phi-4-mini-readme
jackzhxng 0484d16
Update checkpointer phi version
jackzhxng 2b87df7
Merge branch 'main' into jz/phi-4-mini-readme
jackzhxng 80c1811
Update README.md
jackzhxng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## Summary | ||
Phi-4-mini Instruct (3.8B) is a newly released version of the popular Phi-4 model developed by Microsoft. | ||
|
||
## Instructions | ||
|
||
Phi-4-mini uses the same example code as Llama, while the checkpoint, model params, and tokenizer are different. Please see the [Llama README page](../llama/README.md) for details. | ||
|
||
All commands for exporting and running Llama on various backends should also be applicable to Phi-4-mini, by swapping the following args: | ||
``` | ||
--model phi_4_mini | ||
--params examples/models/phi-4-mini/config.json | ||
--checkpoint <path-to-meta-checkpoint> | ||
``` | ||
|
||
### Generate the Checkpoint | ||
The original checkpoint can be obtained from HuggingFace: | ||
``` | ||
huggingface-cli download microsoft/Phi-4-mini-instruct | ||
``` | ||
|
||
We then convert it to Meta's checkpoint format: | ||
``` | ||
python examples/models/phi-4-mini/convert_weights.py <path-to-checkpoint-dir> <output-path> | ||
``` | ||
|
||
### Example export and run | ||
Here is an basic example for exporting and running Phi-4-mini, although please refer to [Llama README page](../llama/README.md) for more advanced usage. | ||
|
||
Export to XNNPack, no quantization: | ||
``` | ||
# No quantization | ||
# Set these paths to point to the downloaded files | ||
PHI_CHECKPOINT=path/to/checkpoint.pth | ||
|
||
python -m examples.models.llama.export_llama \ | ||
--model phi_4_mini \ | ||
--checkpoint "${PHI_CHECKPOINT=path/to/checkpoint.pth:?}" \ | ||
--params examples/models/phi-4-mini/config.json \ | ||
-kv \ | ||
--use_sdpa_with_kv_cache \ | ||
-d fp32 \ | ||
-X \ | ||
--metadata '{"get_bos_id":151643, "get_eos_ids":[151643]}' \ | ||
--output_name="phi-4-mini.pte" | ||
--verbose | ||
``` | ||
|
||
Run using the executor runner: | ||
``` | ||
# Currently a work in progress, just need to enable HuggingFace json tokenizer in C++. | ||
# In the meantime, can run with an example Python runner with pybindings: | ||
|
||
python -m examples.models.llama.runner.native | ||
--model phi_4_mini | ||
--pte <path-to-pte> | ||
-kv | ||
--tokenizer <path-to-tokenizer>/tokenizer.json | ||
--tokenizer_config <path-to_tokenizer>/tokenizer_config.json | ||
--prompt "What is in a california roll?" | ||
--params examples/models/phi-4-mini/config.json | ||
--max_len 64 | ||
--temperature 0 | ||
``` |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a note here to suggest to users to make sure they have installed ET with pybindings? Although is that the default now already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, by default now