Skip to main content

GRPO Training

Train language models using Group Relative Policy Optimization (GRPO) with custom reward environments. Instead of a reward model, you provide a Python module with an environment class that runs multi-turn episodes and returns scores.

Overview

GRPO is different from PPO in a key way:
  • PPO requires a pre-trained reward model to score responses
  • GRPO uses a custom environment that you write — it generates multiple completions per prompt, scores them via your environment, and optimizes the policy relative to the group
This makes GRPO ideal for agentic training where rewards come from task execution (tool use, code execution, multi-turn interactions) rather than a static reward model.

Quick Start

Python API

Environment Interface

You implement a Python class with 3 methods:

Environment with Configuration

Pass JSON configuration to your environment via --rl-env-config:
The JSON is parsed and passed as **kwargs to your environment constructor:

Requirements

GRPO training requires both --rl-env-module and --rl-env-class to be specified. These are validated at startup — if either is missing, training will fail with a clear error message.
GRPO uses TRL’s GRPOTrainer (requires TRL >= 0.28.0). The tokenizer padding side is automatically set to left as required by GRPO.

Parameters

GRPO-Specific Parameters

Shared RL Parameters (PPO + GRPO)

vLLM Acceleration

Use vLLM for significantly faster completion generation during GRPO training:
Two modes are available:
  • colocate (default) — vLLM shares the GPU with training. Adjust --vllm-gpu-memory-utilization (default 0.3) to control the memory split.
  • server — vLLM runs on dedicated GPUs. Training processes are automatically reduced by --vllm-server-gpus.
vLLM requires a separate install: pip install aitraining[vllm] (requires vllm>=0.14.0).
GRPO does not require --data-path — the dataset is built by your environment’s build_dataset() method.

How It Works

  1. Environment loads — Your module is imported via importlib.import_module(), class instantiated with optional config
  2. Dataset builtenv.build_dataset(tokenizer) returns prompts
  3. Model generates — GRPO generates rl_num_generations completions per prompt
  4. Environment scoresenv.score_episode() is called for each completion, returning 0.0-1.0
  5. GRPO optimizes — Policy is updated relative to the group scores (better completions get higher weight)

Example: Hotel Booking Agent

GRPO vs PPO

Best Practices

  1. Start with simple environments — Validate that scoring works before complex multi-turn logic
  2. Use small rl_num_generations — Start with 4, increase if you need more diversity in completions
  3. Score between 0 and 1 — Use the full range; avoid always returning 0 or 1
  4. Test your environment independently — Make sure build_dataset() and score_episode() work before training
  5. Use LoRA — GRPO with full fine-tuning requires significant memory; LoRA makes it practical
  6. Small learning rates — Start with 1e-5, same guidance as PPO

Next Steps

PPO Training

RLHF with reward models

RL Module

Low-level RL building blocks

DPO Training

Simpler alternative with preference data

LoRA/PEFT

Efficient fine-tuning