Use dpo trainer to do the RLHF so that the model can be more precise and consistent.
1 generation_config = GenerationConfig(
2 max_new_tokens=150,
3 min_new_tokens=5,
4 repetition_penalty=1.1,
5 top_k=3,
6 top_p=0.9,
7 pad_token_id=tokenizer.pad_token_id,
8 eos_token_id=tokenizer.eos_token_id,
9 temperature=1.0,
10 do_sample=True,
11 num_beams=1
12 )
This llama model was trained 2x faster with
Unsloth and Huggingface's TRL library.
1 # libs are from github repo
2 from libs import ResponseGeneratorPipeline
3 from unsloth import FastLanguageModel
4 model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name = "Shotaro30678/response_generator_DPO", # YOUR MODEL YOU USED FOR TRAINING
6 load_in_4bit = True,
7 )
8 FastLanguageModel.for_inference(model) # Enable native 2x faster inference
9
10 bot = ResponseGeneratorPipeline(
11 model,
12 tokenizer,
13 framework="pt",
14 task="conversation-generation",
15 num_workers=16,
16 torch_dtype="auto",
17 add_special_tokens=True,
18 truncation=False,
19 padding=True
20 )
21
22 conversation = [
23 {'content': {'dialog': '', 'emotion': ''}, 'role': 'system'},
24 {'content': {'dialog': 'Can you do push-ups ?', 'emotion': 'neutral'},
25 'role': 'user'},
26 {'content': {'dialog': "Of course I can . It's a piece of cake ! Believe it or not , I can do 30 push-ups a minute .",
27 'emotion': 'neutral'},
28 'role': 'assistant'},
29 {'content': {'dialog': "Really ? I think that's impossible !",
30 'emotion': 'surprise'},
31 'role': 'user'},
32 {'content': {'dialog': 'You mean 30 push-ups ?', 'emotion': 'neutral'},
33 'role': 'assistant'},
34 {'content': {'dialog': 'Yeah !', 'emotion': 'neutral'}, 'role': 'user'},
35 {'content': {'dialog': '', 'emotion': 'neutral'}, 'role': 'assistant'}
36 ]
37
38 generation_config = GenerationConfig(
39 max_new_tokens=150,
40 min_new_tokens=5,
41 repetition_penalty=1.1,
42 top_k=3,
43 top_p=0.9,
44 pad_token_id=tokenizer.pad_token_id,
45 eos_token_id=tokenizer.eos_token_id,
46 temperature=1.0,
47 do_sample=True,
48 num_beams=1
49 )
50
51 print(bot(conversation, generation_config=generation_config)[0]['generated_text'][-1]["content"]["dialog"])