agent-management
Create, manage, and orchestrate AI agents using the AI Maestro CLI. Use when the user asks to "create agent", "list agents",…
Expert guidance for GRPO/RL fine-tuning with TRL for reasoning and task-specific model training
Claude Code
$ npx -y skills add davila7/claude-code-templates --skill post-training-grpo-rl-training --agent claude-code
Codex
$ npx skills add davila7/claude-code-templates --skill post-training-grpo-rl-training -a codex -y
Cursor
$ npx skills add davila7/claude-code-templates --skill post-training-grpo-rl-training -a cursor -y
Gemini CLI
$ npx skills add davila7/claude-code-templates --skill post-training-grpo-rl-training -a gemini-cli -y
GitHub Copilot
$ npx skills add davila7/claude-code-templates --skill post-training-grpo-rl-training -a github-copilot -y
OpenCode
$ npx skills add davila7/claude-code-templates --skill post-training-grpo-rl-training -a opencode -y
Windsurf
$ npx skills add davila7/claude-code-templates --skill post-training-grpo-rl-training -a windsurf -y
name: post-training-grpo-rl-training description: Expert guidance for GRPO/RL fine-tuning with TRL for reasoning and task-specific model training license: MIT metadata: version: 1.0.0 author: Orchestra Research tags: [Post-Training, Reinforcement Learning, GRPO, TRL, RLHF, Reward Modeling, Reasoning, DPO, PPO, Structured Output] dependencies: [transformers>=4.47.0, trl>=0.14.0, datasets>=3.2.0, peft>=0.14.0, torch]
Expert-level guidance for implementing Group Relative Policy Optimization (GRPO) using the Transformer Reinforcement Learning (TRL) library. This skill provides battle-tested patterns, critical insights, and production-ready workflows for fine-tuning language models with custom reward functions.
Use GRPO training when you need to:
**Do NOT use GRPO for:**
---
**Key Mechanism:**
**Critical Difference from PPO:**
**Mathematical Intuition:**
For each prompt p:
1. Generate N completions: {c₁, c₂, ..., cₙ}
2. Compute rewards: {r₁, r₂, ..., rₙ}
3. Learn to increase probability of high-reward completions
relative to low-reward ones in the same group**Golden Rules:** 1. **Compose multiple reward functions** - Each handles one aspect (format, correctness, style) 2. **Scale rewards appropriately** - Higher weight = stronger signal 3. **Use incremental rewards** - Partial credit for partial compliance 4. **Test rewards independently** - Debug each reward function in isolation
**Reward Function Types:**
| Type | Use Case | Example Weight | |------|----------|----------------| | **Correctness** | Verifiable tasks (math, code) | 2.0 (highest) | | **Format** | Strict structure enforcement | 0.5-1.0 | | **Length** | Encourage verbosity/conciseness | 0.1-0.5 | | **Style** | Penalize unwanted patterns | -0.5 to 0.5 |
---
**Critical Requirements:**
**Example Structure:**
from datasets import load_dataset, Dataset
SYSTEM_PROMPT = """
Respond in the following format:
<reasoning>
[Your step-by-step thinking]
</reasoning>
<answer>
[Final answer]
</answer>
"""
def prepare_dataset(raw_data):
"""
Transform raw data into GRPO-compatible format.
Returns: Dataset with columns:
- 'prompt': List[Dict] with role/content (system + user messages)
- 'answer': str (ground truth, optional but recommended)
"""
return raw_data.map(lambda x: {
'prompt': [
{'role': 'system', 'content': SYSTEM_PROMPT},
{'role': 'user', 'content': x['question']}
],
'answer': extract_answer(x['raw_answer'])
})**Pro Tips:**
**Template Structure:**
def reward_function_name(
prompts, # List[List[Dict]]: Original prompts
completions, # List[List[Dict]]: Model generations
answer=None, # Optional: Ground truth from dataset
**kwargs # Additional dataset columns
) -> list[float]:
"""
Evaluate completions and return rewards.
Returns: List of floats (one per completion)
"""
# Extract completion text
responses = [comp[0]['content'] for comp in completions]
# Compute rewards
rewards = []
for response in responses:
score = compute_score(response)
rewards.append(score)
return rewards**Example 1: Correctness Reward (Math/Coding)**
def correctness_reward(prompts, completions, answer, **kwargs):
"""Reward correct answers with high score."""
responses = [comp[0]['content'] for comp in completions]
extracted = [extract_final_answer(r) for r in responses]
return [2.0 if ans == gt else 0.0
for ans, gt in zip(extracted, answer)]**Example 2: Format Reward (Structured Output)**
import re
def format_reward(completions, **kwargs):
"""Reward XML-like structured format."""
pattern = r'<reasoning>.*?</reasoning>\s*<answer>.*?</answer>'
responses = [comp[0]['content'] for comp in completions]
return [1.0 if re.search(pattern, r, re.DOTALL) else 0.0
for r in responses]**Example 3: Incremental Format Reward (Partial Credit)**
def incremental_format_reward(completions, **kwargs):
"""Award partial credit for format compliance."""
responses = [comp[0]['content'] for comp in completions]
rewards = []
for r in responses:
score = 0.0
if '<reasoning>' in r:
score += 0.25
if '</reasoning>' in r:
score += 0.25
ifOpen-source registry and CLI for Claude Code components: agents, commands, skills, hooks, MCPs, settings and mods
Create, manage, and orchestrate AI agents using the AI Maestro CLI. Use when the user asks to "create agent", "list agents",…
Send and receive cryptographically signed messages between AI agents using the Agent Messaging Protocol (AMP). Use when the user…
Search auto-generated codebase documentation for function signatures, API docs, class definitions, and code comments. Use when…
Query the code graph database to understand component relationships, dependencies, and change impact. Use when the user asks to…
Search conversation history and semantic memory to recall previous discussions, decisions, and context. Use when the user asks to…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.