Commit
·
0b24fae
1
Parent(s):
5f99bd5
example
Browse files- README.md +56 -4
- example.py +56 -4
README.md
CHANGED
@@ -103,15 +103,68 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
103 |
import torch
|
104 |
import accelerate
|
105 |
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
model_id = "Reward-Reasoning/RRM-32B"
|
110 |
|
111 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
112 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
|
113 |
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
116 |
|
117 |
generation_args = {
|
@@ -119,7 +172,6 @@ generation_args = {
|
|
119 |
"temperature": 0.6,
|
120 |
"do_sample": True,
|
121 |
"top_p": 1.0,
|
122 |
-
"top_k": 50,
|
123 |
"eos_token_id": tokenizer.eos_token_id,
|
124 |
"pad_token_id": tokenizer.pad_token_id,
|
125 |
}
|
|
|
103 |
import torch
|
104 |
import accelerate
|
105 |
|
106 |
+
Skywork_SYSTEM_PROMPT = """You are a helpful assistant in evaluating the quality of the responses for a given instruction. Your goal is to select the best response for the given instruction.
|
107 |
+
Select Assistant 1 or Assistant 2, that is better for the given instruction. The two responses are generated by two different AI assistants respectively.
|
108 |
+
Do NOT say both / neither are good.
|
109 |
+
|
110 |
+
Here are some rules of the evaluation:
|
111 |
+
(1) If the instruction does not contain harmful content, you should prioritize evaluating whether the output honestly/precisely/closely executes the instruction, then consider its helpfulness, accuracy, level of detail, harmlessness, etc.
|
112 |
+
(2) If the instruction contains harmful content, prioritize the harmlessness and safety of the response.
|
113 |
+
(3) Responses should NOT contain more/less than what the instruction asks for, as such responses do NOT precisely execute the instruction.
|
114 |
+
(4) You should avoid any potential bias and your judgment should be as objective as possible. Here are some potential sources of bias:
|
115 |
+
- The order in which the responses were presented should NOT affect your judgment, as Response A and Response B are equally likely to be the better.
|
116 |
+
- The length of the responses should NOT affect your judgement, as a longer response does not necessarily correspond to a better response. When making your decision, evaluate if the response length is appropriate for the given instruction.
|
117 |
+
(5) Your output should only consist of '\\boxed{Assistant 1}' if assistant 1 is better, or '\\boxed{Assistant 2}' if assistant 2 is better. Omit any other output.
|
118 |
+
|
119 |
+
"""
|
120 |
+
|
121 |
+
Skywork_PROMPT = """## Query
|
122 |
+
|
123 |
+
{question}
|
124 |
+
|
125 |
+
## Assistant responses
|
126 |
+
|
127 |
+
### Assistant 1
|
128 |
+
|
129 |
+
{answer1}
|
130 |
+
|
131 |
+
|
132 |
+
### Assistant 2
|
133 |
+
|
134 |
+
{answer2}
|
135 |
+
|
136 |
+
"""
|
137 |
+
|
138 |
+
Skywork_ASSISTANT_PROMPT = """## Analysis
|
139 |
+
|
140 |
+
Let's analyze this step by step and decide which assistant is better, and then answer \\boxed{Assistant 1} or \\boxed{Assistant 2}."""
|
141 |
+
|
142 |
|
143 |
model_id = "Reward-Reasoning/RRM-32B"
|
144 |
|
145 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
146 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
|
147 |
|
148 |
+
query = "How do I detail a car?"
|
149 |
+
response1 = "Detailing a car involves washing the exterior and interior of the car, as well as polishing and waxing the exterior. Interior detailing typically involves vacuuming, cleaning the upholstery and air vents, polishing the dashboard and console, and dusting. Polishing and waxing the exterior will depend on the condition of the paint, but typically involves applying a polish and wax to make it shine."
|
150 |
+
response2 = "Detailing a car involves a thorough cleaning inside and out, as well as polishing and waxing to protect the vehicle's surfaces. Here's a step-by-step guide to detailing a car:\n\n**Exterior Detailing:**\n\n1. **Wash the Car:**\n - Rinse the car with water to remove loose dirt.\n - Use a car wash soap and microfiber wash mitt to clean the car from top to bottom.\n - Clean the wheels and tires with a brush and a wheel cleaner.\n - Rinse the car thoroughly to remove all soap.\n\n2. **Dry the Car:**\n - Use a microfiber towel or a chamois to dry the car to prevent water spots.\n\n3. **Clay Bar Treatment:**\n - Use a clay bar with a lubricant to remove embedded surface contaminants from the paint.\n\n4. **Polishing:**\n - Apply car polish with a dual-action polisher or by hand to correct paint imperfections and create a smooth surface.\n\n5. **Waxing:**\n - Apply a coat of wax or paint sealant to protect the paint and give it a glossy finish.\n\n6. **Windows and Mirrors:**\n - Clean the windows and mirrors with a glass cleaner and a microfiber towel.\n\n7. **Tire and Trim Dressing:**\n - Apply a tire dressing to the tires for a shiny finish.\n - Use a trim restorer or protectant on plastic and rubber parts to prevent fading.\n\n**Interior Detailing:**\n\n1. **Remove Trash:**\n - Clear out any trash and remove personal items from the car.\n\n2. **Vacuum:**\n - Vacuum the seats, carpets, floor mats, and trunk.\n - Use a brush attachment for the dashboard and door panels.\n\n3. **Shampoo Carpets and Upholstery:**\n - Use a carpet cleaner and a brush to clean the carpets and upholstery.\n - For leather interiors, use a leather cleaner and conditioner.\n\n4. **Clean Hard Surfaces:**\n - Wipe down all hard surfaces (dashboard, center console, door panels, etc.) with a mild all-purpose cleaner and a microfiber cloth.\n\n5. **Windows and Mirrors:**\n - Clean the interior side of windows and mirrors.\n\n6. **Air Vents and Crevices:**\n - Use a detailing brush or compressed air to clean out air vents and hard-to-reach crevices.\n\n7. **Final Touches:**\n - Apply a protectant to the dashboard and other plastic components.\n - Replace air fresheners if needed.\n\n**Additional Tips:**\n\n- Work in the shade or a cool, well-ventilated garage to prevent products from drying too quickly and leaving residue.\n- Use separate buckets for washing and rinsing to avoid contaminating the clean water with dirt.\n- Always use gentle, non-abrasive materials and cleaners specifically designed for automotive use to avoid damaging surfaces.\n- Move in a systematic way to ensure you don't miss any spots.\n\nBy following these steps, you'll give your car a thorough clean that not only makes it look great but also helps in maintaining its value. Remember, regular detailing can prevent wear and tear and keep your car looking new for years to come."
|
151 |
+
|
152 |
+
system_prompt = Skywork_SYSTEM_PROMPT
|
153 |
+
|
154 |
+
user_prompt = Skywork_PROMPT.format(
|
155 |
+
question=query, answer1=response1, answer2=response2
|
156 |
+
) + Skywork_ASSISTANT_PROMPT
|
157 |
+
|
158 |
+
messages = [
|
159 |
+
{
|
160 |
+
"role": "system",
|
161 |
+
"content": system_prompt,
|
162 |
+
},
|
163 |
+
{"role": "user", "content": user_prompt},
|
164 |
+
]
|
165 |
+
|
166 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
167 |
+
|
168 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
169 |
|
170 |
generation_args = {
|
|
|
172 |
"temperature": 0.6,
|
173 |
"do_sample": True,
|
174 |
"top_p": 1.0,
|
|
|
175 |
"eos_token_id": tokenizer.eos_token_id,
|
176 |
"pad_token_id": tokenizer.pad_token_id,
|
177 |
}
|
example.py
CHANGED
@@ -2,15 +2,68 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
2 |
import torch
|
3 |
import accelerate
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
model_id = "Reward-Reasoning/RRM-32B"
|
9 |
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
11 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
15 |
|
16 |
generation_args = {
|
@@ -18,7 +71,6 @@ generation_args = {
|
|
18 |
"temperature": 0.6,
|
19 |
"do_sample": True,
|
20 |
"top_p": 1.0,
|
21 |
-
"top_k": 50,
|
22 |
"eos_token_id": tokenizer.eos_token_id,
|
23 |
"pad_token_id": tokenizer.pad_token_id,
|
24 |
}
|
|
|
2 |
import torch
|
3 |
import accelerate
|
4 |
|
5 |
+
Skywork_SYSTEM_PROMPT = """You are a helpful assistant in evaluating the quality of the responses for a given instruction. Your goal is to select the best response for the given instruction.
|
6 |
+
Select Assistant 1 or Assistant 2, that is better for the given instruction. The two responses are generated by two different AI assistants respectively.
|
7 |
+
Do NOT say both / neither are good.
|
8 |
+
|
9 |
+
Here are some rules of the evaluation:
|
10 |
+
(1) If the instruction does not contain harmful content, you should prioritize evaluating whether the output honestly/precisely/closely executes the instruction, then consider its helpfulness, accuracy, level of detail, harmlessness, etc.
|
11 |
+
(2) If the instruction contains harmful content, prioritize the harmlessness and safety of the response.
|
12 |
+
(3) Responses should NOT contain more/less than what the instruction asks for, as such responses do NOT precisely execute the instruction.
|
13 |
+
(4) You should avoid any potential bias and your judgment should be as objective as possible. Here are some potential sources of bias:
|
14 |
+
- The order in which the responses were presented should NOT affect your judgment, as Response A and Response B are equally likely to be the better.
|
15 |
+
- The length of the responses should NOT affect your judgement, as a longer response does not necessarily correspond to a better response. When making your decision, evaluate if the response length is appropriate for the given instruction.
|
16 |
+
(5) Your output should only consist of '\\boxed{Assistant 1}' if assistant 1 is better, or '\\boxed{Assistant 2}' if assistant 2 is better. Omit any other output.
|
17 |
+
|
18 |
+
"""
|
19 |
+
|
20 |
+
Skywork_PROMPT = """## Query
|
21 |
+
|
22 |
+
{question}
|
23 |
+
|
24 |
+
## Assistant responses
|
25 |
+
|
26 |
+
### Assistant 1
|
27 |
+
|
28 |
+
{answer1}
|
29 |
+
|
30 |
+
|
31 |
+
### Assistant 2
|
32 |
+
|
33 |
+
{answer2}
|
34 |
+
|
35 |
+
"""
|
36 |
+
|
37 |
+
Skywork_ASSISTANT_PROMPT = """## Analysis
|
38 |
+
|
39 |
+
Let's analyze this step by step and decide which assistant is better, and then answer \\boxed{Assistant 1} or \\boxed{Assistant 2}."""
|
40 |
+
|
41 |
|
42 |
model_id = "Reward-Reasoning/RRM-32B"
|
43 |
|
44 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
45 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
|
46 |
|
47 |
+
query = "How do I detail a car?"
|
48 |
+
response1 = "Detailing a car involves washing the exterior and interior of the car, as well as polishing and waxing the exterior. Interior detailing typically involves vacuuming, cleaning the upholstery and air vents, polishing the dashboard and console, and dusting. Polishing and waxing the exterior will depend on the condition of the paint, but typically involves applying a polish and wax to make it shine."
|
49 |
+
response2 = "Detailing a car involves a thorough cleaning inside and out, as well as polishing and waxing to protect the vehicle's surfaces. Here's a step-by-step guide to detailing a car:\n\n**Exterior Detailing:**\n\n1. **Wash the Car:**\n - Rinse the car with water to remove loose dirt.\n - Use a car wash soap and microfiber wash mitt to clean the car from top to bottom.\n - Clean the wheels and tires with a brush and a wheel cleaner.\n - Rinse the car thoroughly to remove all soap.\n\n2. **Dry the Car:**\n - Use a microfiber towel or a chamois to dry the car to prevent water spots.\n\n3. **Clay Bar Treatment:**\n - Use a clay bar with a lubricant to remove embedded surface contaminants from the paint.\n\n4. **Polishing:**\n - Apply car polish with a dual-action polisher or by hand to correct paint imperfections and create a smooth surface.\n\n5. **Waxing:**\n - Apply a coat of wax or paint sealant to protect the paint and give it a glossy finish.\n\n6. **Windows and Mirrors:**\n - Clean the windows and mirrors with a glass cleaner and a microfiber towel.\n\n7. **Tire and Trim Dressing:**\n - Apply a tire dressing to the tires for a shiny finish.\n - Use a trim restorer or protectant on plastic and rubber parts to prevent fading.\n\n**Interior Detailing:**\n\n1. **Remove Trash:**\n - Clear out any trash and remove personal items from the car.\n\n2. **Vacuum:**\n - Vacuum the seats, carpets, floor mats, and trunk.\n - Use a brush attachment for the dashboard and door panels.\n\n3. **Shampoo Carpets and Upholstery:**\n - Use a carpet cleaner and a brush to clean the carpets and upholstery.\n - For leather interiors, use a leather cleaner and conditioner.\n\n4. **Clean Hard Surfaces:**\n - Wipe down all hard surfaces (dashboard, center console, door panels, etc.) with a mild all-purpose cleaner and a microfiber cloth.\n\n5. **Windows and Mirrors:**\n - Clean the interior side of windows and mirrors.\n\n6. **Air Vents and Crevices:**\n - Use a detailing brush or compressed air to clean out air vents and hard-to-reach crevices.\n\n7. **Final Touches:**\n - Apply a protectant to the dashboard and other plastic components.\n - Replace air fresheners if needed.\n\n**Additional Tips:**\n\n- Work in the shade or a cool, well-ventilated garage to prevent products from drying too quickly and leaving residue.\n- Use separate buckets for washing and rinsing to avoid contaminating the clean water with dirt.\n- Always use gentle, non-abrasive materials and cleaners specifically designed for automotive use to avoid damaging surfaces.\n- Move in a systematic way to ensure you don't miss any spots.\n\nBy following these steps, you'll give your car a thorough clean that not only makes it look great but also helps in maintaining its value. Remember, regular detailing can prevent wear and tear and keep your car looking new for years to come."
|
50 |
+
|
51 |
+
system_prompt = Skywork_SYSTEM_PROMPT
|
52 |
+
|
53 |
+
user_prompt = Skywork_PROMPT.format(
|
54 |
+
question=query, answer1=response1, answer2=response2
|
55 |
+
) + Skywork_ASSISTANT_PROMPT
|
56 |
+
|
57 |
+
messages = [
|
58 |
+
{
|
59 |
+
"role": "system",
|
60 |
+
"content": system_prompt,
|
61 |
+
},
|
62 |
+
{"role": "user", "content": user_prompt},
|
63 |
+
]
|
64 |
+
|
65 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
66 |
+
|
67 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
68 |
|
69 |
generation_args = {
|
|
|
71 |
"temperature": 0.6,
|
72 |
"do_sample": True,
|
73 |
"top_p": 1.0,
|
|
|
74 |
"eos_token_id": tokenizer.eos_token_id,
|
75 |
"pad_token_id": tokenizer.pad_token_id,
|
76 |
}
|