Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from vllm import LLM, SamplingParams
3
4model_id = "launch/ThinkPRM-14B" # Replace with actual model ID on Hub
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6llm = LLM(model=model_id, max_model_len=16384)
7
8# Example problem and solution
9problem = "Solve for x: 2x + 3 = 7"
10prefix = "Step 1: Subtract 3 from both sides: 2x = 4
11Step 2: Divide by 2: x = 1"
12
13# Format the prompt
14prompt = f"""You are given a math problem and a proposed step-by-step solution:
15
16[Math Problem]
17
18{problem}
19
20[Solution]
21
22{prefix}
23
24Review and critique each step in the proposed solution to determine whether each step is correct. If the solution is incomplete, only verify the provided steps
25"""
26
27prompt = tokenizer.apply_chat_template([
28 {'role': "user", "content": prompt}
29], tokenize=False, add_generation_prompt=True) + "
30Let's verify step by step:"
31
32# Set sampling parameters
33sampling_params = SamplingParams(
34 temperature=0.0,
35 max_tokens=4096,
36 stop=None
37)
38
39# Generate the verification
40outputs = llm.generate(prompt, sampling_params)
41verification_cot = outputs[0].outputs[0].text
42
43print(verification_cot)
44"""
45Step 1: Subtract 3 from both sides: 2x = 4
46
47Critique: Starting with the equation 2x + 3 = 7, subtracting 3 from both sides is a correct operation to isolate the term with the variable. So, 2x + 3 - 3 = 7 - 3, which simplifies
48 to 2x = 4. This step seems correct.
49
50Step 2: Divide by 2: x = 1
51
52Critique: Now, to solve for x, we need to divide both sides of the equation by 2. So, 2x / 2 = 4 / 2, which simplifies to x = 2. Wait a minute, the solution says x = 1, but accordin
53g to this calculation, it should be x = 2. This seems incorrect.
54
55Therefore, the first step is correct, but the second step has an error.
56
57**Final Output:**
58
59Let's verify step by step:
60
61Step 1: Subtract 3 from both sides: 2x = 4
62
63Critique: This step is correct. Subtracting 3 from both sides of the equation 2x + 3 = 7 properly isolates the term with the variable, resulting in 2x = 4.
64
65Step 1 is \boxed{correct}
66
67Step 2: Divide by 2: x = 1
68
69Critique: This step is incorrect. Dividing both sides of the equation 2x = 4 by 2 should yield x = 2, not x = 1.
70
71Step 2 is \boxed{incorrect}
72</think>
73Is the solution correct? No
74"""