Update README.md
Browse files
README.md
CHANGED
@@ -16,3 +16,28 @@ TRL supports the DPO Trainer for training language models from preference data,
|
|
16 |
target_modules=[ "gate_proj", "up_proj", "down_proj"]
|
17 |
|
18 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
target_modules=[ "gate_proj", "up_proj", "down_proj"]
|
17 |
|
18 |
```
|
19 |
+
sample codeimport torch
|
20 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
21 |
+
import math
|
22 |
+
|
23 |
+
## v2 models
|
24 |
+
model_path = "cloudyu/google-gemma-7b-it-dpo-v1"
|
25 |
+
|
26 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, use_default_system_prompt=False)
|
27 |
+
model = AutoModelForCausalLM.from_pretrained(
|
28 |
+
model_path, torch_dtype=torch.bfloat16, device_map='auto',local_files_only=False, load_in_4bit=True
|
29 |
+
)
|
30 |
+
print(model)
|
31 |
+
prompt = input("please input prompt:")
|
32 |
+
while len(prompt) > 0:
|
33 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to("cuda")
|
34 |
+
|
35 |
+
generation_output = model.generate(
|
36 |
+
input_ids=input_ids, max_new_tokens=500,repetition_penalty=1.2
|
37 |
+
)
|
38 |
+
print(tokenizer.decode(generation_output[0]))
|
39 |
+
prompt = input("please input prompt:")
|
40 |
+
|
41 |
+
```
|
42 |
+
|
43 |
+
```
|