Text Generation
Transformers
Safetensors
English
phi3
nlp
code
conversational
custom_code
Eval Results
text-generation-inference
Instructions to use microsoft/Phi-3-mini-128k-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Phi-3-mini-128k-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/Phi-3-mini-128k-instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-128k-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-128k-instruct", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Phi-3-mini-128k-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Phi-3-mini-128k-instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-mini-128k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/Phi-3-mini-128k-instruct
- SGLang
How to use microsoft/Phi-3-mini-128k-instruct 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-3-mini-128k-instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-mini-128k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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-3-mini-128k-instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-mini-128k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/Phi-3-mini-128k-instruct with Docker Model Runner:
docker model run hf.co/microsoft/Phi-3-mini-128k-instruct
Update the chat format (#1)
Browse files- Update the chat format (50cb625d6273a5d22911ae4c64b05eda4fa7c2aa)
Co-authored-by: Nguyen Bach <nguyenbh@users.noreply.huggingface.co>
README.md
CHANGED
|
@@ -54,30 +54,29 @@ The current `transformers` version can be verified with: `pip list | grep transf
|
|
| 54 |
|
| 55 |
### Chat Format:
|
| 56 |
|
| 57 |
-
Given the nature of the training data, the Phi-3 Mini-128K-Instruct model is best suited for prompts using the chat format as follows.
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
```markdown
|
| 60 |
<|system|>
|
| 61 |
-
You are a helpful AI assistant.
|
| 62 |
-
<|end|>
|
| 63 |
<|user|>
|
| 64 |
-
How to explain Internet for a medieval knight?
|
| 65 |
-
<|end|>
|
| 66 |
<|assistant|>
|
| 67 |
```
|
| 68 |
|
| 69 |
-
where the model generates the text after `<|assistant|>`
|
| 70 |
|
| 71 |
```markdown
|
| 72 |
<|system|>
|
| 73 |
-
You are a helpful AI assistant.
|
| 74 |
-
<|end|>
|
| 75 |
<|user|>
|
| 76 |
-
I am going to Paris, what should I see?
|
| 77 |
-
<|end|>
|
| 78 |
<|assistant|>
|
| 79 |
-
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:\n\n1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.\n3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.\n\nThese are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world."
|
| 80 |
-
<|end|>
|
| 81 |
<|user|>
|
| 82 |
What is so great about #1?
|
| 83 |
<|assistant|>
|
|
|
|
| 54 |
|
| 55 |
### Chat Format:
|
| 56 |
|
| 57 |
+
Given the nature of the training data, the Phi-3 Mini-128K-Instruct model is best suited for prompts using the chat format as follows.
|
| 58 |
+
You can provide the prompt as a question with a generic template as follow:
|
| 59 |
+
```markdown
|
| 60 |
+
<|user|>/nQuestion <|end|>/n <|assistant|>
|
| 61 |
+
```
|
| 62 |
+
For example:
|
| 63 |
```markdown
|
| 64 |
<|system|>
|
| 65 |
+
You are a helpful AI assistant.<|end|>
|
|
|
|
| 66 |
<|user|>
|
| 67 |
+
How to explain Internet for a medieval knight?<|end|>
|
|
|
|
| 68 |
<|assistant|>
|
| 69 |
```
|
| 70 |
|
| 71 |
+
where the model generates the text after `<|assistant|>`. In case of few-shots prompt, the prompt can be formatted as the following:
|
| 72 |
|
| 73 |
```markdown
|
| 74 |
<|system|>
|
| 75 |
+
You are a helpful AI assistant.<|end|>
|
|
|
|
| 76 |
<|user|>
|
| 77 |
+
I am going to Paris, what should I see?<|end|>
|
|
|
|
| 78 |
<|assistant|>
|
| 79 |
+
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:\n\n1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.\n3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.\n\nThese are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world."<|end|>
|
|
|
|
| 80 |
<|user|>
|
| 81 |
What is so great about #1?
|
| 82 |
<|assistant|>
|