Skip to content
SurogateSurogateDocs
↑↓ to move↵ to openesc to close

Quickstart: RL Training (GRPO)

This quickstart runs a GRPO reinforcement learning example. GRPO improves a model from a reward signal: the model generates answers, a reward function scores them, and the trainer updates the model toward the better ones. A single command runs the three components involved: Surogate’s inference server, an orchestrator (rollouts and rewards) and a Surogate trainer (policy-gradient updates).

You’ll find example configs in examples/grpo/. GRPO uses three config files:

  • train.yaml: trainer settings (model, LoRA, precision, loss function)
  • infer.yaml: inference server settings
  • orch.yaml: orchestrator settings (environment, batch size, sampling)

The keys for each file are listed under GRPO (RL) Settings.

GRPO has two single-command modes. Pick the one that matches your GPUs:

Section titled “Split-GPU mode — surogate grpo (recommended for ≥2 GPUs)”

The inference server and the trainer run on separate GPUs and communicate through the filesystem. You assign GPU ids to each side:

bash
surogate grpo --train examples/grpo/train.yaml --infer examples/grpo/infer.yaml --orch examples/grpo/orch.yaml \
--infer-gpus 0 --trainer-gpus 1

Surogate derives the trainer’s GPU count from --trainer-gpus, so the YAML gpus field becomes optional. For MoE models, ep_size is also set to the trainer GPU count automatically. All flags are in the CLI reference.

Co-locate mode — surogate grpo-colocate (single-GPU or shared-GPU setups)

Section titled “Co-locate mode — surogate grpo-colocate (single-GPU or shared-GPU setups)”

Serving and training take turns on one GPU and share a single resident copy of the base weights:

bash
surogate grpo-colocate --train examples/grpo/train.yaml --infer examples/grpo/infer.yaml --orch examples/grpo/orch.yaml

This mode takes no GPU-assignment flags. See Single-GPU GRPO for its current limits.

If you use uv, prefix any of the above with uv run.

Checkpoints, LoRA adapters and logs are written under the trainer’s output_dir.

The trainer resumes from its latest checkpoint automatically: resume_from_checkpoint defaults to true, and the trainer looks in checkpoint_dir. Re-run the same command and it picks up where it stopped (details in Checkpoint resume):

Resuming from checkpoint step 5 (next batch: 6)

A checkpoint at step S means “trained through batch S”, so the resumed run starts at S + 1. That one number drives everything downstream: which batch is packed, which batch is read from the transport, the LR schedule position, the save cadence, and the step number the broadcast weights are published under. The orchestrator, which may already be waiting on the broadcast for step S, is therefore unblocked instead of falling out of sync.

Set resume_from_checkpoint: false in train.yaml to force a fresh run.

Here is a minimal setup using the reverse-text environment. With co-locate (grpo-colocate) it runs on a single GPU; with split mode (grpo) it runs on two GPUs, one for the server and one for the trainer:

train.yaml:

yaml
model: Qwen/Qwen3-0.6B
output_dir: ./outputs
gpus: 1 # ignored in split mode — derived from --trainer-gpus
per_device_train_batch_size: 1
sequence_len: 2048
max_steps: 40
logging_steps: 1
learning_rate: 2e-4
lr_scheduler_type: constant
max_grad_norm: 1.0
weight_decay: 0.01
recipe: fp8-hybrid
lora: true
lora_rank: 16
lora_alpha: 32
# QeRL noise scheduler (optional, improves exploration)
noise_scheduler:
enabled: true
sigma_start: 5e-2
sigma_end: 5e-4
num_stages: 10

infer.yaml:

yaml
model: Qwen/Qwen3-0.6B
enable_lora: true
max_lora_rank: 32
# Optional; omit to use the engine's own defaults.
# max_num_seqs: 16 # concurrency cap — see "Serving memory" below
# kv_cache_dtype: fp8 # halves KV bytes/token

orch.yaml:

yaml
model:
name: Qwen/Qwen3-0.6B
lora_adapter: default
env:
- id: reverse-text
batch_size: 128
rollouts_per_example: 16
seq_len: 2048
max_steps: 40
sampling:
max_tokens: 128

RL training usually needs lower learning rates than SFT:

  • Recommended range: 5e-7 to 5e-5 (start with 5e-6)
  • Schedule: constant or cosine (constant is common for RL)
  • Warmup: 0 steps is fine for RL; use a few steps if training is unstable
  • batch_size (in orch.yaml): number of rollouts per training step. 128-512 is typical.
  • rollouts_per_example: samples per prompt. Use 8-16 for a varied reward signal.
  • per_device_train_batch_size: usually 1 (packed sequences fill the batch).
  • ratio_type: "token" (per-token ratios, recommended) or "sequence" (per-sequence)
  • kl_tau: KL penalty coefficient. Start with 0.0 and raise it if the policy drifts too fast.
  • adv_tau: advantage scaling. The default 1.0 works well.

See GRPO loss for every loss key.

A mask drops tokens where the trainer and the rollout engine disagree too much:

  • ipo_mask_low/ipo_mask_high (default 0.2/0.2): a token is left out when the trainer’s probability for it is more than ipo_mask_high above the engine’s, or more than ipo_mask_low below it
  • ratio_clip (default 7.389, which is e²): caps each kept token’s importance ratio, so one rare token can’t dominate the batch
  • If is_masked in the logs goes above 50%, lower the learning rate or raise kl_tau

QeRL adds controlled noise to the inference weights to encourage exploration (QeRL noise scheduler keys):

  • sigma_start: 5e-2 (initial noise level)
  • sigma_end: 5e-4 (final noise level)
  • num_stages: 10 (geometric decay intervals)
  • Useful when rollouts show little reward diversity early in training

Every precision option from SFT is available (see Precision & recipes):

  • FP8-Hybrid (recipe: fp8-hybrid): Recommended for Hopper+ GPUs
  • BF16 (recipe: bf16): Maximum accuracy
  • QLoRA: Add qlora_fp8: true, qlora_bnb: true, or qlora_fp4: true for quantized base weights

Two infer.yaml keys decide whether a large policy plus LoRA fits in memory:

  • max_num_seqs caps concurrent sequences, which sets the size of the CUDA-graph and activation buffers. A 27B model served TP2 with enable_lora: true OOMs at the default and fits at 16.
  • kv_cache_dtype: fp8 halves KV bytes per token, raising sustainable concurrency on a KV-bound server. It also perturbs sampled logprobs, which feed GRPO’s importance ratio, so check mismatch_kl after enabling it.

Both are unset by default, so the engine’s own defaults apply.

For multi-node setups, or whenever you want each component in its own process, run three commands separately:

bash
# Terminal 1: Inference server
CUDA_VISIBLE_DEVICES=0 surogate grpo-infer infer.yaml
# Terminal 2: Orchestrator
surogate grpo-orch orch.yaml
# Terminal 3: Trainer
CUDA_VISIBLE_DEVICES=1 surogate grpo-train train.yaml

On a single host, prefer surogate grpo (split GPUs) or surogate grpo-colocate (shared GPUs), which manage the lifecycle of all three components for you.

  • Reading progress from a log file. The orchestrator’s rollout progress bar is rendered by tqdm, which needs a TTY; under nohup or any redirect it writes nothing useful. The orchestrator also emits plain [progress] lines with the same information, so a redirected log stays readable:

    [progress] step 11 Generating rollouts (train): 128/256 (50%) | 42.7/min | elapsed 3m00s | eta 3m00s

    When a step stops completing rollouts, the log says so explicitly:

    [progress] step 11 Generating rollouts (train): 128/256 — NO completions in the last 60s (inflight 64, scoring 3, elapsed 14m22s)

    When you see that line, check the inference server. A deep queue, an unresponsive engine and failing rollouts all look the same from a frozen progress bar.

  • The model field must match across all three config files.

  • max_steps in train.yaml and orch.yaml should match.