Skip to main content

Overview

Reward models (RMs) are trained to assign scalar scores to model outputs, reflecting how well a response aligns with human preferences. A well-trained reward model can then be used to guide online RL methods (such as PPO, GRPO, or RLOO) or to evaluate model outputs at inference time. RewardTrainer trains a AutoModelForSequenceClassification model (with num_labels=1) on a preference dataset using a Bradley-Terry pairwise ranking objective. The model learns to assign higher scores to preferred responses than to rejected ones.

Quick start

Dataset format

RewardTrainer requires a preference dataset with chosen and rejected fields. An optional prompt field is supported. Both standard and conversational formats are accepted.
To convert from a different format:

How reward modeling works

Under the Bradley-Terry model, the probability that response y⁺ is preferred over y⁻ is:
The reward model is trained with the negative log-likelihood of observed preferences:
The Bradley-Terry model is underdetermined — adding a constant to all rewards does not change preference probabilities. Use center_rewards_coefficient to encourage mean-zero rewards, which helps with reward hacking.

Key configuration parameters

float | None
Coefficient for an auxiliary loss term that encourages the model to output mean-zero rewards. Recommended value: 0.01. Addresses the underdetermination of the Bradley-Terry model.
bool
default:"false"
Offload activations to CPU to reduce GPU memory usage.
bool
default:"true"
Disable dropout in the model during training. Recommended to improve consistency of reward estimates.
int | None
default:"1024"
Maximum tokenized sequence length. Samples where either chosen or rejected exceeds this length are filtered out.
str | None
Token used to indicate end of sequence. Defaults to the tokenizer’s eos_token.
str | None
Token used for padding. Defaults to processing_class.pad_token, falling back to eos_token.
dict | None
Keyword arguments forwarded to AutoModelForSequenceClassification.from_pretrained when the model argument is a string. Note: num_labels is always set to 1 automatically and cannot be overridden here.
str | None
Path to a tokenizer or Jinja template file to set as the model’s chat template.
RewardConfig overrides some TrainingArguments defaults: logging_steps=10, gradient_checkpointing=True, bf16=True, and learning_rate=1e-4.

Training with PEFT/LoRA

When fine-tuning a base causal LM as a reward model using LoRA, include the classification head (score) in modules_to_save:
When training a reward model adapter on a base causal LM (not a sequence classification model), you must include "score" in modules_to_save. This ensures the classification head is trained and saved alongside the adapter.
To continue training an existing PEFT reward model:
When training reward model adapters, use a higher learning rate (around 1e-3) since only new parameters are being learned.

Using the reward model in an RLHF pipeline

After training, use the reward model as the reward_funcs argument in online RL trainers:
You can also combine a trained reward model with custom reward functions to create a hybrid reward signal.

Logged metrics