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
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- 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
Update README.md
Browse files
README.md
CHANGED
|
@@ -43,8 +43,6 @@ where the model generates the code after the comments. (Note: This is a legitima
|
|
| 43 |
|
| 44 |
* Direct adoption for production coding tasks is out of the scope of this research project. As a result, Phi-1 has not been tested to ensure that it performs adequately for production-level code. Please refer to the limitation sections of this document for more details.
|
| 45 |
|
| 46 |
-
* If you are using `transformers<4.37.0`, always load the model with `trust_remote_code=True` to prevent side-effects.
|
| 47 |
-
|
| 48 |
## Sample Code
|
| 49 |
|
| 50 |
```python
|
|
@@ -53,8 +51,8 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 53 |
|
| 54 |
torch.set_default_device("cuda")
|
| 55 |
|
| 56 |
-
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1", torch_dtype="auto"
|
| 57 |
-
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1"
|
| 58 |
|
| 59 |
inputs = tokenizer('''def print_prime(n):
|
| 60 |
"""
|
|
@@ -73,6 +71,7 @@ print(text)
|
|
| 73 |
* Replicate Scripts Online: As our model is trained on Python scripts found online, there is a small chance it may replicate such scripts, especially if they appear repetitively across different online sources.
|
| 74 |
|
| 75 |
* Generate Inaccurate Code: The model frequently generates incorrect code. We suggest that users view these outputs as a source of inspiration rather than definitive solutions.
|
|
|
|
| 76 |
* Unreliable Responses to Alternate Formats: Despite appearing to comprehend instructions in formats like Q&A or chat, our models often respond with inaccurate answers, even when seeming confident. Their capabilities with non-code formats are significantly more limited.
|
| 77 |
|
| 78 |
* Limitations on Natural Language Comprehension. As a coding bot, Phi-1's main focus is to help with coding-related questions. While it may have some natural language comprehension capabilities, its primary function is not to engage in general conversations or demonstrate common sense like a general AI assistant. Its strength lies in providing assistance and guidance in the context of programming and software development.
|
|
|
|
| 43 |
|
| 44 |
* Direct adoption for production coding tasks is out of the scope of this research project. As a result, Phi-1 has not been tested to ensure that it performs adequately for production-level code. Please refer to the limitation sections of this document for more details.
|
| 45 |
|
|
|
|
|
|
|
| 46 |
## Sample Code
|
| 47 |
|
| 48 |
```python
|
|
|
|
| 51 |
|
| 52 |
torch.set_default_device("cuda")
|
| 53 |
|
| 54 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1", torch_dtype="auto")
|
| 55 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1")
|
| 56 |
|
| 57 |
inputs = tokenizer('''def print_prime(n):
|
| 58 |
"""
|
|
|
|
| 71 |
* Replicate Scripts Online: As our model is trained on Python scripts found online, there is a small chance it may replicate such scripts, especially if they appear repetitively across different online sources.
|
| 72 |
|
| 73 |
* Generate Inaccurate Code: The model frequently generates incorrect code. We suggest that users view these outputs as a source of inspiration rather than definitive solutions.
|
| 74 |
+
|
| 75 |
* Unreliable Responses to Alternate Formats: Despite appearing to comprehend instructions in formats like Q&A or chat, our models often respond with inaccurate answers, even when seeming confident. Their capabilities with non-code formats are significantly more limited.
|
| 76 |
|
| 77 |
* Limitations on Natural Language Comprehension. As a coding bot, Phi-1's main focus is to help with coding-related questions. While it may have some natural language comprehension capabilities, its primary function is not to engage in general conversations or demonstrate common sense like a general AI assistant. Its strength lies in providing assistance and guidance in the context of programming and software development.
|