Skills · Data & AI

GRPO & RLVR Training

Unverified32/40

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.

Originally by wshobson · MIT

Claude CodePartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
CursorPartialPlain prose you can paste in — but no Cursor rules file
CodexPartialPlain prose you can paste in — but no AGENTS.md
Gemini CLIPartialPlain prose you can paste in
CopilotPartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add grpo-rlvr-training

This command does not work yet — the CLI is still being built. Until then, use Raw in the reader below to take the file.

Who is stuck, and on what

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.

The whole source

No sign-in, no blur, nothing truncated
grpo-rlvr-training/SKILL.md206 lines7.6 KBRawView on GitHub
Frontmatter — 2 properties
namegrpo-rlvr-training
descriptionTrain 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.
1---
2name: grpo-rlvr-training
3description: 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.
4---A5No allowed-tools declared — no way to tell what this skill may touch
5 
6# GRPO & RLVR Training
7 
8This skill assumes `finetuning-method-selection`
9already routed here because the target behavior
10has a verifiable pass/fail signal — not
11demonstrations (`lora-qlora-recipes`) or
12preference pairs (`preference-optimization`).
13What follows is when RL is the right tool, the
14reference recipe, the mandatory reward-inspection
15gate, and how to pick a GRPO variant when the
16base recipe misbehaves.
17 
18**Input:** a routing decision (RLVR via GRPO)
19plus a verifier (code executor, test suite,
20schema checker, or grader) for the target task.
21**Output format:** a validated GRPO config — the
22kwarg values in `references/grpo-memory.md` and
23the reward functions in
24`references/reward-functions.md`, not free-form
25advice — that `llm-finetuning-training-engineer`
26consumes directly.
27 
28## When RL Applies
29 
30GRPO+RLVR only pays off when task success is
31**algorithmically checkable** — a unit test
32passes, a parser accepts the output, a tool call
33matches an expected schema, a math answer matches
34a ground truth. If grading the output requires
35human judgment or a subjective rubric, that's an
36eval-harness and judge-calibration problem first
37— see `eval-harness-first` — not a reason to skip
38straight to RL.
39 
40Before opening a GRPO run, confirm the model can
41**sometimes** succeed on the target task already.
42RL sharpens an existing capability by reweighting
43toward the samples that already work; it does not
44install a capability from zero.
45 
46- **The model never succeeds, even at low
47 temperature across many samples:** the gap is
48 format or task understanding, not policy
49 refinement. Route back to SFT first
50 (`lora-qlora-recipes`) and only return to this
51 skill once the base success rate is nonzero.
52- **The model succeeds sometimes,
53 inconsistently:** this is the GRPO sweet spot —
54 proceed to The Recipe below.
55 
56The standing rule for the whole plugin: **DPO for
57taste, GRPO for reasoning.** If the signal is a
58preference between two acceptable outputs, that's
59`preference-optimization`, not this skill.
60 
61## The Recipe
62 
63The reference recipe is TRL's `GRPOTrainer` with
64vLLM-backed generation:
65 
66```python
67from trl import GRPOConfig, GRPOTrainer
68 
69grpo_args = GRPOConfig(
70 output_dir="./outputs-grpo",
71 use_vllm=True,
72 vllm_mode="colocate", # single GPU; "server" for multi-GPU
73 num_generations=8, # floor — fewer starves the group-relative baseline
74 learning_rate=5e-7, # settled range for GRPO
75 beta=0.01, # KL coefficient vs the reference policy
76 per_device_train_batch_size=8,
77 gradient_accumulation_steps=4,
78 bf16=True,
79 logging_steps=10,
80 seed=3407,
81)
82 
83trainer = GRPOTrainer(
84 model=SFT_CHECKPOINT,
85 args=grpo_args,
86 reward_funcs=[format_reward, correctness_reward], # references/reward-functions.md
87 train_dataset=prompts, # prompt-only — GRPO generates its own completions
88 processing_class=tokenizer,
89)
90 
91trainer.train()
92```
93 
94- **`vllm_mode="colocate"`** runs generation and
95 training on the same GPU — the default for a
96 single-GPU box.
97- **`vllm_mode="server"`** points at a separate
98 vLLM server process and is the multi-GPU path —
99 generation and training don't compete for the
100 same device.
101- **`num_generations` ≥ 8** is a floor, not a
102 suggestion: GRPO's advantage estimate is
103 relative to the group mean, and fewer than 8
104 samples per prompt produces a noisy baseline.
105- **Reward is composite** — a format reward (did
106 the output parse / match the required
107 structure) plus a correctness reward (did the
108 answer verify). A well-formed-but-wrong answer
109 and a malformed one should not score
110 identically; correctness alone loses that
111 signal.
112- **`learning_rate=5e-7`** and **`beta=0.01`** are
113 the settled starting point; deviate only after
114 the base run is stable and reward-inspected
115 (below).
116 
117Memory sizing for this recipe by target size
118class: `references/grpo-memory.md`.
119 
120## The Inspection Rule
121 
122**Run the reward function against 50–100 sampled
123outputs and manually read the results before
124starting the actual training run.** This is a
125gate, not a one-time sanity check.
126 
127If the reward function's judgment disagrees with
128a human reading of that sample, fix the reward
129function first. Training against an uninspected
130reward, or tuning hyperparameters to compensate
131for one silently scoring the wrong thing, is how
132a run reward-hacks: the model optimizes cleanly
133toward the wrong target, and that doesn't surface
134as a training-loop bug.
135 
136This inspection is a Phase 1 gate input for
137`/finetune` — the same 50–100-sample read that
138catches a broken reward function here is what that
139command checks for before it lets a GRPO brief
140proceed.
141 
142Complete reward function implementations to
143inspect against — exact-match, schema-validation,
144unit-test-execution, a length-penalty wrapper, and
145a rubric-as-reward judge pattern:
146`references/reward-functions.md`.
147 
148## Variant Selection
149 
150The base recipe above is the default. Reach for a
151variant only when a specific failure mode shows
152up, not preemptively:
153 
154| Failure mode | Variant | Why |
155|---|---|---|
156| Entropy collapse / degenerate long chain-of-thought | **DAPO** | Decouples clip bounds and relaxes the KL penalty that over-regularizes exploration on long reasoning traces |
157| Reward or output length trends up regardless of quality | **Dr.GRPO** | Removes GRPO's length-normalization bias so reward tracks correctness, not completion length |
158| Training a mixture-of-experts model | **GSPO** | Moves the importance-sampling ratio to the sequence level instead of per-token — per-token ratios are unstable on MoE routing, so GSPO is required here, not optional |
159 
160Start with plain GRPO. Watch for the specific
161symptom — collapsing entropy on long CoT, a
162length-reward correlation, or MoE instability —
163and only then swap in the matching variant above.
164Don't pre-select a variant before the base recipe
165has actually shown the failure mode.
166 
167## VLM RL Is Reference-Only
168 
169Vision-language RL is **not executed by this
170plugin in v1** — it's documented here for
171context, not as a runnable path. Tooling is
172fragmented across ms-swift and EasyR1-derived
173forks with no one-line TRL command yet, and naive
174text-only GRPO applied to a VLM tends to
175reward-hack by optimizing the text-reasoning trace
176while ignoring the image — the model learns to
177sound right without looking at the input. A VLM
178RL run is a research spike outside this skill's
179supported recipe, not a variant of The Recipe
180above.
181 
182## References
183 
184- `references/reward-functions.md` — complete
185 Python reward functions (exact-match
186 correctness, schema validation, unit-test
187 execution, a length-penalty wrapper, and a
188 rubric-as-reward judge pattern) to inspect under
189 The Inspection Rule before any training run.
190- `references/grpo-memory.md` — memory sizing by
191 target size class, vLLM sleep-mode and
192 optimizer-state tactics, Unsloth's long-context
193 RL chunking, and the DGX Spark bandwidth caveat
194 for decode-heavy rollouts.
195 
196Related skills: `finetuning-method-selection`
197routes here once a verifiable pass/fail signal
198exists; `preference-optimization` is the sibling
199skill for preference pairs rather than verifiable
200rewards; `eval-harness-first` covers judge
201calibration for any reward that isn't purely
202code-checkable. On DGX Spark, defer to the
203`dgx-spark-ops` plugin's skills, when installed,
204for the memory/thermal remediation ladder this
205skill's memory table doesn't cover.
206 

Reviews

Installed this one?Write the first review and take the Trailblazer badge.

Reviews only open after a real install, so this is empty — and we leave it empty rather than invent one.

Alternatives

Also in Data & AI