Skip to main content
Grade an agent’s answers with a plain Python function, then let GRPO train the model to score higher — no preference pairs required. praisonai-train llm adds three RL / preference objectives on top of SFT: grpo (group-relative policy optimisation, scored by your reward functions), reward (train a reward model from preference pairs), and cpo (contrastive preference optimisation, no reference model). Only GRPO needs reward functions — the other two learn from chosen / rejected pairs.

Quick Start

Start with an Agent whose behaviour you want to score, write one function that grades its outputs, then run GRPO on it.
1

Start from an Agent

Pick the behaviour you want to reward — here, concise answers.
2

Write a reward function

TRL calls each reward function as (prompts, completions, **kwargs) and expects one float per completion. Put it in an importable module — e.g. myproject/rewards.py.
3

Point reward_funcs at it and run GRPO

reward_funcs names each callable by its module:function import path. GRPO needs only a prompt column — it generates its own completions.

Which method should I use?


Dataset shapes

Each method fails fast before training if the required columns are missing — the error names both the missing columns and the columns your dataset actually has.
Column: prompt only. GRPO generates its own completions, so no chosen / rejected / completion is needed.

Reward functions

A reward function is a Python callable that scores generated completions. GRPO calls it once per generation batch and uses the returned floats to push the model toward higher-scoring answers.

The module:function convention

A YAML config can only carry a string, so reward_funcs names each callable by a dotted import path — the same module:function form console_scripts and gunicorn use.
A single spec doesn’t have to be a list — reward_funcs: myproject.rewards:length_penalty works too. You can also pass callables directly from the Python API.

The signature TRL expects

One float per completion. Extra columns from your dataset arrive in **kwargs, keyed by column name.

Resolved before the model loads

Every reward path is imported and validated before the multi-gigabyte model loads — a typo costs five seconds, not a lost session.

Why an import path, not a registry?

Two alternatives were considered and deliberately not offered:
A registry populated by @reward means the config can only name functions from a module something else already imported — a worse failure to debug than “no module named X”.
Inline code is an execution surface in a file people paste from the internet. An import path is the only option that can be resolved before anything runs.

Signature check is a warning, not a failure

If a reward function’s signature doesn’t accept completions, the trainer prints a warning and continues — TRL may still call it correctly, and refusing would block working code:
Callables whose signature can’t be read (builtins, C callables) are left to TRL rather than guessed at.

Python API — praisonai_train.rewards

Resolve import paths yourself, or pass callables straight into a config.

GRPO config keys

Three keys apply to GRPO, alongside the shared training keys.

Errors you might see

Each error runs before the model loads and tells the failing part apart, so you know exactly what to fix.
Add at least one module:function path under reward_funcs.
The module isn’t importable — check the name and that its directory is on PYTHONPATH.
The module imported but has no such function; the message lists the callables it does have (up to 8).
Use a colon between module and function: mymod:func, not mymod.func.
The named attribute exists but isn’t callable — point at a function.
resolve_all collects every broken path and raises once with all failures separated by newlines — three fixes in one pass, not three runs.

Best Practices

Put them in a module on PYTHONPATH (e.g. myproject/rewards.py) and keep them side-effect-free. They run once per generation batch, so avoid slow I/O.
List multiple module:function paths — correctness, length, and format compliance as separate functions is easier to tune than one monolithic scorer.
Because paths resolve before the model loads, a bad reward_funcs entry fails in seconds. Fix all reported paths at once — resolve_all lists every failure.
Train a reward model from (chosen, rejected) pairs, then wrap it in a reward function to score GRPO completions later.

praisonai-train Package

The standalone training package and its CLI subcommands.

Train

Full fine-tuning setup and config reference.

Train CLI

Full flag and config-key reference for praisonai train llm.

Multi-GPU Training

Fine-tune across multiple GPUs with torchrun.