openai/gsm8k
Benchmark • Updated • 17.6k • 942k • 1.47k
How to use michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO")
model = AutoModelForCausalLM.from_pretrained("michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO", device_map="auto")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO
How to use michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO with Docker Model Runner:
docker model run hf.co/michaelbzhu/Qwen2.5-Math-1.5B-GSM8K-GRPO
used GRPO on top of Qwen/Qwen2.5-Math-1.5B model on the gsm8k training set
hyperparameters:
lr = 3e-5
n_grpo_steps = 100
advantage_eps = 1e-6
rollout_batch_size = 256
group_size = 8
gradient_accumulation_steps = 128
epochs_per_rollout_batch = 1
train_batch_size = 256 # on policy since same as rollout_batch_size
use_std_normalization = True
optim = torch.optim.AdamW(
hf_model.parameters(), lr=lr, weight_decay=0.0, betas=(0.9, 0.95)
)
scheduler = LinearLR(optim, start_factor=1.0, end_factor=0.1, total_iters=n_grpo_steps)
prompt template:
A conversation between User and Assistant. The User asks a question, and the Assistant solves it. The Assistant first thinks about the reasoning process in the mind and then provides the User with the answer. The reasoning process is enclosed within <think> </think> and answer is enclosed within <answer> </answer> tags, respectively, i.e., <think> reasoning process here </think> <answer> answer here </answer>.
User: {question}
Assistant: <think>
reward format checks for proper use of <think></think> and <answer></answer> tags
performance on GSM8K test set
correct format: 1172/1319
correct reward: 966/1319