Instructions to use microsoft/phi-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/phi-1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/phi-1")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1") model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1") - Inference
- Local Apps Settings
- vLLM
How to use microsoft/phi-1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/phi-1" # 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-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/phi-1
- SGLang
How to use microsoft/phi-1 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-1" \ --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-1", "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-1" \ --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-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/phi-1 with Docker Model Runner:
docker model run hf.co/microsoft/phi-1
more fixes
Browse files- configuration_phi.py +2 -2
- modeling_phi.py +5 -5
configuration_phi.py
CHANGED
|
@@ -23,8 +23,8 @@ from transformers.utils import logging
|
|
| 23 |
logger = logging.get_logger(__name__)
|
| 24 |
|
| 25 |
PHI_PRETRAINED_CONFIG_ARCHIVE_MAP = {
|
| 26 |
-
"microsoft/phi-1": "https://huggingface.co/
|
| 27 |
-
"microsoft/phi-1_5": "https://huggingface.co/
|
| 28 |
}
|
| 29 |
|
| 30 |
|
|
|
|
| 23 |
logger = logging.get_logger(__name__)
|
| 24 |
|
| 25 |
PHI_PRETRAINED_CONFIG_ARCHIVE_MAP = {
|
| 26 |
+
"microsoft/phi-1": "https://huggingface.co/microsoft/phi-1/resolve/main/config.json",
|
| 27 |
+
"microsoft/phi-1_5": "https://huggingface.co/microsoft/phi-1_5/resolve/main/config.json",
|
| 28 |
}
|
| 29 |
|
| 30 |
|
modeling_phi.py
CHANGED
|
@@ -52,12 +52,12 @@ if is_flash_attn_2_available():
|
|
| 52 |
|
| 53 |
logger = logging.get_logger(__name__)
|
| 54 |
|
| 55 |
-
_CHECKPOINT_FOR_DOC = "
|
| 56 |
_CONFIG_FOR_DOC = "PhiConfig"
|
| 57 |
|
| 58 |
PHI_PRETRAINED_MODEL_ARCHIVE_LIST = [
|
| 59 |
-
"
|
| 60 |
-
"
|
| 61 |
# See all Phi models at https://huggingface.co/models?filter=phi
|
| 62 |
]
|
| 63 |
|
|
@@ -978,8 +978,8 @@ class PhiForCausalLM(PhiPreTrainedModel):
|
|
| 978 |
```python
|
| 979 |
>>> from transformers import AutoTokenizer, PhiForCausalLM
|
| 980 |
|
| 981 |
-
>>> model = PhiForCausalLM.from_pretrained("
|
| 982 |
-
>>> tokenizer = AutoTokenizer.from_pretrained("
|
| 983 |
|
| 984 |
>>> prompt = "This is an example script ."
|
| 985 |
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
|
|
|
| 52 |
|
| 53 |
logger = logging.get_logger(__name__)
|
| 54 |
|
| 55 |
+
_CHECKPOINT_FOR_DOC = "microsoft/phi-1"
|
| 56 |
_CONFIG_FOR_DOC = "PhiConfig"
|
| 57 |
|
| 58 |
PHI_PRETRAINED_MODEL_ARCHIVE_LIST = [
|
| 59 |
+
"microsoft/phi-1",
|
| 60 |
+
"microsoft/phi-1_5",
|
| 61 |
# See all Phi models at https://huggingface.co/models?filter=phi
|
| 62 |
]
|
| 63 |
|
|
|
|
| 978 |
```python
|
| 979 |
>>> from transformers import AutoTokenizer, PhiForCausalLM
|
| 980 |
|
| 981 |
+
>>> model = PhiForCausalLM.from_pretrained("microsoft/phi-1_5")
|
| 982 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1_5")
|
| 983 |
|
| 984 |
>>> prompt = "This is an example script ."
|
| 985 |
>>> inputs = tokenizer(prompt, return_tensors="pt")
|