Instructions to use WeeRobots/phi-2-chat-v05 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use WeeRobots/phi-2-chat-v05 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="WeeRobots/phi-2-chat-v05", 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("WeeRobots/phi-2-chat-v05", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("WeeRobots/phi-2-chat-v05", 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
- vLLM
How to use WeeRobots/phi-2-chat-v05 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "WeeRobots/phi-2-chat-v05" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WeeRobots/phi-2-chat-v05", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/WeeRobots/phi-2-chat-v05
- SGLang
How to use WeeRobots/phi-2-chat-v05 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 "WeeRobots/phi-2-chat-v05" \ --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": "WeeRobots/phi-2-chat-v05", "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 "WeeRobots/phi-2-chat-v05" \ --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": "WeeRobots/phi-2-chat-v05", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use WeeRobots/phi-2-chat-v05 with Docker Model Runner:
docker model run hf.co/WeeRobots/phi-2-chat-v05
Model Card for Model ID
Phi-2-chat-v05 is a finetuned version of Phi-2 to increase the model's understanding of instructions and multi-turn conversations. In essence: it now has a concept of shutting up after an answer is given - as opposed to just switching into random generator mode.
Finetuning used 25k records from the dataset HuggingFaceH4/ultrachat_200k
Prompt format
<|system|>
You are a helpful assistant....
<|user|>
Why is the sky blue?
<|assistant|>
The sky appears blue because of a phenomenon called Rayleigh scattering. When sunlight enters the Earth's atmosphere [...]
<|user|>
Who was the phenomenon named after?
<|assistant|>
The system generates its output after the special token <|assistant|>. You need to have that token in the input for a reliable response. Or you can use the tokenizer's chat_template, as shown below.
How to use it?
Dependencies
pip install -u torch[cuda] transformers einops
Code for inference.
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "WeeRobots/phi-2-chat-v05"
model = AutoModelForCausalLM.from_pretrained(model_id, device_map={"": 0}, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False, trust_remote_code=True)
payload = tokenizer.apply_chat_template([
{ 'role': 'system', 'content': '''You are a state machine. The user will add state slot values and you'll keep track of them.''' },
{ 'role': 'user', 'content': '''Place 15 into slot apple''' },
{ 'role': 'assistant', 'content': '''Roger that.''' },
{ 'role': 'user', 'content': '''Bananas slot should be 20''' },
{ 'role': 'assistant', 'content': '''Certainly''' },
{ 'role': 'user', 'content': '''What is the value of Apple + Banana?''' },
], tokenize=False, add_generation_prompt=True,)
device = "cuda"
model_input = tokenizer(payload, return_tensors="pt").to(device)
with torch.no_grad():
# IMPORTANT: always set the eos_token_id in this call. the model is trained to emit the eos_token the right time
# but it might continue generating irrelevant text. this way the model will stop at the right place
model_response = model.generate(**model_input, max_new_tokens=512, eos_token_id=tokenizer.eos_token_id, )
print(tokenizer.decode(model_result[0], skip_special_tokens=False))
Non production quality
Be aware that this model tuning wasn't thoroughly tested, and isn't meant to be used in production, only for experimentation or hobby projects.
- Downloads last month
- 6