https://rlhfbook.com/book.pdfa

Introduction

  • RLHF is used to incorporate human information into AI systems

Training Overview

RL Context

  • Agent takes action sampled from policy in state to maximize reward
  • Policy maps state to a probability distribution over actions
  • RLHF uses deep reinforcement learning policies - where is a deep neural network
  • Transitions are probabilities from current state + current action to next state with an initial state distribution of
  • Policy and transitions make up a trajectory distribution
  • Trajectories overal probability
    • across finite horizon
  • Goal of RL Agent
    • maximises the future expected reward where determines how far outlooking the agent is
  • indicates the expected return for a policy and indicates the optimal policy.
  • and for well-defined objectives

Training Objective/Loop for RLHF

where

  • is the learned reward/preference model
  • is a frozen snapshot of the policy/model before optimisation
  • influence how close the model is to its starting position

We use the KL-divergence to ensure that the model does not over optimise as we are using a strong prior (the pretrained model)

Differences between RLHF and the standard RL

  1. Uses a reward model
    • Increases flexibility of approach and control for the designer
    • Model is trained on human preferences
  2. No state transitions exist - goes from prompt to answer
  3. Response-level reward and no discounting

Why RL in post-training LMs?

  • Can fix rough edges of the model - making it easy to talk to as an assistant
  • Can be done surgically - RL does not squash the capabilities of the model

Examples of Recipes

  • Instruct GPT - Instruction tuning on 10K examples -> Training a reward model on 100K pairwise prompts -> Training instruction-tuned model with RLHF on a seperate 100K prompts
  • Tulu 3 -> More overall prompts -> On-policy preference data on 1M preference pairs -> RLVR on 10K prompts

Instruction Fine-Tuning

Training a base model to answer in an user/assistant format

Chat template - the format of interaction between user/assistant that the model must conform to

  • Three roles:
    • system - system prompt
    • user
    • assistant

Best practices

  • High quality data
  • Around 1M prompts
  • Similar distribution to downstream tasks of interest
  • Training after instruction tunign allows models to receover from some noise

Implementation details

  • Smaller batch sizes - allows models to optimize to a narrower data distribution whilst preserving models generalization
  • Prompt masking - prompt tokens are masked out so model does not learn to predict the user queries
  • Multi-turn masking
    1. Final turn only - only tokens in final assistant turn is included in the loss
    2. Mask user turn only - all user tokens masked, loss includes all assistant turns
  • Same loss as pretraining
  • Lower learning rate

Reward Modelling

Constructing a model to learn human preferences in prompts

Notation

  • - prompts
  • - completions

Bradley-Terry model of preference - Probability that in a pairwise comparison between two items and , a judge prefers over

  • assumes that each item has
  • often is reperametrized where
- where $\sigma$ is the sigmoid function

Loss function

Reward model is trained on a loss function based on the Bradley-Terry relation. To do so it is given a small linear layer to be able to predict a scalar score.

Given prompt and two sampled completions and , where is the chosen completion and is the rejected one, the loss function per example is

When training language models only one epoch is completed to prevent overfitting.

Outcome Reward Models

Learning a per-token signal of how likely the completion is to end in a correct answer over time

Here we are given a prompt and our inductive bias is that one completion should be correct whereas the others are incorrect, . The ORM is training a per-token predictor of if an answer is correct. The per-token loss function applies the binary cross-entropy at each completion token, where each token’s outcome probability is trained towards the sequence’s outcome label.

where

  • is a completion of tokens
  • - binary label of correctness
  • - probability of correctness predicted at token from model’s scalar logit

Process Reward Models

Reward models trained to output scores at every step in a chain-of-though reasoning process

PRMs is often optimized with a per-step cross-entropy loss: where

  • is a sampled chain-of-thought with annotated steps
  • denotes whether -th step is correct
  • - PRMs predicted probability that step is valid condition on prompt and all previous steps