Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3import pandas as pd
4
5model_name = "/data/project/pj/r1/opencsg-r1/open-r1/train/Qwen2.5-3B-Open-R1-Code-GRPO/checkpoint-150"
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 torch_dtype="auto",
9 device_map="auto"
10)
11tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=False)
12df = pd.read_parquet('/data/project/pj/r1/opencsg-r1/OpenThoughts-114k-Code_decontaminated/train-00000-of-00006.parquet')
13data = df['problem'][0]
14messages = [
15 {
16 "role": "user",
17 "content": f"Please help me solve the problem: {data}.Output the thinking process within the <think> </think> tags,and then return the final result within the <answer> </answer> tags.",
18 },
19 {
20 "role": "assistant",
21 "content": "Let's solve the problem step by step.\n<think>",
22 },
23]
24text = tokenizer.apply_chat_template(
25 messages,
26 tokenize=False,
27 continue_final_message=True,
28 # add_generation_prompt=True
29)
30model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
31
32generated_ids = model.generate(
33 **model_inputs,
34 max_new_tokens=1024,
35 temperature=0.6
36)
37generated_ids = [
38 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
39]
40
41response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
42print(response)1@article{zhihong2024deepseekmath,
2 title = {{DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models}},
3 author = {Zhihong Shao and Peiyi Wang and Qihao Zhu and Runxin Xu and Junxiao Song and Mingchuan Zhang and Y. K. Li and Y. Wu and Daya Guo},
4 year = 2024,
5 eprint = {arXiv:2402.03300},
6}
71@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallouédec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}