Prince Osei Aboagye
Guide

The control run

How to run our GSPO pipeline on Qwen2.5-Math-1.5B with PocketRL's data, prompt and grader on one H100, with a decision rule fixed in advance, and check the result stage by stage.

// § 01

What you will do

Our own model gained little from RL. Was the base model too weak, or was our RL pipeline losing something? This run answers that. It puts our GSPO pipeline, with its own learning rate, KL penalty and clipping, on a strong public base model, with the data, prompt and grader of a published study, PocketRL. Its Dense arm is the yardstick.

The run has ten stages:

  1. set up the machine;
  2. build PocketRL’s data;
  3. download the model and make a tokenizer copy;
  4. build a Megatron checkpoint skeleton;
  5. convert the Hugging Face weights into it;
  6. evaluate the base model;
  7. check the conversion;
  8. run GSPO;
  9. read the result against the decision rule, then evaluate five more test sets;
  10. copy everything off and check the copy.
// § 02

Hardware and time

One H100 SXM with the same container image, host CUDA 13 or newer, and a 100 GB volume. The whole run took about 4.1 h of machine time. GSPO itself took 7,681 s: 100 updates, the in-run evaluations at updates 50 and 100, a repeat evaluation Megatron runs after the last update, and two saves.

// § 03

What is ours and what is matched

Ours Matched to PocketRL (commit 82ffdcc5)
Megatron-LM d6316eb45 with our patch the model: Qwen2.5-Math-1.5B
GSPO with a KL penalty of 0.01 to the starting model the data: 8,552 MATH problems of levels 3–5
full Adam with fp32 master weights the qwen-math prompt
learning rate 1e-6, constant; gradient clip 1.0 the reward: Dr. GRPO’s \boxed{} grader, 0 for answers cut off at 3,000 tokens
our agent, metrics, reports and first-update check 16 prompts × 8 answers per step, one update per step

The settings that still differ: GSPO with its KL term against Dr. GRPO without one, a 5-update warm-up, Adam’s β2 of 0.95, and a sequence cap of 3,584 tokens against their 4,096.

// § 04

The decision rule, fixed before any data

The measure is the gain in MATH-500 avg@8 at update 50, over our own reading of the base model. avg@8 is the share of right answers among 8 samples per problem (evaluation). PocketRL’s Dense arm gained about 23 points by update 50 and about 31 by update 100, read off their plots.

\[\Delta \ge \tfrac{1}{2}\,\Delta_{\text{Dense}} \;\Rightarrow\; \text{works}, \qquad \Delta \le \tfrac{1}{4}\,\Delta_{\text{Dense}} \;\Rightarrow\; \text{loses something}\]

where \(\Delta\) is our gain in avg@8 points and \(\Delta_{\text{Dense}}\) the Dense arm’s gain at the same update.

In words: half the published gain means the pipeline works, a quarter or less means it loses something, and anything between means run on to update 100.

At update 50 that is a gain of at least 11.5 points to pass and at most 5.75 to fail. From our base reading of 21.8%, it meant at least 33.3% to pass and at most 27.55% to fail.

// § 05

Steps

C1. Setup

Copy the repository as in the setup guide, then on the machine:

cd /workspace/MyModel
CONTROL_ONLY=1 EXPECT_GPUS=1 MIN_FREE_GB=80 WORKDIR=/workspace bash code/scripts/pod_setup.sh   # 80: a 100 GB volume can show a little under 100 free
source /workspace/env.sh            # MODEL_FAMILY=qwen2p5_math_1p5b and the control's folders
export WANDB_MODE=offline           # no key on this machine; the runs' W&B files can be synced later
mkdir -p /workspace/runs /workspace/qwen
nohup nvidia-smi --query-gpu=timestamp,index,utilization.gpu,temperature.gpu,power.draw,memory.used,clocks.sm,ecc.errors.uncorrected.volatile.total \
    --format=csv -l 10 > /workspace/gpu.csv 2>&1 &

MODEL_FAMILY=qwen2p5_math_1p5b makes code/scripts/megatron/common.sh swap in Qwen’s shape: 28 layers, hidden size 1,536, 12 heads in 2 key-value groups, one GPU, no experts and no recomputation. The RL and evaluation scripts stay the same. In control mode the setup script installs PocketRL’s grader packages and skips our own data.

C2. Data

python -I code/scripts/prepare_control_data.py "$CURRICULUM_DIR"

It downloads PocketRL’s sources at pinned versions, checks their SHA-256, and builds exactly 8,552 training problems.

It also writes the six test sets, 1,547 problems in all: MATH-500, AIME24, AIME25, AMC23, Minerva and OlympiadBench.

C3. Model and tokenizer

hf download Qwen/Qwen2.5-Math-1.5B --revision 4a83ca6e4526a4f2da3aa259ec36c259f66b2ab2 --local-dir "$QWEN_HF_DIR"
python -I code/scripts/make_qwen_tokenizer.py "$QWEN_HF_DIR" "$TOKENIZER_DIR"

The tokenizer copy changes two things, explained in the conversion guide: its pad token differs from its end token, and it leaves out generation_config.json.

C4 and C5. The skeleton and the conversion

RUN_DIR=/workspace/runs/qwen_skeleton bash code/scripts/megatron/qwen_skeleton.sh > /workspace/runs/qwen_skeleton.log 2>&1
PYTHONPATH="$MEGATRON_PATH" python code/scripts/megatron/convert_qwen2_hf.py /workspace/runs/qwen_skeleton/skeleton \
    "$QWEN_HF_DIR" /workspace/qwen/megatron

The skeleton is one iteration of Megatron’s own pretrain_gpt.py at Qwen’s shape, saved in Megatron’s format. The converter then replaces every tensor with the mapped Hugging Face weight, or refuses.

The conversion guide covers both, and their checks.

C6. The base model on MATH-500

Greedy plus 8 samples per problem, on all 500 problems:

RUN_DIR=/workspace/runs/control_base RUN_NAME=control_base EVAL_CKPT=/workspace/qwen/megatron \
    EVAL_CONFIG=code/rl/control_eval500_env.yaml EVAL_PROMPTS=500 EVAL_COLLECT_PROMPTS=16 RL_SEQ=3584 RL_CUDA_GRAPHS=1 \
    bash code/scripts/megatron/eval.sh > /workspace/runs/control_base.log 2>&1

RL_SEQ=3584 is prompt plus answer. Every prompt up to 584 tokens keeps its 3,000 answer tokens, which covers 99% of the training prompts and of MATH-500’s. RL_CUDA_GRAPHS=1 decodes with CUDA graphs; if they fail to capture, rerun with 0 and note it.

Before you trust any rollout, check that the engine samples:

  • grep "Sampling defaults" /workspace/runs/control_base.log must show top_k=0, not top_k=1;
  • the first curriculum batch’s step_stats.jsonl must show about 8 distinct_texts_per_group.

C7. Check the conversion

Compare the log-probabilities Megatron’s engine gave the tokens it sampled in C6 with Hugging Face’s for the same tokens in the same context:

python code/scripts/qwen_logprob_parity.py "$QWEN_HF_DIR" "$TOKENIZER_DIR" /workspace/runs/control_base/rollouts.jsonl \
    /workspace/runs/control_base/rollout_logprobs.jsonl --n 64 --out /workspace/runs/control_base/logprob_parity.json

The gate: PASS when the mean absolute difference is at most 0.05 nats per token, and at most 1% of tokens differ by more than 0.5. A FAIL stops the run.

C8. GSPO

EVAL_RESULTS=/workspace/runs/control_gspo/eval_results.jsonl \
RUN_DIR=/workspace/runs/control_gspo RUN_NAME=control_gspo SFT_CKPT=/workspace/qwen/megatron GSPO_LR=1e-6 \
    PROMPTS_PER_STEP=16 GROUP_SIZE=8 UPDATES_PER_STEP=1 RL_PROMPTS_PER_EVAL=500 RL_SEQ=3584 RL_CUDA_GRAPHS=1 \
    RL_ENV_CONFIG=code/rl/control_env.yaml GSPO_SAMPLES=12800 EXIT_MINS=420 \
    bash code/scripts/megatron/gspo.sh > /workspace/runs/control_gspo.log 2>&1

SFT_CKPT is the converted base model: there is no SFT stage here. The run length follows from:

\[N_{\text{samples}} = U \times P \times G\]

where \(U\) is the number of updates, \(P\) the prompts per update and \(G\) the answers per prompt.

In words: with one update per step, every update trains on one step’s fresh answers.

\(100 \times 16 \times 8 = 12{,}800\), hence GSPO_SAMPLES=12800. The in-run evaluation of MATH-500 comes at updates 50 and 100, each with a checkpoint. With one update per step the ratio is 1 by construction, so the paper’s narrow clip only guards numerical noise.

  • Timing: after update 5, read the time per update from the log. Ours ran about 68–70 s per update.

  • Update 1: the ratio is exactly 1 and the KL 0 on one GPU (gspo_run_report.py --updates-per-step 1), and the rewards are not all zero.

C9. Read the result

python3 code/scripts/analyze_control.py eval <runs>/control_base/eval_results.jsonl \
    <runs>/control_gspo/eval_results.jsonl --after-eval 1      # update 50; --after-eval 2 for update 100
python3 code/scripts/analyze_control.py train <runs>/control_gspo/step_stats.jsonl

C9b. Five more test sets

Evaluate the base model and the update-100 checkpoint on PocketRL’s other five sets, 1,047 problems. Run them after GSPO has ended, so nothing shares the GPU:

RUN_DIR=/workspace/runs/control_base_sets RUN_NAME=control_base_sets EVAL_CKPT=/workspace/qwen/megatron \
    EVAL_CONFIG=code/rl/control_eval5_env.yaml EVAL_PROMPTS=675 EVAL_COLLECT_PROMPTS=16 RL_SEQ=3584 RL_CUDA_GRAPHS=1 \
    bash code/scripts/megatron/eval.sh > /workspace/runs/control_base_sets.log 2>&1
RUN_DIR=/workspace/runs/control_final_sets RUN_NAME=control_final_sets EVAL_CKPT=/workspace/runs/control_gspo/ckpt \
    EVAL_CKPT_STEP=100 EVAL_CONFIG=code/rl/control_eval5_env.yaml EVAL_PROMPTS=675 EVAL_COLLECT_PROMPTS=16 RL_SEQ=3584 \
    RL_CUDA_GRAPHS=1 bash code/scripts/megatron/eval.sh > /workspace/runs/control_final_sets.log 2>&1

EVAL_PROMPTS=675 covers all of OlympiadBench, the largest set. Then read all six sets, MATH-500 from C6 and from the run’s second in-run evaluation:

python3 code/scripts/analyze_control.py sets \
    --before <runs>/control_base/eval_results.jsonl --before <runs>/control_base_sets/eval_results.jsonl \
    --after <runs>/control_gspo/eval_results.jsonl@2 --after <runs>/control_final_sets/eval_results.jsonl

The same tools check that the saved weights are the model the run evaluated in memory, on the dev split:

python3 code/scripts/analyze_control.py eval <runs>/control_gspo/eval_results.jsonl \
    <runs>/control_final_sets/eval_results.jsonl --before-eval 2

Expect mostly identical texts, not all: the batches differ.

C10. Save and check the copy

Copy the runs folder, the conversion record, the parity reports, the data manifest and the final weights to durable storage. Check the copy file by file, by checksum, before you shut the machine down. The checkpoints guide shows how.

// § 06

What to expect

Setup to conversion: all 26 launch configurations passed setup’s flag check; the data built in 4 s with every SHA-256 matched; the conversion replaced 198 tensors and passed its strict key and shape check first time.

C6, the base model on MATH-500:

Ours PocketRL, Table 3
avg@8 21.8% 21.9%
greedy 33.6% —
pass@8 69.6% —

A tenth of a point from their base reading: a mistake anywhere in the chain would have shown here.

The first curriculum batch had 8.0 distinct texts per group of 8, and 93.8% of groups were mixed.

C7: PASS on 63,278 tokens of 64 answers: a mean absolute difference of 0.034 nats per token, and 0.92% of tokens over 0.5.

C8, training (16 problems × 8 answers per update, in blocks of 10 updates):

Updates 1–10 21–30 41–50 61–70 81–90 91–100
Solve rate 24.1% 28.3% 37.1% 47.0% 49.8% 53.8%
Mixed groups 71% 71% 81% 71% 78% 66%
Median answer (tokens) 752 796 711 688 631 614

The solve rate went from 29.3% in updates 1–50 to 48.6% in updates 51–100 (Welch t 11.95). The first update’s KL was 0.0000 on one GPU. No grading hit its time limit, and one gradient spike, at update 36, was caught and clipped.

The decision and the final numbers, MATH-500 avg@8:

Base Update 50 Update 100
avg@8 21.77% 41.42% 53.95%
Gain over base (paired) — +19.65 (SE 1.13, t 17.3) +32.17 (SE 1.41, t 22.9)
PocketRL Dense, read off its plot ~22% ~45% ~53.5%

The gain at update 50 cleared the 11.5-point bar: the pipeline works, and the weak base model explains our own small RL gain. By update 100 the gain was level with Dense’s.

C9b, all six sets, avg@8:

Set (problems) Base Update 100 Paired gain
MATH-500 (500) 21.77% 53.95% +32.17 (t 22.9)
AIME24 (30) 4.17% 7.92% +3.75 (p 0.14)
AIME25 (30) 0.42% 2.50% +2.08 (p 0.25)
AMC23 (40) 12.81% 34.38% +21.56 (t 5.1)
Minerva (272) 5.88% 16.36% +10.48 (t 8.4)
OlympiadBench (675) 12.98% 24.19% +11.20 (t 12.6)
Mean of the six 9.67% 23.21% +13.54 (t 15.2)

PocketRL’s Dense arm reads about 23% for the six-set mean at update 100, so we are level there too.

The AIME sets have 30 problems each, so their gains are not significant.

The saved weights: evaluated on their own, they agreed with the run’s in-memory evaluation as closely as two evaluations of the same weights did: 9 changed answers against 5.

// § 07

Check that it worked

  • Setup ends with == ready, and grep "Sampling defaults" shows top_k=0.
  • The base reading lands near PocketRL’s 21.9%.
  • The log-prob check passes before any GSPO.
  • Update 1 shows KL 0 and no “ratio not exactly 1” alarm.
  • The log has no [boxed grader] timeout lines.
  • The copy matches the machine’s files by checksum.
// § 08

Common problems

Symptom Cause Fix
about 1.44 distinct texts per group of 8 Qwen’s generation_config.json says do_sample: false, and Megatron’s endpoint turned that into greedy decoding make_qwen_tokenizer.py never copies that file
the skeleton stops after 44 s Megatron divides by --eval-interval even with no evaluation --eval-interval 1000 (in qwen_skeleton.sh)
the greedy-text check fails, 11 of 20 openings a base model’s greedy answers start at near-ties that bf16 rounding flips gate on log-probabilities; keep greedy text as a report
training hangs after update 16, the main thread at 100% CPU the grader’s sympy path spun on one answer, on the thread that drives generation skip grading of cut-off answers, and a 10 s CPU-time limit per grading
one update’s gradient norm is 5.77 against 0.18–1.04 one batch; Megatron’s re-run reproduced it, so not the GPU the clip at 1.0 scaled it down; nothing else needed
Qwen’s own tokenizer is refused its pad token equals its end token, which would mask the end label the tokenizer copy’s pad is <|vision_pad|>
// § 09

Read more