Qwen2.5-Coder-7B-Instruct, GRPO on LeetCode (step 90)

Qwen/Qwen2.5-Coder-7B-Instruct post-trained with GRPO on LeetCode problems. The reward comes from running the generated code against the problem's unit tests in a sandbox. This is the step-90 checkpoint of a 180-step run.

Code, configs and technical report: github.com/giovanni-vaccarino/grpo-code

Results

Held-out set: the 228 problems of LeetCodeDataset's test split, released after mid-2024. Each task gets 10 samples at temperature 0.8 plus one greedy response, graded by the same sandboxed verifier used in training.

Base model This model
LeetCode held-out pass@1, sampled 14.1% 21.9%
LeetCode held-out pass@1, greedy 14.9% 20.2%
LeetCode held-out pass@5 24.3% 28.2%
LeetCode held-out pass@10 28.5% 28.9%
pass@1 Easy / Medium / Hard (48 / 101 / 79 tasks) 44.6 / 7.9 / 3.4% 56.0 / 17.1 / 7.3%
HumanEval+ pass@1 / pass@10 83.0 / 93.9% 85.6 / 90.2%
MBPP+ pass@1 / pass@10 68.1 / 85.2% 72.5 / 82.8%

Training

Algorithm GRPO: 8 responses per prompt, advantage = (reward โˆ’ group mean) / group std, PPO-clip 0.2, no KL term, no critic
Reward 1 if every unit test passes, else 0. The code runs sandboxed (user, network, PID and mount namespaces; 6 CPU-seconds per response)
Data LeetCodeDataset train split minus 611 tasks every earlier response had solved: 2,030 tasks. 90 steps ร— 64 prompts โ‰ˆ 2.8 passes
Hyperparameters lr 1e-6 (constant), AdamW, 64 prompts per step, 4 optimizer steps per batch, grad clip 1.0, temperature 1.0, max response 1,024 tokens
Stack veRL 0.9.1 (sync trainer), vLLM 0.24 rollouts, FSDP2, 4 ร— GH200. vLLM's log-probs were reused as the old policy's
Precision Trained with fp32 master weights and bf16 compute; exported in bf16

Usage

Use the base model's chat template. Training prompts gave the problem statement and LeetCode's starter code, and ended with: "Write your solution in Python 3 and put the complete code in a single ```python block."

from transformers import AutoModelForCausalLM, AutoTokenizer

repo = "gianniiii/Qwen2.5-Coder-7B-Instruct-GRPO-LeetCode"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, dtype="bfloat16", device_map="auto")
messages = [{"role": "user", "content": "Write a Python function two_sum(nums, target) that returns the indices of the two numbers adding up to target."}]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
print(tok.decode(model.generate(inputs, max_new_tokens=512)[0][inputs.shape[1]:], skip_special_tokens=True))
Downloads last month
56
Safetensors
Model size
8B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for gianniiii/Qwen2.5-Coder-7B-Instruct-GRPO-LeetCode

Base model

Qwen/Qwen2.5-7B
Finetuned
(493)
this model

Dataset used to train gianniiii/Qwen2.5-Coder-7B-Instruct-GRPO-LeetCode