Instructions to use microsoft/Phi-3.5-mini-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Phi-3.5-mini-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/Phi-3.5-mini-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.5-mini-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3.5-mini-instruct", trust_remote_code=True) 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.5-mini-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.5-mini-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.5-mini-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/Phi-3.5-mini-instruct
- SGLang
How to use microsoft/Phi-3.5-mini-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.5-mini-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.5-mini-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.5-mini-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.5-mini-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/Phi-3.5-mini-instruct with Docker Model Runner:
docker model run hf.co/microsoft/Phi-3.5-mini-instruct
Discrepency in template
Using pipe and the example we get those tokens
[32006, 887, 526, 263, 8444, 319, 29902, 20255, 29889, 32007,
32010, 1815, 366, 3867, 5837, 304, 17545, 18240, 310, 9892,
16397, 322, 8338, 265, 29888, 21211, 29973, 32007, 32001, 18585,
29991, 2266, 526, 777, 5837, 304, 17545, 9892, 16397, 322,
8338, 265, 29888, 21211, 4208, 29901, 29871, 29896, 29889, 10765,
1648, 322, 8338, 265, 29888, 9216, 10597, 347, 29901, 3164,
355, 9892, 16397, 322, 8338, 265, 29888, 21211, 4208, 411,
777, 27274, 322, 298, 4992, 29889, 29871, 29906, 29889, 10765,
1648, 322, 8338, 265, 29888, 9216, 4497, 328, 29901, 23478,
269, 506, 287, 9892, 16397, 322, 8338, 265, 29888, 21211,
4208, 411, 777, 454, 3712, 3623, 625, 322, 298, 4992,
29889, 32007, 32010, 1724, 1048, 17069, 385, 29871, 29906, 29916,
718, 29871, 29941, 353, 29871, 29955, 6306, 29973, 32007, 32001],
which correspond to
'<|system|> You are a helpful AI assistant.<|end|><|user|> Can you provide ways to eat combinations of bananas and dragonfruits?<|end|><|assistant|> Sure! Here are some ways to eat ...'.
This doesn't correspond to the template given in the webpage where \n are present.
What actual template was used for training ? With or without jumping lines ?
Thanks for your interest in Phi! The actual string the model sees is without the newline.