Text Generation
Transformers
Safetensors
English
French
phi3
nlp
code
conversational
custom_code
Eval Results
text-generation-inference
Instructions to use microsoft/Phi-3-mini-4k-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Phi-3-mini-4k-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/Phi-3-mini-4k-instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-mini-4k-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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Phi-3-mini-4k-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-4k-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-4k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/Phi-3-mini-4k-instruct
- SGLang
How to use microsoft/Phi-3-mini-4k-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-4k-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-4k-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-4k-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-4k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/Phi-3-mini-4k-instruct with Docker Model Runner:
docker model run hf.co/microsoft/Phi-3-mini-4k-instruct
fix(root): Replaces system by user to improve generation experience.
Browse files- README.md +0 -5
- tokenizer_config.json +2 -2
README.md
CHANGED
|
@@ -73,8 +73,6 @@ You can provide the prompt as a question with a generic template as follow:
|
|
| 73 |
```
|
| 74 |
For example:
|
| 75 |
```markdown
|
| 76 |
-
<|system|>
|
| 77 |
-
You are a helpful AI assistant.<|end|>
|
| 78 |
<|user|>
|
| 79 |
How to explain Internet for a medieval knight?<|end|>
|
| 80 |
<|assistant|>
|
|
@@ -83,8 +81,6 @@ How to explain Internet for a medieval knight?<|end|>
|
|
| 83 |
where the model generates the text after `<|assistant|>` . In case of few-shots prompt, the prompt can be formatted as the following:
|
| 84 |
|
| 85 |
```markdown
|
| 86 |
-
<|system|>
|
| 87 |
-
You are a helpful AI assistant.<|end|>
|
| 88 |
<|user|>
|
| 89 |
I am going to Paris, what should I see?<|end|>
|
| 90 |
<|assistant|>
|
|
@@ -113,7 +109,6 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 113 |
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
| 114 |
|
| 115 |
messages = [
|
| 116 |
-
{"role": "system", "content": "You are a helpful digital assistant. Please provide safe, ethical and accurate information to the user."},
|
| 117 |
{"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
|
| 118 |
{"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
|
| 119 |
{"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
|
|
|
|
| 73 |
```
|
| 74 |
For example:
|
| 75 |
```markdown
|
|
|
|
|
|
|
| 76 |
<|user|>
|
| 77 |
How to explain Internet for a medieval knight?<|end|>
|
| 78 |
<|assistant|>
|
|
|
|
| 81 |
where the model generates the text after `<|assistant|>` . In case of few-shots prompt, the prompt can be formatted as the following:
|
| 82 |
|
| 83 |
```markdown
|
|
|
|
|
|
|
| 84 |
<|user|>
|
| 85 |
I am going to Paris, what should I see?<|end|>
|
| 86 |
<|assistant|>
|
|
|
|
| 109 |
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
| 110 |
|
| 111 |
messages = [
|
|
|
|
| 112 |
{"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
|
| 113 |
{"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
|
| 114 |
{"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
|
tokenizer_config.json
CHANGED
|
@@ -116,7 +116,7 @@
|
|
| 116 |
}
|
| 117 |
},
|
| 118 |
"bos_token": "<s>",
|
| 119 |
-
"chat_template": "{{ bos_token }}{% for message in messages %}{% if (message['role'] == '
|
| 120 |
"clean_up_tokenization_spaces": false,
|
| 121 |
"eos_token": "<|endoftext|>",
|
| 122 |
"legacy": false,
|
|
@@ -127,4 +127,4 @@
|
|
| 127 |
"tokenizer_class": "LlamaTokenizer",
|
| 128 |
"unk_token": "<unk>",
|
| 129 |
"use_default_system_prompt": false
|
| 130 |
-
}
|
|
|
|
| 116 |
}
|
| 117 |
},
|
| 118 |
"bos_token": "<s>",
|
| 119 |
+
"chat_template": "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}",
|
| 120 |
"clean_up_tokenization_spaces": false,
|
| 121 |
"eos_token": "<|endoftext|>",
|
| 122 |
"legacy": false,
|
|
|
|
| 127 |
"tokenizer_class": "LlamaTokenizer",
|
| 128 |
"unk_token": "<unk>",
|
| 129 |
"use_default_system_prompt": false
|
| 130 |
+
}
|