Home/AI/ML Notes/GenAI and LLMs Summary/LLM Training: Pretraining, SFT & RLHF
⌂ Main Page
GenAI and LLMs Summary

LLM Training: Pretraining, SFT & RLHF

Unsupervised pretraining, supervised fine-tuning, RLHF, rejection sampling, PPO, and the advantage function.

On this page

Unsupervised phase - pre-training on large corpus of unlabeled text = learning general-purpose representations via self-supervised learning - next token prediction.

Supervised alignment phase

To better align to end tasks and user preferences. Superficial Alignment Hypothesis (SAH) = most knowledge is learned during pre-training, while alignment refines the delivery format.

Rejection sampling – LLM

Proximal policy optimization (RL)

Trains agent to learn how to act in an env. in order to maximize reward (by OpenAI).

  1. Adjusts policy (agent’s strategy) by gradient ascent to maximize the reward.

  2. Clipped policy gradient objective - prevents large updates - more stable and reliable improvement.

  3. Actor-Critic Method: 'actor' updates policy based on feedback from 'critic' which evaluates the policy.

  4. Multiple Epochs per Update: runs through data multiple times (epochs) - better sample efficiency.

RLFH PPO requires 4 models in memory simultaneously: 1) Reward Model for human preferences: fitted & frozen, provides scalar reward, 2) Policy Model (Actor): being trained to maximize reward for predicting the token sequence, but making sure it is not too far from original reference model => 3) Reference Model: frozen SFT model used for KL divergence penalty to prevent reward hacking (when LLM learns to output garbage that is rewarded highly like emojis or backslashes) 4) Value func./model (aka Critic): Terminology disambig. - The value function V(s) is a math object: given a state (prompt + tokens generated so far), it estimates the expected total future reward, if generation continues under the current policy, to reduce variance during training => stabilize training. The value model (small regression head attached to the policy, trained jointly with it) is a neural net that implements the value function. Critic is just the actor-critic name for it.

PPO relies on "Advantage" - measures how better specific action (token) is vs. avg. expected action = difference betw. actual return and value predicted by Critic (in a simple case when lambda = 1 - close to reality). Return = discounted sum of all future rewards.

Two PPO methods: a) PPO-Clip (Clipped Surrogate Objective) - prevents new policy from deviating far from old one in a single update, clipping by ε [1-ε, 1+ε] (typically ε=0.2): de facto PPO standard due to its simplicity and strong empirical performance; b) PPO-KL - adds dynamic KL-divergence term to objective function to penalize large deviation of new policy from the old one (dynamic - if KL divergence too high, the coefficient increases to enforce stronger constraints; if too low, the coefficient decreases to allow larger updates). KL divergence - measure of how far two proba distributions are from each other.