In InstructGPT's reinforcement-learning step, each episode is one prompt and one sampled response. The reward model scores the response, a per-token KL penalty keeps the policy near the supervised model, and PPO-ptx also pushes up the log-likelihood of pretraining text. The policy maximises The log-ratio of a response is the sum over its tokens of , and of a pretraining sequence is the sum of its token log-probabilities. Plain "PPO" is the case .
token_rewards(score, logp_rl, logp_sft, beta=0.02)
logp_rl, logp_sft: per-token log-probabilities of one response (same length ). Token gets reward , and the last token also gets the reward-model score. Return the list of floats rounded to 6 decimals.ppo_ptx_objective(scores, logp_rl, logp_sft, pretrain_logp, beta=0.02, gamma=27.8)
scores: reward-model scores; logp_rl[e], logp_sft[e]: token log-probability lists of episode (lengths may differ); pretrain_logp: a list of token log-probability lists, one per pretraining sequence (may be empty)."mean_log_ratio" (mean over episodes of the response log-ratio), "rl_term" (mean of score minus times log-ratio), "ptx_term" (mean over pretraining sequences of their log-likelihood, 0.0 if there are none), "objective" (rl_term + gamma * ptx_term, from unrounded parts).rlhf_settings(iteration, n_episodes=256000): the paper's RL settings. Return a dict: "batch" 512, "minibatch" 64, "minibatches" (batch divided by minibatch), "inner_epochs" 1, "iterations" (n_episodes // batch), "gradient_steps" (iterations times minibatches times inner epochs), "beta" 0.02, "gamma" 27.8, "clip" 0.2, "ema_decay" 0.992, "pretrain_per_minibatch" (8 pretraining sequences per episode), "pretrain_total" (8 per episode over the run), and "lr_scale": the learning rate as a fraction of its peak, warmed up linearly from 0.1 at iteration 0 to 1.0 at iteration 10 and constant after ( below 10), rounded to 10 decimals.
ema_update(ema, params, decay=0.992) returns the exponential moving average of the weights after one update, decay * ema + (1 - decay) * params, as a list of floats rounded to 6 decimals.