Downloads · 30 days
12
4% of all-time downloads
liangzhidanta/Qwen3-4B-GRPO-119
Qwen3-4B-GRPO-119 is a text generation model from liangzhidanta. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
Downloads · 30 days
12
4% of all-time downloads
All-time downloads
282
Public
Parameters
4B
8.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors8 GB · 100%
From the Hugging Face model README
<a name="-english-version"></a>
GRPO Reinforcement Learning on Math Reasoning — trained end-to-end on 8×RTX 4090 with slime
AIME 2024: 57.5% → 65.0% (+7.5pp) · response length −49% · truncation −54%
</div>Top-left: AIME 2024 pass@1 every 20 iterations (gray band = ±1pp test-retest noise, calibrated by 3 baseline runs). Top-right: train-batch reward rises while mean response length falls — accuracy and efficiency improve together. Bottom-left: truncation ratio halves on both train (8k cap) and eval (16k cap). Bottom-right: rollout dominates ~85–96% of each ~23-min iteration.
</div>| Metric | Base (Qwen3-4B) | This model (iter 119) | Δ |
|---|---|---|---|
| AIME 2024 pass@1 (30 problems × 16 samples) | 57.5% | 65.0% (peak 66.0% @ iter 79) | +7.5pp |
| Train batch reward (DAPO-Math-17K) | 0.535 | 0.629 | +0.094 |
| Response length median | 7,400 tok | 3,777 tok | −49% |
| Response length mean | 6,403 tok | 4,476 tok | −30% |
| Truncated ratio (train, 8k cap) | 46.1% | 21.1% | −54% |
| Truncated ratio (eval, 16k cap) | 37.5% | 19.6% | −48% |
| Degenerate repetition | 0.0% | 0.0% | — |
The headline finding: the model became more accurate and more concise simultaneously — no length-based reward hacking, entropy stays healthy (0.34 → 0.29).
<details> <summary><b>📊 Full AIME eval history (7 points)</b></summary>| Iteration | 0 (base) | 19 | 39 | 59 | 79 | 99 | 119 |
|---|---|---|---|---|---|---|---|
| pass@1 | 57.5% | 60.6% | 61.0% | 63.1% | 66.0% | 64.8% | 65.0% |
| Algorithm | GRPO — group-relative advantage, group size G=8 (32 prompts × 8 samples = 256 trajectories/iteration = 1 optimizer step) |
| Clipping | Asymmetric DAPO-style: eps-clip 0.2 / eps-clip-high 0.28; no KL penalty (coef 0), no entropy bonus |
| Reward | Rule-based verifier (deepscaler RM): extract \boxed{} after </think>, grade vs ground truth via mathd/sympy symbolic equivalence → 0/1 |
| Data | zhuzilin/dapo-math-17k, 32 prompts/iter ≈ 5.5 epochs over the run |
| Optimizer | Adam, lr 1e-6 constant, wd 0.1, β=(0.9, 0.98) |
| Precision | bf16 mixed precision (fp32 grad all-reduce, fp32 optimizer/master weights) |
| Rollout | SGLang v0.5.15.post1, 4 engines × TP=2, temperature 1.0, max response 8192 tok |
| Training | Megatron-LM, TP=4 + sequence parallel → DP=2, full activation recompute, dynamic token packing (4096/microbatch), chunked log-prob softmax |
| Colocation | Rollout and training share the same 8 GPUs via torch_memory_saver weight offload/reload each iteration |
| Duration | 46.6 hours / 120 iterations (~23 min each: ~15–18 min rollout + ~2–3 min train + sync) |
The official recipe targets 8×H100 80GB. Adapting it to 8×RTX 4090 24GB required (full story in EXPERIMENT_REPORT.md):
expandable_segments:True against fragmentation (requires the +slime fork of torch_memory_saver);loginctl enable-linger + tmux) and checkpoint retention (53GB each, keep-latest) for a multi-day run.from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model = AutoModelForCausalLM.from_pretrained(
"liangzhidanta/Qwen3-4B-GRPO-119",
torch_dtype=torch.bfloat16, device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained("liangzhidanta/Qwen3-4B-GRPO-119")
messages = [{"role": "user",
"content": "Find the number of ordered pairs of prime numbers $(p, q)$ "
"such that $3p + 5q = 102$. Put the answer in \\boxed{}."}]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
).to(model.device)
out = model.generate(**inputs, max_new_tokens=8192,
do_sample=True, temperature=1.0)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Best served with thinking mode enabled (default chat template) and a generous generation budget; the model was trained at temperature 1.0.
<a name="-中文版本"></a>
GRPO 数学推理强化学习 —— 基于 slime 框架、在 8×RTX 4090 上端到端训练
AIME 2024:57.5% → 65.0%(+7.5 个百分点)· 响应长度 −49% · 截断率 −54%
</div>左上:每 20 轮一次的 AIME 2024 pass@1(灰色带 = ±1pp 复测噪声,由 3 次基线重复测量标定)。右上:训练批奖励上升的同时平均响应长度下降——正确率与效率同步改善。左下:训练(8k 上限)与评估(16k 上限)的截断率均减半。右下:每轮约 23 分钟中 rollout 占 85–96%。
</div>| 指标 | 基座(Qwen3-4B) | 本模型(第 119 轮) | 变化 |
|---|---|---|---|
| AIME 2024 pass@1(30 题 × 16 采样) | 57.5% | 65.0%(峰值 66.0% @ 第 79 轮) | +7.5pp |
| 训练批平均奖励(DAPO-Math-17K) | 0.535 | 0.629 | +0.094 |
| 响应长度中位数 | 7,400 tok | 3,777 tok | −49% |
| 响应长度均值 | 6,403 tok | 4,476 tok | −30% |
| 截断率(训练,8k 上限) | 46.1% | 21.1% | −54% |
| 截断率(评估,16k 上限) | 37.5% | 19.6% | −48% |
| 退化复读率 | 0.0% | 0.0% | — |
核心发现:模型变得更准的同时变得更简洁——没有出现"靠写长碰答案"的 reward hacking,策略熵保持健康(0.34 → 0.29)。
<details> <summary><b>📊 完整 AIME 评估历史(7 个评估点)</b></summary>| 轮次 | 0(基线) | 19 | 39 | 59 | 79 | 99 | 119 |
|---|---|---|---|---|---|---|---|
| pass@1 | 57.5% | 60.6% | 61.0% | 63.1% | 66.0% | 64.8% | 65.0% |
| 算法 | GRPO——组内相对 advantage,组大小 G=8(32 prompt × 8 采样 = 256 条轨迹/轮 = 1 个优化器步) |
| 裁剪 | DAPO 式非对称裁剪:eps-clip 0.2 / eps-clip-high 0.28;无 KL 惩罚(系数 0)、无熵加成 |
| 奖励 | 规则判分器(deepscaler RM):取 </think> 后正文的 \boxed{},与标准答案做 mathd/sympy 符号等价比对 → 0/1 |
| 数据 | zhuzilin/dapo-math-17k,每轮 32 个 prompt,全程约 5.5 个 epoch |
| 优化器 | Adam,lr 1e-6 恒定,wd 0.1,β=(0.9, 0.98) |
| 精度 | bf16 混合精度(梯度 fp32 all-reduce,优化器/主权重 fp32) |
| 推理引擎 | SGLang v0.5.15.post1,4 引擎 × TP=2,温度 1.0,响应上限 8192 token |
| 训练后端 | Megatron-LM,TP=4 + 序列并行 → DP=2,全层激活重计算,动态 token 打包(4096/microbatch),log-prob 分块 softmax |
| 显存共存 | 推理与训练共用同一批 8 卡,每轮通过 torch_memory_saver 做权重卸载/重载 |
| 耗时 | 46.6 小时 / 120 轮(每轮约 23 分钟:rollout 15–18 分 + 训练 2–3 分 + 同步) |
官方配方按 8×H100 80G 设计,适配 8×RTX 4090 24G 做了以下改造(完整记录见 EXPERIMENT_REPORT.md):
expandable_segments:True 对抗碎片(需要 torch_memory_saver 的 +slime fork);loginctl enable-linger + tmux)与 checkpoint 保留策略(每份 53GB,只留最新)。from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model = AutoModelForCausalLM.from_pretrained(
"liangzhidanta/Qwen3-4B-GRPO-119",
torch_dtype=torch.bfloat16, device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained("liangzhidanta/Qwen3-4B-GRPO-119")
messages = [{"role": "user",
"content": "求满足 3p + 5q = 102 的质数有序对 (p, q) 的个数。答案写在 \\boxed{} 中。"}]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
).to(model.device)
out = model.generate(**inputs, max_new_tokens=8192,
do_sample=True, temperature=1.0)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
建议开启思考模式(默认 chat template)并给足生成长度;模型训练温度为 1.0。
| 文件 | 说明 |
|---|---|
model-*.safetensors | 微调权重(第 119 轮,GRPO) |
curves.png | 四联训练曲线图 |
EXPERIMENT_REPORT.md | 完整实验报告:配置、指标、工程日志 |