Views
No views yet
transformers library. You can load and use it for text generation as follows:1from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
2import torch
3
4model_name = "sunblaze-ucb/Qwen2.5-3B-GRPO-MATH-1EPOCH"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 torch_dtype=torch.bfloat16,
9 device_map="auto"
10)
11
12# Define a conversation prompt for mathematical reasoning
13prompt = "Question: What is the sum of the first 100 positive integers?
14Answer:"
15
16# Apply the chat template suitable for Qwen models
17messages = [
18 {"role": "user", "content": prompt}
19]
20text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
21
22# Encode the input
23input_ids = tokenizer.encode(text, return_tensors="pt").to(model.device)
24
25# Set generation configuration
26generation_config = GenerationConfig(
27 bos_token_id=tokenizer.bos_token_id,
28 eos_token_id=tokenizer.eos_token_id,
29 max_new_tokens=2048,
30 do_sample=True,
31 temperature=0.7,
32 top_p=0.9,
33)
34
35# Generate response
36outputs = model.generate(input_ids, generation_config=generation_config)
37response = tokenizer.decode(outputs[0], skip_special_tokens=True)
38
39print(response)1@article{zhao2025learning,
2 title={Learning to Reason without External Rewards},
3 author={Zhao, Xuandong and Kang, Zhewei and Feng, Aosong and Levine, Sergey and Song, Dawn},
4 journal={arXiv preprint arXiv:2505.19590},
5 year={2025}
6}
7
8@article{sha2024deepseekmath,
9 title = {DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models},
10 author = {Shao, Zhihong and Wang, Peiyi and Zhu, Qihao and Xu, Runxin and Song, Junxiao and Bi, Xiao and … Guo, Daya},
11 journal = {arXiv preprint arXiv:2402.03300},
12 year = {2024},
13}