prithivMLmods commited on
Commit
fc01de9
·
verified ·
1 Parent(s): b5d7d03

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +71 -1
README.md CHANGED
@@ -30,4 +30,74 @@ PRM-Math-7B-Reasoner is a fully reproducible model, fine-tuned on the Qwen2.5-Ma
30
  | **Description** | This example demonstrates the reformatting of a solution for finding the foci of an ellipse. The original solution is generated by Qwen2-7B-Instruct, and the reformatted version is presented for clarity. |
31
  | **Problem Statement**| The ellipse \(\frac{(x-6)^{2}}{25}+\frac{(y-3)^{2}}{9}=1\) has two foci. Find the one with the larger x-coordinate. Enter your answer as an ordered pair, like \((2,1)\). |
32
  | **Original Solution**| The original solution is provided in a less readable format, with some syntax errors and unclear notation. |
33
- | **Reformatted Solution** | The reformatted solution clearly explains the steps: <br> 1. Identify the center of the ellipse \((6,3)\). <br> 2. Calculate the distance from the center to each focus using \(\sqrt{a^2 - b^2}\). <br> 3. Determine the foci locations at \((2,3)\) and \((10,3)\). <br> 4. Identify the focus with the larger x-coordinate as \((10,3)\). |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  | **Description** | This example demonstrates the reformatting of a solution for finding the foci of an ellipse. The original solution is generated by Qwen2-7B-Instruct, and the reformatted version is presented for clarity. |
31
  | **Problem Statement**| The ellipse \(\frac{(x-6)^{2}}{25}+\frac{(y-3)^{2}}{9}=1\) has two foci. Find the one with the larger x-coordinate. Enter your answer as an ordered pair, like \((2,1)\). |
32
  | **Original Solution**| The original solution is provided in a less readable format, with some syntax errors and unclear notation. |
33
+ | **Reformatted Solution** | The reformatted solution clearly explains the steps: <br> 1. Identify the center of the ellipse \((6,3)\). <br> 2. Calculate the distance from the center to each focus using \(\sqrt{a^2 - b^2}\). <br> 3. Determine the foci locations at \((2,3)\) and \((10,3)\). <br> 4. Identify the focus with the larger x-coordinate as \((10,3)\). |
34
+
35
+
36
+ # **Hugging Face Transformers**
37
+
38
+
39
+ ```python
40
+ import torch
41
+ from transformers import AutoModel, AutoTokenizer
42
+ import torch.nn.functional as F
43
+
44
+
45
+ def make_step_rewards(logits, token_masks):
46
+ probabilities = F.softmax(logits, dim=-1)
47
+ probabilities = probabilities * token_masks.unsqueeze(-1) # bs, seq_len, num_labels
48
+
49
+ all_scores_res = []
50
+ for i in range(probabilities.size(0)):
51
+ sample = probabilities[i] # seq_len, num_labels
52
+ positive_probs = sample[sample != 0].view(-1, 2)[:, 1] # valid_tokens, num_labels
53
+ non_zero_elements_list = positive_probs.cpu().tolist()
54
+ all_scores_res.append(non_zero_elements_list)
55
+ return all_scores_res
56
+
57
+
58
+ model_name = "prithivMLmods/PRM-Math-7B-Reasoner"
59
+ device = "auto"
60
+
61
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
62
+ model = AutoModel.from_pretrained(
63
+ model_name,
64
+ device_map=device,
65
+ torch_dtype=torch.bfloat16,
66
+ trust_remote_code=True,
67
+ ).eval()
68
+
69
+
70
+ data = {
71
+ "system": "Please reason step by step, and put your final answer within \\boxed{}.",
72
+ "query": "Sue lives in a fun neighborhood. One weekend, the neighbors decided to play a prank on Sue. On Friday morning, the neighbors placed 18 pink plastic flamingos out on Sue's front yard. On Saturday morning, the neighbors took back one third of the flamingos, painted them white, and put these newly painted white flamingos back out on Sue's front yard. Then, on Sunday morning, they added another 18 pink plastic flamingos to the collection. At noon on Sunday, how many more pink plastic flamingos were out than white plastic flamingos?",
73
+ "response": [
74
+ "To find out how many more pink plastic flamingos were out than white plastic flamingos at noon on Sunday, we can break down the problem into steps. First, on Friday, the neighbors start with 18 pink plastic flamingos.",
75
+ "On Saturday, they take back one third of the flamingos. Since there were 18 flamingos, (1/3 \\times 18 = 6) flamingos are taken back. So, they have (18 - 6 = 12) flamingos left in their possession. Then, they paint these 6 flamingos white and put them back out on Sue's front yard. Now, Sue has the original 12 pink flamingos plus the 6 new white ones. Thus, by the end of Saturday, Sue has (12 + 6 = 18) pink flamingos and 6 white flamingos.",
76
+ "On Sunday, the neighbors add another 18 pink plastic flamingos to Sue's front yard. By the end of Sunday morning, Sue has (18 + 18 = 36) pink flamingos and still 6 white flamingos.",
77
+ "To find the difference, subtract the number of white flamingos from the number of pink flamingos: (36 - 6 = 30). Therefore, at noon on Sunday, there were 30 more pink plastic flamingos out than white plastic flamingos. The answer is (\\boxed{30})."
78
+ ]
79
+ }
80
+
81
+ messages = [
82
+ {"role": "system", "content": data['system']},
83
+ {"role": "user", "content": data['query']},
84
+ {"role": "assistant", "content": "<extra_0>".join(data['response']) + "<extra_0>"},
85
+ ]
86
+ conversation_str = tokenizer.apply_chat_template(
87
+ messages,
88
+ tokenize=False,
89
+ add_generation_prompt=False
90
+ )
91
+
92
+ input_ids = tokenizer.encode(
93
+ conversation_str,
94
+ return_tensors="pt",
95
+ ).to(model.device)
96
+
97
+ outputs = model(input_ids=input_ids)
98
+
99
+ step_sep_id = tokenizer.encode("<extra_0>")[0]
100
+ token_masks = (input_ids == step_sep_id)
101
+ step_reward = make_step_rewards(outputs[0], token_masks)
102
+ print(step_reward) # [[0.9921875, 0.2333984375, 0.6796875, 0.94140625]]
103
+ ```