Reinforcement learning (GRPO and GSPO)

GRPO and GSPO train a model from scores on its sampled answers. Use SFT instead when you already have demonstrations of the answers you want.

When to use it

Use reinforcement learning when you can verify an answer, for example:

  • A final number in a word problem.

  • SQL that returns the expected rows.

  • Code that passes your task’s checks.

If you have ranked pairs instead of a verifier, use DPO.

Prepare your data

Use text chat rows with the prompt and an expected answer your reward can check:

{"messages":[{"role":"system","content":"Solve the problem. End with #### NUMBER."},{"role":"user","content":"A shop has 12 pens and sells 5. How many remain?"},{"role":"assistant","content":"12 - 5 = 7.\n#### 7"}]}

Reinforcement runs do not accept images or prepared token rows. For tools and conversation fields, see Conversations and tools.

For a small first run, the GSM8K example uses 200 training rows and 50 evaluation rows. This checks the workflow and reward signal, rather than producing a useful model.

Register your examples:

akka optimize registry datasets register maths/train -f train.jsonl

Start a run

Create a training project and select a base model that supports your method. Save this plan as run.yaml. It uses a registered scoring bundle to check answers:

kind: run
project: maths
baseModel: Qwen/Qwen3-0.6B
config:
  dataset: maths/train
  method: grpo
  reward:
    terms:
      - kind: rule
        weight: 1.0
        bundle: maths/scoring
        module: reward

Validate the plan, then start training:

akka optimize training runs start -f run.yaml --dry-run
akka optimize training runs start -f run.yaml --wait --exit-status

Set config.method: gspo to use GSPO. Check available methods with akka optimize training base-models get Qwen/Qwen3-0.6B. The GSM8K example supplies a complete dataset, bundle and run plan.

Key parameters

These fields are under config.rlHyperparams:

Field Default Purpose

optimizer.learningRate

0.00001

Peak learning rate.

groupSize

4

Answers sampled per prompt.

promptsPerStep

8

Prompts per update; use a multiple of execution.gpus.

maxCompletionLength

256

Maximum answer length in tokens.

klBeta

0.04

Penalty toward the reference policy; 0 disables it.

temperature

0.7

Sampling temperature; 0 selects greedy sampling.

For training budgets and other fields, see Run plan reference. To start from an SFT adapter, name its model version as source.model, or branch from a snapshot of the SFT run with weights; see Start from existing weights. If a positive KL penalty is refused for that adapter, set klBeta: 0 or train without it.

What to watch

Check these readings with akka optimize training runs metrics RUN_ID and inspect answers with akka optimize training runs rollouts RUN_ID:

  • The FLAT GROUPS column near 100% means the answers in each group receive the same reward and provide no learning signal. Check SCORED NOTHING for all-zero groups. Add a format reward or start from an SFT adapter if every answer scores zero. In JSON output, zeroVarianceGroups gives the flat-group fraction.

  • Reward: check that it improves alongside the quality of sampled answers.

  • Held-out evaluation score: use it to decide whether the trained model improves your task.

Run-to-run variation

A stated config.rlHyperparams.seed fixes the prompt order and a new adapter’s first weights. On a reinforcement run, it does not make rollouts repeatable, so two runs of one plan can finish with very different results. Before promoting a reinforcement candidate on a score difference, read its answers and train the plan more than once where the difference matters.