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.
How reward modeling works
Under the Bradley-Terry model, the probability that responsey⁺ is preferred over y⁻ is:
Key configuration parameters
Training
Training
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.
Data preprocessing
Data preprocessing
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.Model initialization
Model initialization
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:
Using the reward model in an RLHF pipeline
After training, use the reward model as thereward_funcs argument in online RL trainers: