Instructions to use microsoft/phi-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/phi-2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/phi-2")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2") model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/phi-2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/phi-2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/phi-2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/phi-2
- SGLang
How to use microsoft/phi-2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "microsoft/phi-2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/phi-2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "microsoft/phi-2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/phi-2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/phi-2 with Docker Model Runner:
docker model run hf.co/microsoft/phi-2
Commit History
-
Update README.md (#146)
Verified signature- Update README.md (5796513e0346968b2a3e18347ceeae6da032e31c) Co-authored-by: Blake S <[email protected]>810d367 -
Upload data_summary_card.md (#145)
Verified signature- Upload data_summary_card.md (47f4b0f4d967d1f9a06ed2994c1a608d7f6a9191) Co-authored-by: Blake S <[email protected]>8ca3f13
-
fix(config): Removes auto_map since it will not be used anymore.
Verified signatureef38235 -
Delete configuration_phi.py
Verified signature6c4befe -
Delete modeling_phi.py
Verified signatureda135b7 -
Update README.md
Verified signaturec929c77
-
Update README.md
Verified signature710686f -
Update README.md
Verified signature523a3d6 -
Readme: fix generation, update transformers version instructions (#121)
Verified signature- Readme: fix generation, update transformers version instructions (96bc18c2e7946021a4f821caa7d6a32484bde76e) Co-authored-by: Pedro Cuenca <[email protected]>7e13090
-
Update LICENSE
Verified signatureb10c3eb
-
Add EOS token (#100)
Verified signature- Add EOS token (ec7094f5d65a66ec033c08f90729f72f2603e2a1) Co-authored-by: Joao Gante <[email protected]>3f879ff -
Add EOS token to the generation config (#101)
Verified signature- Add EOS token to the generation config (9a5117d15e407c48fa40f8adbac1244abae52d6f) Co-authored-by: Joao Gante <[email protected]>313453c
-
Update README.md
Verified signaturecb02e3e -
Update config.json
Verified signaturef05bc51
-
Update modeling_phi.py
Verified signature85d00b0
-
Update modeling_phi.py
Verified signature1a4c7ae
-
Update modeling_phi.py
Verified signatureaccfee5 -
Update README.md
Verified signature39afec1
-
Update modeling_phi.py
Verified signatureeb8bbd1
-
Upload 8 files
Verified signaturecb2f453
-
Update README.md (#69)
- Update README.md (36b427216ebb497ea0091db5187760725c3164ac) Co-authored-by: Ikko Eltociear Ashimine <[email protected]>834565c
-
updating notice.md (#66)
- updating notice.md (adfcd3040c143799fc2dad87759e603141fbb804) Co-authored-by: Mojan Javaheripi <[email protected]>e35b92d -
Update README.md (#65)
- Update README.md (0a71a888c558a911518f81f6c0b728774a7ff744) Co-authored-by: Mojan Javaheripi <[email protected]>a63c22c
-
Upload README.md
c46d6cf -
Upload 3 files
7e10f3e
-
Upload 2 files
d318676 -
Update config.json
5d8f23d -
Upload 4 files
40b720d -
Update README.md
25a6b01 -
Update README.md
ca30dd4 -
Disables inference API to prevent mismatch with HF implementation.
98e33aa -
Update README.md (#2)
- Update README.md (93093db3a799f04d6d2a4850749bc5fd6b896781) Co-authored-by: Mojan Javaheripi <[email protected]>e22cfa2 -
Uploading license and readme files (#1)
- Uploading license and readme files (7773e2a3084a285688d050a6c490d7f51371e1ac) Co-authored-by: Mojan Javaheripi <[email protected]>b800bab -
Update config.json
96f15ad -
Upload PhiForCausalLM
f6ba9c8 -
Upload tokenizer
3fee371 -
initial commit
fb2b714