← Back home

01 / Machine learning & language models

PythonGPT

Starting from the same base weights as Qwen’s own Instruct model, I built a post-training pipeline that nearly matches it on HumanEval+ and beats it on MBPP+.

Python · PyTorch · Qwen2.5-Coder · DeepSeek API · Docker · EvalPlus · GRPO · H100

Same starting point, same benchmarks.

Qwen released two versions of its 0.5B coding model: a raw base checkpoint and an Instruct model, which Qwen’s team post-trained from that base. The base, Qwen2.5-Coder-0.5B, has 494M parameters. It can complete code, but it can’t follow instructions. PythonGPT starts from the same base and turns it into a Python coding assistant that takes a task and writes a correct, self-contained standard-library function.

The project had two aims. One was to learn post-training by building each step myself: data curation, supervised fine-tuning (SFT), benchmarking and reinforcement learning. The other was to match Qwen’s official Instruct model under the same measurements.

After three SFT stages and a final round of execution-reward RL (GRPO), the model passes 54.3% of HumanEval+ against the Instruct model’s 54.9%, and 53.4% of MBPP+ against 43.9%, with both models graded by the same harness.

HumanEval+
54.3%
MBPP+
53.4%
vs Qwen Instruct
−0.6 / +9.5
Parameters
0.49B
Training rounds
3 SFT + RL
Teacher data
≈$19

pass@1 with one greedy answer per task, a chat prompt, a 512-token answer limit, and EvalPlus grading in an isolated Docker container. “vs Qwen Instruct” is the difference in points on HumanEval+ / MBPP+ against Qwen2.5-Coder-0.5B-Instruct, graded under the same protocol.

Study / checkpoint lineage Checkpoints from one base model Qwen's Instruct model was post-trained by Qwen from the base model B0. My first SFT run, S1, trained B0 on one dataset and scored 28.0 on HumanEval+. The main track trained S2 from B0 on curated data (34.1), continued it into S3 with wider data (50.6), and finished with GRPO reinforcement learning (54.3), which is PythonGPT. Qwen Instruct scores 54.9. B0 · base S1 · SFT S2 · SFTS3 · SFTGRPO · RL 9.128.034.150.654.3 PythonGPT 01 / BASE02 / FIRST SFT03 / MAIN TRACK Qwen Instruct 54.9
The number in each box is HumanEval+ pass@1. Qwen’s Instruct model and every one of my checkpoints start from the same base weights, so the final comparison is post-training against post-training. S1 was the first pass through the whole loop; S2 started again from the base with curated data.

Head-to-head with Qwen’s Instruct model

Published scores use each team’s own prompts and settings, so I downloaded the Instruct model and graded it with exactly the harness I use for my own checkpoints.

BenchmarkPythonGPTQwen InstructDifference
HumanEval56.159.8−3.7
HumanEval+54.354.9−0.6
MBPP60.352.9+7.4
MBPP+53.443.9+9.5

pass@1, % of tasks, both models under my protocol. On LiveCodeBench v6 (January–April 2025), which no model here trained on, every small model is near zero: S3 solved 3 of 175 problems and Qwen Instruct 1 of 175.

Four rounds of training, one yardstick

Every checkpoint is graded with the same prompts, decoding settings, answer limit and sandbox, so each row isolates one change. HumanEval+ and MBPP+ tasks never enter the training data; the dataset build checks every row against all 542 of them.

Chart / HumanEval+ by checkpoint HumanEval+ pass@1 for each checkpoint B0 base 9.1, S1 28.0, S2 34.1, S3 50.6, GRPO 54.3. Qwen Instruct, shown as a dashed reference line, scores 54.9. 0204060 HumanEval+ pass@1 (%) B0 · base: 9.1 HumanEval+ · Qwen2.5-Coder-0.5B base, no post-trainingB0 · base9.1 S1 · SFT: 28.0 HumanEval+ · First SFT on OpenCoder educational_instructS1 · SFT28.0 S2 · SFT: 34.1 HumanEval+ · Curated 197K-row SFTS2 · SFT34.1 S3 · SFT: 50.6 HumanEval+ · KodCode and wider data, continued from S2S3 · SFT50.6 GRPO · RL: 54.3 HumanEval+ · execution-reward RL from S3 · PythonGPTGRPO · RL54.3 Qwen Instruct · 54.9
The dashed line is Qwen’s Instruct model under the same protocol. The base scores low here partly because it was never trained to stop after an answer: many of its replies ran to the token limit.
CheckpointWhat changedHumanEvalHumanEval+MBPPMBPP+
B0Qwen2.5-Coder-0.5B base, no post-training11.69.1––
S1First SFT · OpenCoder educational set, ~118K rows30.528.0––
S2Curated SFT · 197K test-verified rows36.634.155.348.7
S3S2 + KodCode and wider data53.750.660.351.1
GRPO · PythonGPTS3 + GRPO on executed tests56.154.360.353.4
Qwen InstructQwen’s own post-training of B0, graded here59.854.952.943.9

pass@1, % of tasks, every row graded by the same harness. MBPP was not run for B0 and S1.

S1: the first pass

The first checkpoint trained on the full OpenCoder educational_instruct subset, about 118K rows, in Qwen’s chat format, with loss computed only on the answer. It ran on my home PC (an RX 9070 XT under ROCm in WSL2), which first meant tracking down missing ROCm runtime libraries. Late in the run the loss turned into NaN; I recovered by resuming from a checkpoint saved before the failure.

The same stage produced the evaluation tools every later row depends on: an inference script, HumanEval+ answer generation and a sandboxed Docker grader. S1 scored 28.0% on HumanEval+, up from 9.1%.

Building the training set

More rows of the same kind were not likely to help, so for S2 I rebuilt the data around one rule: a row counts only if its code runs and its tests pass. Each source gets its own adapter. The adapters keep code only, reject third-party imports and unsafe calls, re-run each row’s tests in Docker, and remove exact and near repeats. They also compare every row against all 542 HumanEval+ and MBPP+ tasks by function name and wording, so benchmark tasks stay out of training.

SourceWhat it isVerified rows
OpenCodeInstructNVIDIA’s 5M synthetic rows, all read; 422K passed the strict filter and the Docker re-run420,682
Self-OSS-InstructBigCode’s execution-filtered instructions, after repeats were removed40,104
DeepSeek distillationMy own teacher-written problems with verified solutions and tests3,071
KodCodeAdded for S3; prompts in the signature-plus-docstring shape HumanEval uses83,875
S2 training setCurated mix · 77M tokens197,374
S3 training setNew KodCode and OpenCodeInstruct rows plus a 15% replay of S2 · 118M tokens265,427

A study of why OpenCodeInstruct rows failed the filter showed that most rejected rows had broken generated tests, not broken code.

The checks also caught a leak in the data itself: 20% of KodCode prompts ended with their own pytest tests, so the model could see the answer’s test cases inside the question. I found and fixed the bug before it reached training.

Distilling a teacher

Asking a model to “be diverse” produces repeats, so the program decides the mix. It assigns each question a skill from a list of about 235, a form and a difficulty, and DeepSeek writes the questions. A second stage writes a solution plus six to ten test asserts for each. A third runs every solution against its tests in a locked-down Docker container. After a review I tightened the checks: every test must call the function, the signature must match the question, stubs must include docstring examples that the solution passes, and a retry must also pass the test that failed the earlier attempt.

Verified rows
3,071
Skills
~235
API cost
≈$19

Training

A hand-written training loop

For S2 I replaced the library trainer (TRL’s SFTTrainer) with train_torch.py, a training loop written by hand in plain PyTorch. Batches are capped by padded token count rather than row count, so long and short rows don’t waste memory on padding. Loss is averaged per token over each 64-row update however it is split into chunks, so splitting never changes the gradient. The schedule is warmup followed by cosine decay, with gradient clipping, and checkpoints resume exactly. Before renting a GPU, I checked the loop against TRL on one batch and tested resume on my Mac.

S2 and S3 on rented H100s

RunStarts fromRowsTokensEpochsTime · cost
S2B0 base197K77M3≈$9.50 on Vast.ai, failed runs included
S3S2, epoch-2 checkpoint265K118M2102 minutes

1× H100 · AdamW · peak LR 5e-5 · 64 rows per update · bf16 autocast.

  • NaN gradients. The first S2 runs died with non-finite gradients. The cause was PyTorch’s cuDNN attention kernel on padded bf16 batches; turning that kernel off fixed it.
  • Memorization. In S2’s third epoch, validation loss jumped: the model had started memorizing. S3 continued from the epoch-2 checkpoint instead.
  • Loss picked the wrong checkpoint. In S3, the checkpoint with the lowest validation loss was worse on every benchmark than the final one. From then on, checkpoints were chosen by running tests.

S3 shrank the gap to Qwen on HumanEval+ from 34 tasks to 7.

Reinforcement learning on executed tests

Before RL, I read S3’s failures task by task. They were mostly logic errors that contradict the examples in the prompt, not formatting problems. S3 solves 72% of HumanEval+ tasks in at least one of 10 samples (pass@10), and 39% of unseen tasks gave mixed pass and fail results across samples. Mixed results are what RL needs to learn from.

The GRPO trainer samples eight answers to each task, runs each one against hidden tests, and gives a reward of 1 only if every test passes. Advantages are normalized within each task’s group of eight, so passing answers become more likely relative to failing ones on the same task.

SettingValue
Starts fromS3
Each step16 tasks × 8 answers
Reward1 if all tests pass, 0 otherwise
AdvantageNormalized within each task’s group of 8
Task pool6,416 unused verified tasks, benchmark look-alikes removed
Learning rate3e-6, best of three variants
Hardware1× H100

The best run added 3.7 points on HumanEval+ and 2.3 on MBPP+ over S3. Those gains are small and close to run-to-run noise.

What I learned

  • Data mattered most. Distinct, test-verified data that matches the benchmark’s prompt shape (a signature plus a docstring) gave far bigger jumps than tuning the recipe. The S2 → S3 data change alone was worth 16.5 points on HumanEval+.
  • Choose models by running tests. Validation loss and the small held-out pass rate both picked the wrong checkpoint or learning rate.
  • More epochs memorize. The third pass over the data hurt; adding more distinct rows helped.
  • Make runs reproducible. Every run has a log, revisions are pinned, and comparisons use the same protocol, all recorded in the training log.

Limits

  • The model answers only in code, never in prose, because every training answer was code-only. Chat-style SFT rows would fix this.
  • GRPO gains are close to noise. Bigger or better-targeted RL runs are the obvious next experiment.
  • Small models, mine and Qwen’s, are near zero on unseen competition problems (LiveCodeBench). These benchmarks measure short standard-library functions.
  • The benchmark screen matches function names and wording; it can’t catch the same problem in different words, and the base model’s pretraining data can’t be audited.
  • In distillation, the teacher writes both the solution and its tests, so a shared misunderstanding can pass.