Skip to content

RLVR — Reinforcement Learning from Verifiable Rewards

v0.25.0 adds deterministic reward signals for GRPO training on math, code, and JSON-schema tasks. No reward model, no human labels. These rewards run on the transformers backend. backend: mlx trains GRPO natively since v0.77.1 with the built-in accuracy and format rewards only, and refuses reward_fn: verifiable at config load; since v0.77.2 it takes a dense base or a 4-bit mlx-community base, covered upstream only by its hosted macOS test job. See GRPO on MLX.

Enable it

yaml
base: Qwen/Qwen3-8B
task: grpo

data:
  train: math_problems.jsonl
  format: chatml

training:
  reward_fn: verifiable
  verifiable_domain: math   # math | code | json_schema
  lr: 1e-5
  epochs: 1
  gradient_checkpointing: true   # since v0.77.0 the default false turns it off on GRPO
  lora: { r: 16, alpha: 32 }

training.gradient_checkpointing reaches the GRPO trainer since v0.77.0 (#797, #1778). With the default false a GRPO run now trains with checkpointing off, where TRL's own default (on) used to apply, so a config that never set the key uses more activation memory than it did. Keep the line above to keep the memory you had; upstream's shipped GRPO recipes now set it (#1923). With checkpointing on, task: grpo (like ppo and online_dpo) no longer adds a forward hook to the policy's input embedding at every step since v0.77.2: the trl loops switch checkpointing off and back on around generation, and each switch used to register one more hook that transformers never removed, so every generated token ran one more hook per step already taken (#2373, by @ybai08). No speed figure is published for it.

Built-in reward functions

DomainWhat it doesSandbox
mathReads the final answer of the completion and of the gold with one parser (see How the answer is read), compares a numeric gold by value with tolerance and any other gold as normalised textpure Python
codeExecutes Python against expected outputsbest-effort sandbox: subprocess, 5 s timeout, 10 KB output cap, 512 MB address-space limit on POSIX. Network isolation is not guaranteed (see Safety)
json_schemaValidates output against a JSON Schema and scores completenesspure Python

All three live in soup_cli/trainer/rewards.py and are routed through the existing GRPO trainer.

When the reward is a judge, not a verifier (v0.77.0)

A task with no checkable answer can use reward_fn: judge_rank instead (#2047, #2117): one judge call per prompt scores all of its completions against each other, from 0 to 1. It is not verifiable: it needs training.grpo_judge (a judge URL, checked at load: plain http only to a loopback host, and no private, link-local or reserved IP literal) and training.grpo_judge_max_calls, which has no default, and a run that could make more judge calls than that is refused after the data loads and before the model does. It runs on task: grpo only, not on backend: mlx, not with modality: vision, and not beside prm_reward or a rollout_backend. Prompts and completions are sent to the judge host you configure, and a request the judge answers with 429 or a 5xx, or that times out, is retried up to twice inside each counted call, so the host can see up to three requests per counted call. No quality claim is made for it. The settings and limits are on GRPO Plus.

Generate training data

bash
soup data generate \
  --prompt "Math word problems, each with a single exact numeric answer" \
  --provider ollama --count 500 --output verifiable.jsonl

--prompt is required, and --template accepts only code, conversation, qa, preference and reasoning; there is no verifiable template and no flag that selects the verifiable helper (--domain exists, but it only picks the domain of the reasoning template). soup_cli/data/templates/verifiable.py builds problems with ground-truth answers you can verify at training time, but it is a library helper with no command-line selector.

As of v0.76.0, --template reasoning tells the generator how to end each solution so the gold can be read by these rewards: math rows end with a #### <number> line, logic and code rows with an Answer: <answer> line (#1349). Before that the prompt asked only for "the final answer", and a gold such as So there are 42 apples. made soup train refuse the dataset before generation.

How the answer is read

Since v0.76.0 (#1226). GRPO's accuracy reward and the math domain read the completion and the gold with the same parser, so a spelling understood on one side is understood on the other. Before this, only the completion was parsed, and a reference such as 6*7=42\n#### 42 was compared raw.

The answer is whichever of these the text states:

  1. The text after the last ####.
  2. The last \boxed{}. A space before the brace and nested braces are allowed.
  3. The text after The answer is or Answer: (also **Answer**:, and on the next line). The number is read from its own clause, so The answer is 41 apples, not 42. is 41, and The answer is 42 because 6*7=42. is 42.

A completion that states none of these is scored by its last number. A phrase that names more than one distinct value is a hedge and scores 0.0 whatever the gold (The answer is either 41 or 42.).

Both sides are normalised the same way: $ and \(...\) delimiters, trailing punctuation, thousands separators (1,000, 1{,}000), the Unicode minus, \text{} and similar wrappers, degree marks and the compact \frac12 spellings. A variable prefix is kept, so x = 3 does not match y = 3. A numeric gold is compared by value; any other gold, such as \frac{14}{3}, is compared as normalised text. Units are not stripped (42 apples does not match 42) and nothing is evaluated (\frac{1}{2} does not equal 0.5).

Scoring: accuracy returns 1.0 or 0.0, with no partial credit. math returns 1.0 within the tolerance, 0.6 for a near-miss (within max(100 x tolerance, 1e-2)) and 0.0 otherwise; its near-miss band is unchanged.

A gold that states no single final answer is refused before generation, with its split, row and field and a count of the other such rows: a multi-line reference with no marked answer, a hedge, a #### Solution heading over a worked solution, or x = with nothing after it. When some golds are not numbers, validation prints how many are compared as text, so a dataset that mixes numeric and LaTeX answers (MATH-500, for example) loads. PPO's accuracy and math rewards use the same scoring, but PPO's data is not validated this way.

Watching the reward (v0.78.0)

Since v0.78.0 a GRPO run records its per-step training reward in the experiment tracker (reward and reward_std, two nullable columns; NULL means not measured), so a program can read a reward curve the way it reads a loss curve. MLX GRPO does not write the per-step reward. On a GRPO run in the Transformers live panel, a Zero-spread groups line shows the share of groups whose completions all got the same reward, and one warning is logged per run when more than 50% of groups had zero spread for five distinct logged steps. The warning reads GRPO reward diversity is low; that rule is a diagnostic heuristic, not a quality gate, and it changes nothing about training. See Observability for the details and upstream's riders.

Re-run this

If you trainedWhat was wrongWhat to do
GRPO with reward_fn: accuracy, or verifiable with verifiable_domain: math, on a dataset whose reference was an Alpaca output or a ShareGPT or ChatML turn such as 6*7=42\n#### 42The reference was compared raw, so every correct completion scored 0.0, every group had zero reward variance and GRPO got no signal, with no warning (#1226)Re-run. A run whose logged reward sat at 0.0 learned nothing from the reward
GRPO with reward_fn: accuracyIt paid 0.5 whenever the gold string appeared anywhere in the completion (#### 420 for a gold of 42) (#1226)Treat accuracy rewards from earlier versions as partly wrong credit; re-run if the task mattered
GRPO with accuracy or math on MATH-style golds written with \text{}, a degree mark, \frac12 or a variable prefix such as x = 7A correct completion in one spelling scored 0.0 against a gold in another (#1346)Re-run if the logged reward looked low for a model that was answering correctly
soup train --resume on task: grpo with grpo_beta above 0, before v0.77.0The resumed run "restored the optimizer and the step counter and trained a freshly initialised adapter" (#1768, #1797). grpo with grpo_beta: 0 was not affectedUpstream: "Re-run any dpo, ipo or grpo training that was resumed from a checkpoint."
training.relora_steps on task: grpo with grpo_beta above 0, on v0.76.0 or v0.76.1Every ReLoRA restart merged the trained adapter into the base weights trl reads the reference from, "so from the first restart on the reference was the policy as of that step, without an error" (#1835, #1891). Refused at load since v0.77.0Remove relora_steps and train again

Safety

  • code_exec is a best-effort sandbox, not an isolation boundary, and Soup says so in a warning panel the first time it runs. Each completion runs in a short-lived subprocess started with python -I -S, with a 5 s timeout, a 10 KB output cap, a throwaway working directory and a reduced environment. On Linux and macOS it also gets resource limits (512 MB address space, CPU time, file size, open files, processes); on Windows it gets none of those. There is no restricted-builtins mechanism.
  • Network access is not blocked reliably. The guard is a Python-level socket patch, and generated code can bypass it through os.system, subprocess or ctypes. OS-level isolation is added only on Linux with Python 3.12 or newer (the os.unshare call, and only if the kernel allows unprivileged user namespaces; otherwise it falls back silently) and on macOS through /usr/bin/sandbox-exec, the only location Soup runs it from since v0.77.1. Do not use verifiable_domain: code on a host that holds secrets or on untrusted data; run training in a container or VM with no network interface. Soup Cans v2 describes the same isolation tiers.
  • math_verify never uses eval() on model output. Answers are read by the shared answer parser described above and compared as numbers or as normalised text; nothing is evaluated.
  • verifiable_domain is a Pydantic Literal so arbitrary strings can't reach the dispatcher.

See also

  • Training methods — GRPO
  • Autopilot — --goal reasoning writes task: grpo and leaves reward_fn at its default of accuracy; set reward_fn: verifiable yourself to use RLVR

Soup is free and Apache-2.0. If it saved you a training run, starring the repo costs nothing and helps most. You can also fund the GPU time behind the work a 4 GB laptop cannot reach.