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")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2") model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- 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
How should the chatPromptTemplate for Chat-ui Model Config look like?
#77
by chriamue - opened
Hi, I try to run the Model with chat-ui on a candle backend.
How should the chatPromptTemplate look like?
I started with following, derived from the Llama example and the description of the model card.
But it looks like, when asking the second time, the context of last answer is not used correctly.
Here is my configuration.
{
"name": "microsoft/phi-2",
"description": "1.3b and 2.7b LLM with state of the art performance for <10b models",
"websiteUrl": "https://huggingface.co/microsoft/phi-2",
"userMessageToken": "",
"userMessageEndToken": " [/INST] ",
"assistantMessageToken": "",
"assistantMessageEndToken": " </s><s>[INST] ",
"preprompt": " ",
"chatPromptTemplate" : "Instruct: {{#each messages}}{{#ifUser}}{{content}}\n{{/ifUser}}{{#ifAssistant}}{{content}}\n{{/ifAssistant}}{{/each}}\nOutput:",
"endpoints": [{
"type" : "tgi",
"url": "http://chat-flame-backend:8080/model/phi-v2/"
}],
"promptExamples": [
{
"title": "Write an email from bullet list",
"prompt": "As a restaurant owner, write a professional email to the supplier to get these products every week: \n\n- Wine (x10)\n- Eggs (x24)\n- Bread (x12)"
}, {
"title": "Code a snake game",
"prompt": "Code a basic snake game in python, give explanations for each step."
}, {
"title": "Assist in a task",
"prompt": "How do I make a delicious lemon cheesecake?"
}
],
"parameters": {
"temperature": 0.1,
"top_p": 0.95,
"repetition_penalty": 1.2,
"top_k": 50,
"truncate": 3072,
"max_new_tokens": 1024,
"stop": ["</s>"]
}
},
Here is a conversation:
Prompt:
As a restaurant owner, write a professional email to the supplier to get these products every week:
- Wine (x10)
- Eggs (x24)
- Bread (x12)
Answer:
Supplier,
I hope this email finds you well. I am writing to place an order for our weekly supplies of wine, eggs and bread. The quantity required is as follows: 10 bottles of wine, 24 cartons of eggs and 12 loaves of bread. Please let me know when the delivery can be made. Thank you for your continued support.
Best regards,
[Your Name]
Prompt:
rewrite it more happy
Answer:
Weekly Supplies Order - Wine, Eggs & Bread
chriamue changed discussion title from Chat-ui Model Config to How should the chatPromptTemplate for Chat-ui Model Config look like?
It's not trained for chat, see the README for information on a minimal template.
gugarosa changed discussion status to closed