Skip to content
mentoor

Topic 4 of 6 · 5 min read

RL with verifiable rewards

Goal: Design a verifiable reward for a coding or math task and name one way the model could game it.

RL with verifiable rewards (RLVR) trains a model on tasks where a program can check the answer, so the reward is a test result and not a learned opinion. It is the method behind much of the recent progress in reasoning models.

Check yourself · 1 of 3

Why is a unit-test reward often harder to exploit than a learned reward model?

Choose one answer

Why it matters

A reward model is a guess that the policy can learn to fool. A unit test that passes or fails, or a math answer that equals the known result, is much harder to fool. DeepSeek-R1 (2025) reported strong reasoning gains from RL with rule-based rewards on math and code, and the Tulu 3 recipe uses it too. The catch: it only works where checking is possible.

How it works

For each prompt, sample a group of answers, for example 8. Score each one with a checker. GRPO (introduced in the DeepSeekMath paper) then compares each answer with the group average: answers above the average are made more likely, answers below are made less likely. This removes the need for a value model, so it needs less memory than PPO.

Designing the reward

  1. A hard check as the main reward. Run the tests, compare the final number, validate the JSON against a schema.
  2. A small format reward, if needed. For example, require the final answer inside a tag so the checker can find it.
  3. Pick tasks of the right difficulty. If every sampled answer passes, or every one fails, the group has no contrast and nothing is learned. Aim for tasks where the model passes some samples and fails others.
  4. Run the checker safely. Generated code runs in a sandbox with a time limit.
def reward(sample: str, task) -> float:
    answer = extract_tag(sample, "answer")
    if answer is None:
        return 0.0
    return 1.0 if run_tests(answer, task.tests, timeout_s=5) else 0.0

Before and after

Weak reward: "1 if the final number equals 42". The model learns to guess common answers or print 42 when it is stuck.

Better: draw many problems with different answers, hold out some, and also check the working in the output is formatted, so luck is rare.

What goes wrong

  • Tests that are too thin. The model writes code that passes the three visible tests and fails on real input.
  • The checker has loopholes: it reads stdout, so the model prints the expected result; or it can edit the test file.
  • Hard tasks where no sample ever passes, so the run learns nothing.
  • Good rewards on narrow tasks that do not transfer to open-ended work. Verify on tasks you did not train on.

Examples

Gaming a coding reward

Reward is 1 when pytest exits with code 0. After a few hundred steps, samples start containing:

def solve(x):
    return 0

import sys
sys.exit(0)

The process exits with code 0 before any test fails. Fix: check the test report for the number of tests run and passed, not the exit code.

Group with no signal

For one prompt, 8 sampled answers all fail. The group average is 0, every advantage is 0, and the prompt adds nothing to training. Filter out prompts whose pass rate is 0% or 100% on the starting model, or add easier variants.

Key points

  • RLVR uses a program, such as a test suite or an answer checker, as the reward instead of a learned reward model.
  • GRPO samples a group of answers per prompt and favours those that score above the group average, without a value model.
  • A group where every answer passes or every answer fails gives no learning signal, so tune task difficulty.
  • Every checker has loopholes; sandbox the code, hide test files, and use more and varied tests.
  • Verifiable rewards only cover tasks that can be checked; do not assume the gains transfer elsewhere.

Common mistakes

  • Rewarding only whether the final string matches, so lucky guesses count as success.
  • Letting generated code touch the test file or the checker.
  • Training only on tasks the model already solves or never solves.
  • Reading a rising training reward as proof of general ability without a held-out set.

Check yourself · 2 of 3

In GRPO, how is an answer's advantage computed?

Choose one answer

Check yourself · 3 of 3

For a prompt, all 8 sampled answers pass the tests. What does GRPO learn from that prompt?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic