This is a finetuned version of Microsoft's 2.7B parameter
phi-2 transfromer model that has underwent a post-training process that incorporates both
supervised fine-tuning and
anchored preference optimization for instruction following. I used the
trl library and a single
A100 40GB GPU during both the SFT and APO steps.
-
Supervised Fine-Tuning
- SFT Model: phi-2-sft
- Used 128,000 instruction, response pairs from the teknium/OpenHermes-2.5 dataset
-
Anchored Preference Optimization (APO)
- LoRA Adapter: phi-2-apo
- Used 10,000 preference pairs from the ContextualAI/ultrafeedback_clair_32k dataset
Given the nature of the training data, the phi-2 instruct model is best suited for prompts using the chat format as follows.
You can provide the prompt as a question with a generic template as follows:
1<|im_start|>system
2You are a helpful assistant.<|im_end|>
3<|im_start|>user
4Question?<|im_end|>
5<|im_start|>assistant
1<|im_start|>system
2You are a helpful assistant.<|im_end|>
3<|im_start|>user
4How to explain Internet for a medieval knight?<|im_end|>
5<|im_start|>assistant
This code snippets show how to get quickly started with running the model on a GPU:
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
4torch.random.manual_seed(0)
5
6model_id = "rasyosef/phi-2-instruct-apo"
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 device_map="cuda",
10 torch_dtype="auto"
11)
12
13tokenizer = AutoTokenizer.from_pretrained(model_id)
14
15messages = [
16 {"role": "system", "content": "You are a helpful AI assistant."},
17 {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
18 {"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."},
19 {"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
20]
21
22pipe = pipeline(
23 "text-generation",
24 model=model,
25 tokenizer=tokenizer,
26)
27
28generation_args = {
29 "max_new_tokens": 256,
30 "return_full_text": False,
31 "temperature": 0.0,
32 "do_sample": False,
33}
34
35output = pipe(messages, **generation_args)
36print(output[0]['generated_text'])
These benchmarks were run using EleutherAI's
lm-evaluation-harness
Detailed results can be found
here