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.- GRPO
- Reward
- CPO
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.
reward_funcs: myproject.rewards:length_penalty works too. You can also pass callables directly from the Python API.
The signature TRL expects
**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 decorator registry
A decorator registry
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 Python in YAML
Inline Python in YAML
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 acceptcompletions, the trainer prints a warning and continues — TRL may still call it correctly, and refusing would block working code:
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.Missing reward functions for GRPO
Missing reward functions for GRPO
module:function path under reward_funcs.Module can't be imported
Module can't be imported
PYTHONPATH.Attribute not found (with 'did you mean')
Attribute not found (with 'did you mean')
Malformed spec (dot instead of colon)
Malformed spec (dot instead of colon)
mymod:func, not mymod.func.Not a callable
Not a callable
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
Keep reward functions importable and pure
Keep reward functions importable and pure
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.Combine several small rewards
Combine several small rewards
List multiple
module:function paths — correctness, length, and format compliance as separate functions is easier to tune than one monolithic scorer.Dry-run to catch typos early
Dry-run to catch typos early
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.Use reward modelling to bootstrap GRPO
Use reward modelling to bootstrap GRPO
Train a
reward model from (chosen, rejected) pairs, then wrap it in a reward function to score GRPO completions later.Related
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.

