grpo-rlvr-training
它能做什么
这个功能用来训练 AI 完成可以被自动验证的任务,比如解数学题或编写代码。它使用一种名为 GRPO 的强化学习方法,确保 AI 学会做对。
适用场景
- ✓你需要 AI 解数学题的时候。
- ✓你希望 AI 编写能正常运行的代码的时候。
- ✓AI 的任务有明确“对”或“错”答案的时候。
技能链接
https://github.com/wshobson/agents/blob/main/plugins/llm-finetuning/skills/grpo-rlvr-training/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“训练 AI 解数学方程,并验证答案是否正确。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会拿到任务并尝试解答。系统会自动检查答案是否正确。如果正确,AI 就会获得奖励,并学会做得更好;如果错误,它就会再试一次。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
GRPO & RLVR Training
This skill assumes finetuning-method-selection
already routed here because the target behavior
has a verifiable pass/fail signal — not
demonstrations (lora-qlora-recipes) or
preference pairs (preference-optimization).
What follows is when RL is the right tool, the
reference recipe, the mandatory reward-inspection
gate, and how to pick a GRPO variant when the
base recipe misbehaves.
Input: a routing decision (RLVR via GRPO)
plus a verifier (code executor, test suite,
schema checker, or grader) for the target task.
Output format: a validated GRPO config — the
kwarg values in references/grpo-memory.md and
the reward functions in
references/reward-functions.md, not free-form
advice — that llm-finetuning-training-engineer
consumes directly.
When RL Applies
GRPO+RLVR only pays off when task success is
algorithmically checkable — a unit test
passes, a parser accepts the output, a tool call
matches an expected schema, a math answer matches
a ground truth. If grading the output requires
human judgment or a subjective rubric, that's an
eval-harness and judge-calibration problem first
— see eval-harness-first — not a reason to skip
straight to RL.
Before opening a GRPO run, confirm the model can sometimes succeed on the target task already. RL sharpens an existing capability by reweighting toward the samples that already work; it does not install a capability from zero.
- The model never succeeds, even at low
temperature across many samples: the gap is
format or task understanding, not policy
refinement. Route back to SFT first
(
lora-qlora-recipes) and only return to this skill once the base success rate is nonzero. - The model succeeds sometimes, inconsistently: this is the GRPO sweet spot — proceed to The Recipe below.
The standing rule for the whole plugin: DPO for
taste, GRPO for reasoning. If the signal is a
preference between two acceptable outputs, that's
preference-optimization, not this skill.
The Recipe
The reference recipe is TRL's GRPOTrainer with
vLLM-backed generation:
from trl import GRPOConfig, GRPOTrainer
grpo_args = GRPOConfig(
output_dir="./outputs-grpo",
use_vllm=True,
vllm_mode="colocate", # single GPU; "server" for multi-GPU
num_generations=8, # floor — fewer starves the group-relative baseline
learning_rate=5e-7, # settled range for GRPO
beta=0.01, # KL coefficient vs the reference policy
per_device_train_batch_size=8,
gradient_accumulation_steps=4,
bf16=True,
logging_steps=10,
seed=3407,
)
trainer = GRPOTrainer(
model=SFT_CHECKPOINT,
args=grpo_args,
reward_funcs=[format_reward, correctness_reward], # references/reward-functions.md
train_dataset=prompts, # prompt-only — GRPO generates its own completions
processing_class=tokenizer,
)
trainer.train()
vllm_mode="colocate"runs generation and training on the same GPU — the default for a single-GPU box.vllm_mode="server"points at a separate vLLM server process and is the multi-GPU path — generation and training don't compete for the same device.num_generations≥ 8 is a floor, not a suggestion: GRPO's advantage estimate is relative to the group mean, and fewer than 8 samples per prompt produces a noisy baseline.- Reward is composite — a format reward (did the output parse / match the required structure) plus a correctness reward (did the answer verify). A well-formed-but-wrong answer and a malformed one should not score identically; correctness alone loses that signal.
learning_rate=5e-7andbeta=0.01are the settled starting point; deviate only after the base run is stable and reward-inspected (below).
Memory sizing for this recipe by target size
class: references/grpo-memory.md.
The Inspection Rule
Run the reward function against 50–100 sampled outputs and manually read the results before starting the actual training run. This is a gate, not a one-time sanity check.
If the reward function's judgment disagrees with a human reading of that sample, fix the reward function first. Training against an uninspected reward, or tuning hyperparameters to compensate for one silently scoring the wrong thing, is how a run reward-hacks: the model optimizes cleanly toward the wrong target, and that doesn't surface as a training-loop bug.
…
常见问题
“verifiable”(可验证)是什么意思?
意思是计算机可以确切地判断答案对错,不需要人工来评判。
什么时候不应该使用这个功能?
如果任务需要人的主观判断,比如写诗或给出建议,这个功能就不太合适。它最适合有客观答案的任务。
如果 AI 一个都答不对怎么办?
如果即使经过调整 AI 仍然从不答对,可能需要先进行更基础的训练。这个功能是用来提升 AI 已经有一点基础的能力,而不是从零开始教它。
详情
作者的原始描述
Train reasoning and verifiable-task behavior with GRPO and reinforcement learning from verifiable rewards (RLVR). Use when task success is algorithmically checkable (math, code, tool calls, structured output), when designing GRPO reward functions, or when a GRPO run diverges or reward-hacks.
repo: wshobson/agents
热度
- GitHub 星标
- 41k
- 排名
- #6732
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …