Quickstart: RL Training (GRPO)
EngineSurogate EngineThis 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).
1) Pick example configs
Section titled “1) Pick example configs”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 settingsorch.yaml: orchestrator settings (environment, batch size, sampling)
The keys for each file are listed under GRPO (RL) Settings.
2) Run
Section titled “2) Run”GRPO has two single-command modes. Pick the one that matches your GPUs:
Split-GPU mode — surogate grpo (recommended for ≥2 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:
surogate grpo --train examples/grpo/train.yaml --infer examples/grpo/infer.yaml --orch examples/grpo/orch.yaml \ --infer-gpus 0 --trainer-gpus 1Surogate 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:
surogate grpo-colocate --train examples/grpo/train.yaml --infer examples/grpo/infer.yaml --orch examples/grpo/orch.yamlThis 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.
3) Outputs
Section titled “3) Outputs”Checkpoints, LoRA adapters and logs are written under the trainer’s output_dir.
Resuming an interrupted run
Section titled “Resuming an interrupted run”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.
4) Example Configuration
Section titled “4) Example Configuration”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:
model: Qwen/Qwen3-0.6Boutput_dir: ./outputsgpus: 1 # ignored in split mode — derived from --trainer-gpus
per_device_train_batch_size: 1sequence_len: 2048max_steps: 40logging_steps: 1
learning_rate: 2e-4lr_scheduler_type: constantmax_grad_norm: 1.0weight_decay: 0.01
recipe: fp8-hybrid
lora: truelora_rank: 16lora_alpha: 32
# QeRL noise scheduler (optional, improves exploration)noise_scheduler: enabled: true sigma_start: 5e-2 sigma_end: 5e-4 num_stages: 10infer.yaml:
model: Qwen/Qwen3-0.6Benable_lora: truemax_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/tokenorch.yaml:
model: name: Qwen/Qwen3-0.6B lora_adapter: default
env: - id: reverse-text
batch_size: 128rollouts_per_example: 16seq_len: 2048max_steps: 40
sampling: max_tokens: 1285) Recommended Hyperparameters
Section titled “5) Recommended Hyperparameters”Learning Rate
Section titled “Learning Rate”RL training usually needs lower learning rates than SFT:
- Recommended range:
5e-7to5e-5(start with5e-6) - Schedule:
constantorcosine(constant is common for RL) - Warmup: 0 steps is fine for RL; use a few steps if training is unstable
Batch Size
Section titled “Batch Size”batch_size(inorch.yaml): number of rollouts per training step.128-512is typical.rollouts_per_example: samples per prompt. Use8-16for a varied reward signal.per_device_train_batch_size: usually1(packed sequences fill the batch).
GRPO Loss
Section titled “GRPO Loss”ratio_type:"token"(per-token ratios, recommended) or"sequence"(per-sequence)kl_tau: KL penalty coefficient. Start with0.0and raise it if the policy drifts too fast.adv_tau: advantage scaling. The default1.0works well.
See GRPO loss for every loss key.
Masking Thresholds
Section titled “Masking Thresholds”A mask drops tokens where the trainer and the rollout engine disagree too much:
ipo_mask_low/ipo_mask_high(default0.2/0.2): a token is left out when the trainer’s probability for it is more thanipo_mask_highabove the engine’s, or more thanipo_mask_lowbelow itratio_clip(default7.389, which is e²): caps each kept token’s importance ratio, so one rare token can’t dominate the batch- If
is_maskedin the logs goes above 50%, lower the learning rate or raisekl_tau
QeRL Noise
Section titled “QeRL Noise”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
Precision
Section titled “Precision”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, orqlora_fp4: truefor quantized base weights
Serving Memory
Section titled “Serving Memory”Two infer.yaml keys decide whether a large policy plus LoRA fits in memory:
max_num_seqscaps concurrent sequences, which sets the size of the CUDA-graph and activation buffers. A 27B model served TP2 withenable_lora: trueOOMs at the default and fits at16.kv_cache_dtype: fp8halves KV bytes per token, raising sustainable concurrency on a KV-bound server. It also perturbs sampled logprobs, which feed GRPO’s importance ratio, so checkmismatch_klafter enabling it.
Both are unset by default, so the engine’s own defaults apply.
6) Advanced: Three-Process Mode
Section titled “6) Advanced: Three-Process Mode”For multi-node setups, or whenever you want each component in its own process, run three commands separately:
# Terminal 1: Inference serverCUDA_VISIBLE_DEVICES=0 surogate grpo-infer infer.yaml
# Terminal 2: Orchestratorsurogate grpo-orch orch.yaml
# Terminal 3: TrainerCUDA_VISIBLE_DEVICES=1 surogate grpo-train train.yamlOn 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; undernohupor 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 3m00sWhen 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
modelfield must match across all three config files. -
max_stepsintrain.yamlandorch.yamlshould match.
See also
Section titled “See also”- RL Training guide: the full architecture, config reference and tuning tips
- RL Environments: write your own environment and reward function
- Quickstart: SFT: supervised fine-tuning, often a good first step before RL
- Quickstart: Pretraining
- Configuration
- Back to docs index