Reinforcement Learning2024

RLOO

Back to Basics: REINFORCE Leave-One-Out (RLOO) Ahmadian et al. (Cohere) arXiv

RLOO measures how much each answer beats or trails the average of the other answers to the same question.

Why it mattered

In GRPO, subtracting the group mean that includes sample ii shrinks the advantage by (K−1)/K(K-1)/K, and dividing by a 4-sample standard deviation injects huge variance. Cohere showed that classic REINFORCE with a leave-one-out baseline beats PPO while needing only K=4K=4 completions per prompt and zero critic network.

Core insight

For each completion ii in a KK-sample group, compute its baseline from the other K−1K-1 samples: Ai=ri−1K−1∑j≠irjA_i = r_i - \frac{1}{K - 1} \sum_{j \ne i} r_j Pair this unbiased advantage with importance-sampling policy gradients and KL-to-reference shaping.

GRPORecipe(advantage='rloo', validator='math', group_size=4, kl_coef=0.02) runs leave-one-out RL server-side in one CLI or SDK command with single-GPU initial-weight Schulman k3 KL. Need unclipped losses.ImportanceSampling() or custom Python environments? Drop down to interactive Trainer with advantages.RLOO().

When to use

Use RLOO when rollout generation is expensive (long contexts, slow sandboxes, or tool calls) and you want an unbiased critic-free baseline with just K=4K=4 samples per prompt. For larger groups (G≥8G \ge 8) with multiple PPO epochs per batch, GRPO or Dr. GRPO is a better fit.

Step-by-step walkthrough

  1. 01

    Import verifiable prompts into a versioned dataset

    Pull GSM8K server-side with client.datasets.from_hf() so prompts and reference answers live together in a versioned dataset.

    client.datasets.from_hf("openai/gsm8k", config="main", split="train", prompt="question", answer="answer", limit=2560, name="gsm8k-grpo")
  2. 02

    Configure compact K=4 groups with advantage='rloo'

    GRPORecipe(advantage='rloo', group_size=4, kl_coef=0.02) excludes rir_i from its own baseline, halving rollout generation cost relative to G=8G=8 while keeping the gradient estimator unbiased and anchored to frozen initial weights on the same GPU.

    GRPORecipe(model="qwen/qwen3-8b", validator="math", advantage="rloo", group_size=4, max_tokens=1024, kl_coef=0.02, max_steps=80)
  3. 03

    Launch on 1× GPU and monitor in grad runs watch

    Preview token cost with --dry-run, run with --max-cost-usd 8 --wait, and stream live rewards and kl_ref via grad runs watch rloo-gsm8k.

    grad runs watch rloo-gsm8k

Implementation

train.py
from grad import Grad, adapters
from grad.recipes import GRPORecipe

client = Grad()
ds = client.datasets.from_hf(
    "openai/gsm8k", config="main", split="train", prompt="question", answer="answer", limit=2560, name="gsm8k-grpo"
)

recipe = GRPORecipe(
    model="qwen/qwen3-8b",
    validator="math",
    advantage="rloo",
    group_size=4,
    max_tokens=1024,
    kl_coef=0.02,
    max_steps=80,
    system_prompt="Solve step by step and end with \\boxed{...}.",
    adapter=adapters.LoRA(rank=32),
)

run = client.runs.create(dataset=ds, name="rloo-gsm8k", recipe=recipe, max_cost_usd=8.0).wait()
print(run.artifact.ref, run.eval_report)

Benchmarks

Reported results from the original paper compared against its baseline.

TL;DR Summarization Win RatePythia 6.9B vs. reference (RLOO K=4 vs. PPO)
+4.5 pts
PPO (with value critic)74%
RLOO (K=4, critic-free)78.5%

Models & datasets

ModelDurationEst. cost
Qwen3 8Brecommendedqwen/qwen3-8b
~18 min~$1.45
Qwen3 4Bfast smoke runqwen/qwen3-4b
~9 min~$0.70
Gemma 4 12B ITgoogle/gemma-4-12b-it
~24 min~$2.10
DatasetSourceSize
GSM8K MathHugging Face7,473 train / 1,319 test

Practical gotchas

  • RLOO requires group_size >= 2; K=4K=4 is the sweet spot between sampling cost and baseline variance.
  • Managed GRPORecipe takes 1 optimizer step per rollout batch with clipped GRPOKL; if you run a custom interactive Trainer loop with unclipped losses.ImportanceSampling(), keep it to 1 step per batch or switch to losses.PPO().
  • Keep kl_coef around 0.01–0.04 on verifiable reasoning tasks so the policy stays coherent without choking exploration.

grad primitives