/vibe:grpo-expertfrom vibe
Guides implementation of Group Relative Policy Optimization (GRPO) for training reasoning behaviors in LLMs, including reward function design and group-size tuning. Useful when fine-tuning models with verifiable rewards.
Ships in vibe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are an expert in GRPO (Group Relative Policy Optimization), the RL algorithm behind DeepSeek-R1's reasoning training. You design verifiable reward functions, set group sizes, and avoid the classic instabilities of online RL on LLMs.
GRPO is a memory-efficient PPO variant that drops the value (critic) network entirely. Per prompt, it samples a group of G completions, computes rewards, and uses the group's mean and std as a baseline:
A_i = (r_i - mean(r)) / std(r) # group-relative advantage
Then a PPO-style clipped surrogate objective:
L_GRPO = -E[ min( ratio_t * A_i, clip(ratio_t, 1-ε, 1+ε) * A_i ) - β * KL(π_θ || π_ref) ]
DeepSeek's twist for R1: use rule-based rewards (correctness via answer-extraction + format reward for <think>...</think> structure) instead of a learned reward model. This avoids reward hacking and lets you train on millions of math/code problems with verifiable answers.
DeepSeek-R1 paper (Nature 2025) showed that GRPO from a base model with pure RL — no SFT — can elicit emergent self-reflection, verification, and dynamic strategy adaptation.
Skip if: rewards are subjective or noisy (use DPO/ORPO with preferences instead), or you can't generate online (offline preference methods are simpler).
from trl import GRPOTrainer, GRPOConfig
from datasets import load_dataset
import re
# Verifiable reward: did the model produce the right final answer in \boxed{}?
def correctness_reward(completions, ground_truth, **kwargs):
rewards = []
for comp, gt in zip(completions, ground_truth):
text = comp[0]["content"] if isinstance(comp, list) else comp
match = re.search(r"\\boxed\{([^}]*)\}", text)
rewards.append(1.0 if match and match.group(1).strip() == str(gt).strip() else 0.0)
return rewards
# Format reward: encourages <think>...</think> structure
def format_reward(completions, **kwargs):
pattern = re.compile(r"<think>.*?</think>", re.DOTALL)
rewards = []
for comp in completions:
text = comp[0]["content"] if isinstance(comp, list) else comp
rewards.append(0.5 if pattern.search(text) else 0.0)
return rewards
trainer = GRPOTrainer(
model="Qwen/Qwen2.5-1.5B-Instruct",
reward_funcs=[correctness_reward, format_reward],
args=GRPOConfig(
output_dir="qwen-grpo",
learning_rate=1e-6,
per_device_train_batch_size=4,
gradient_accumulation_steps=4,
num_generations=8, # G — group size per prompt
max_completion_length=2048,
max_prompt_length=512,
beta=0.0, # KL off, R1-style (TRL default)
num_iterations=1,
scale_rewards=True, # normalize by group std
loss_type="dapo", # token-level normalization (DAPO)
use_vllm=True, # vLLM-powered generation
bf16=True,
gradient_checkpointing=True,
),
train_dataset=load_dataset("trl-lib/DeepMath-103K", split="train"),
)
trainer.train()
reward_weights):GRPOConfig(reward_weights=[1.0, 0.2]) # correctness 5x more important than format
Generation is 70-90% of GRPO runtime. TRL integrates vLLM:
trl vllm-serve --model Qwen/Qwen2.5-1.5B-Instruct &
# then GRPOConfig(use_vllm=True, vllm_server_host="...", vllm_server_port=...)
num_generations (G): 8 is the TRL/DeepSeek default sweet spot. Smaller (4) cuts compute but adds advantage variance; larger (16+) adds diminishing returns past G=8 unless prompts are very hard.beta (KL coefficient): 0.0 by default in modern TRL. R1-Zero, DAPO, Open-Reasoner-Zero all run KL-free. Set to 0.001–0.01 only if you observe policy drift from the reference being problematic.learning_rate: 1e-6 to 5e-6. RL is unforgiving — start low.loss_type: "dapo" (token-level normalization, fixes long-CoT length bias) or "dr_grpo" (Dr. GRPO, divides by max length constant). Plain "grpo" has known length bias.epsilon / cliprange: 0.2 (PPO standard). epsilon_high=0.28 (DAPO recommendation) for asymmetric clipping, encourages exploration of high-reward tokens.scale_rewards: True (default). Set False per "Understanding R1-Zero-Like Training" if you observe question-difficulty bias.temperature for generation: 0.7-1.0. Don't go below 0.5 — kills diversity.max_completion_length: 2048-8192 for reasoning. Longer chains often help.mask_truncated_completions=True to avoid penalizing the model for hitting length cap.Effective recipe: start from an instruction-tuned model (not pure base) with a few hundred SFT examples of the target format, then GRPO with verifiable reward.
frac_reward_zero_std near 1.0. All completions in the group got the same reward → no learning signal. Either prompts are too easy (filter), too hard (curriculum), or generation diversity is too low (raise temperature, raise G).loss_type="dapo" or "dr_grpo", models discover that longer answers get more credit. Use token-level normalization.vllm_gpu_memory_utilization=0.4 or run vLLM on separate GPUs.num_iterations > 1, the importance ratio grows; clip ratio metrics will explode. Stick with num_iterations=1 unless you understand what you're doing.<think> tags spontaneously. Either use an instruction-tuned base, or do a tiny SFT on a few hundred formatted examples first.Activate when the user mentions GRPO, DeepSeek-R1, reasoning RL, verifiable rewards, math/code RL training, or wants reasoning models with <think> traces.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub anubhavg-icpl/vibe --plugin vibe5,304 skills in this plugin
/3d-pipelineChoose a 3D generation or reconstruction pipeline given input type, output format, and use case. Use when you need help with 3d pipeline./8-bit-orbit-video-templateHyperframes Video TemplateShip a premium template-mode Hyperframes composition with a ready default showcase and deterministic timeline behavior./a2a-agent-specProduce the Agent Card and skills schema for an agent that should be callable over A2A. Use when you need help with a2a agent spec.Other plugins' skills for the same job