Update README.md
Browse files
README.md
CHANGED
|
@@ -6,4 +6,45 @@ language:
|
|
| 6 |
- en
|
| 7 |
base_model:
|
| 8 |
- Qwen/Qwen2.5-Math-7B-Instruct
|
| 9 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
- en
|
| 7 |
base_model:
|
| 8 |
- Qwen/Qwen2.5-Math-7B-Instruct
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 14 |
+
|
| 15 |
+
model_name = "cehao/Select2Reason-Qwen-7B"
|
| 16 |
+
device = "cuda" # the device to load the model onto
|
| 17 |
+
|
| 18 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 19 |
+
model_name,
|
| 20 |
+
torch_dtype="auto",
|
| 21 |
+
device_map="auto"
|
| 22 |
+
)
|
| 23 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 24 |
+
|
| 25 |
+
prompt = "Every morning Aya goes for a $9$-kilometer-long walk and stops at a coffee shop afterwards. When she walks at a constant speed of $s$ kilometers per hour, the walk takes her 4 hours, including $t$ minutes spent in the coffee shop. When she walks $s+2$ kilometers per hour, the walk takes her 2 hours and 24 minutes, including $t$ minutes spent in the coffee shop. Suppose Aya walks at $s+\frac{1}{2}$ kilometers per hour. Find the number of minutes the walk takes her, including the $t$ minutes spent in the coffee shop."
|
| 26 |
+
|
| 27 |
+
# CoT
|
| 28 |
+
messages = [
|
| 29 |
+
{"role": "system", "content": "Please reason step by step, and put your final answer within \\boxed{}."},
|
| 30 |
+
{"role": "user", "content": prompt}
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
text = tokenizer.apply_chat_template(
|
| 34 |
+
messages,
|
| 35 |
+
tokenize=False,
|
| 36 |
+
add_generation_prompt=True
|
| 37 |
+
)
|
| 38 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(device)
|
| 39 |
+
|
| 40 |
+
generated_ids = model.generate(
|
| 41 |
+
**model_inputs,
|
| 42 |
+
max_new_tokens=16384
|
| 43 |
+
)
|
| 44 |
+
generated_ids = [
|
| 45 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 49 |
+
print(response)
|
| 50 |
+
```
|