Sam Babichenko

Reading notes / Reinforcement learning for reasoning

Tülu 3 post-training recipe

Lambert et al., 2024

Objectives
x;x; yyprompt; response
πθ;\pi_\theta; θ\thetamodel being trained; its weights
πref\pi_{\rm ref}fixed model a stage starts from, the reference of its KL penalty
v(x,y)v(x,y)verifiable reward: α\alpha if the checker accepts yy, else 0
β\betaweight of the KL penalty, in RLVR and in DPO
yc;y_c; yry_rchosen and rejected response of a preference pair
∣y∣|y|length of a response in tokens
m(y);m(y); σ\sigmaβ\beta times the log ratio per token; logistic function
L\mathcal Llength-normalized DPO loss
SFT loss
njn_jnon-padding tokens of sequence jj
ℓj\ell_jsummed next-token loss of sequence jj
Constants
α=10\alpha=10reward of an accepted response in RLVR
−10-10RLVR reward of a response cut off without an end-of-sequence token
β=0.05\beta=0.05KL weight of the final 8B RLVR run
β=5\beta=5weight in the final length-normalized DPO runs (Step 5)
8-gram; 50%; 2%decontamination: match unit; share of a test item's tokens matched; share of an evaluation overlapped (Step 1)

Context. everything done to a pretrained language model to turn it into an assistant: supervised fine-tuning on example responses, preference tuning and reinforcement learning shapes most of what users see in a language model, and by 2024 the strongest recipes were closed, run over several rounds on millions of examples that were never released. Open recipes such as Tülu 2 and Zephyr ran supervised fine-tuning (SFT) and then direct preference optimization: fitting the model to preference pairs with a logistic loss on its log-probability ratios to a fixed reference model, with no reward model and no sampling during training on public preference data, and lagged on math and on following precise instructions. Lambert et al. build a fully open recipe on the Llama 3.1 base models at 8B, 70B and 405B parameters and release its data, code and evaluation. Its stages are prompt curation, SFT, DPO on synthetic preferences, and RL on prompts whose answers a program can check, which they name reinforcement learning with verifiable rewards: RL in which the reward is a fixed positive value when a program confirms the response (an answer match, a constraint check) and 0 otherwise, with no learned reward model: the KL-regularized objective of InstructGPT with the reward model replaced by a checker.

Each stage improves the skills its training signal reaches. SFT on a mix assembled one skill at a time sets most scores. DPO on many distinct prompts, with responses from a pool of models that includes the model being trained, rated by GPT-4o, raises chat quality, math and instruction following. RLVR adds a few points on the skills it checks, measured by grade-school math word problems; a response is correct if its final number matches the answer, competition mathematics problems; the extracted final answer is compared with the reference and prompts carrying constraints a program can check, such as “exactly 3 paragraphs” or “no commas”, from 25 constraint types; the score is the share of prompts whose constraints are all met, and less as the start nears a benchmark's ceiling. Every choice was tuned on the same development benchmarks, so a separate unseen suite, scored only at the end, shows which choices carried over: the math data did, and the synthetic instruction-following data did not.

Setting. Scores are percentages on a the twelve benchmarks used to make every decision in the recipe, with fixed prompts, worked examples and answer extraction, averaged with equal weights. It covers knowledge (multiple-choice questions on school and professional subjects, short factual questions about entities, many of them rare, questions written to invite common misconceptions, scored in multiple-choice form), reasoning (hard reasoning tasks from the BIG-Bench collection, answered with a chain of thought, reading comprehension that needs counting, sorting or arithmetic over a passage), math (MATH, GSM8K), coding (Python functions to complete from a docstring, scored by unit tests; HumanEval+ adds more tests per problem, HumanEval+), instruction following (IFEval, real user requests on which an LLM judge compares the model's answer with GPT-4 Turbo's; the score is the win rate corrected for answer length) and safety (an average of six benchmarks scoring refusal of harmful requests and compliance with harmless ones that look harmful). An unseen suite of seven benchmarks was held back (Step 8). The SFT mix has about 939k prompt-response pairs, the DPO mixes 271k preference pairs at 8B and 334k at 70B, and RLVR about 30k prompts: the GSM8K and MATH training sets, checked by exact match of the final answer, and 15k prompts with IFEval-style constraints, checked by one function per constraint type. Write xx for a prompt, yy for a response, the model being trained, as a distribution πθ(y∣x)\pi_\theta(y|x) over responses; θ\theta are its weights for the policy and the fixed model a stage starts from, used as the reference of its KL penalty for the model the stage starts from. RLVR maximizes the checked reward minus a KL penalty:max⁡πθ Ex[Ey∼πθ(⋅∣x) v(x,y)⏟checked reward−β KL(πθ(⋅∣x) ∥ πref(⋅∣x))⏟KL penalty],\begin{aligned}&\max_{\pi_\theta}\ \mathbb E_{x}\Big[\underbrace{\mathbb E_{y\sim\pi_\theta(\cdot|x)}\,v(x,y)}_{\text{checked reward}}\\&\qquad-\underbrace{\beta\,\mathrm{KL}\big(\pi_\theta(\cdot|x)\,\|\,\pi_{\rm ref}(\cdot|x)\big)}_{\text{KL penalty}}\Big],\end{aligned}with prompts xx from the RLVR set, the verifiable reward: α\alpha if the program checking prompt xx accepts response yy, and 0 otherwise equal to why: set from pilot experiments and not tuned further for an accepted response, and the weight of the KL penalty, which keeps the policy near πref\pi_{\rm ref}; 0.05 in the final 8B run; Step 5 uses the same letter for DPO's version of this weight the penalty weight. The optimizer is proximal policy optimization: policy-gradient RL that clips each update so the policy moves little per step with a a second network trained next to the policy to predict, at each token, the reward still to come; PPO uses its predictions to form per-token advantages.

Main findings (all empirical). At 8B the development average goes from 60.6 after SFT to 64.7 after DPO and 65.1 after RLVR, against 62.9 for Llama 3.1 8B Instruct; at 70B it goes from 72.6 to 76.2 and stays there, against 74.1 for Llama 3.1 70B Instruct. The SFT models have the highest safety scores of any stage (93.1 at 8B). DPO's gains at 8B are concentrated: AlpacaEval 2 from 12.4 to 33.5, MATH from 31.5 to 42.0, GSM8K from 76.2 to 84.3, IFEval from 72.8 to 81.1 and TruthfulQA from 46.8 to 56.1, while safety falls to 87.2 and HumanEval+ from 81.4 to 78.6. RLVR adds 3.3 points on GSM8K, 1.7 on MATH and 1.3 on IFEval at 8B and moves the rest by about a point or less, except safety, down 1.7; at 70B it adds 0.7 on MATH and 0.6 on IFEval and leaves GSM8K at 93.5. At 405B, DPO had lowered MATH from 63.4 to 59.9, and RLVR on MATH alone raised it to 67.3. PPO against a learned reward model came close to DPO and took about 14 times the compute.

Consequences and limits. Choose the skills and a development benchmark or two for each, hold out an unseen benchmark per skill, and decontaminate every training set against both. Build the SFT mix by finding, for each skill, the data that does best on that skill alone, then combine and prune while watching the average. For preferences, collect many distinct prompts, include the model's own responses, have a strong LLM rate them, and train with DPO with each response's log-probability ratio divided by its length in tokens (Step 5). Add RLVR last, on skills with a checker, from the best DPO model, with the value model initialized from a reward model and no reward-model score in the reward; keep the KL penalty from getting small and choose checkpoints on the development suite, since at β=0.01\beta=0.01 the policy learned to pass the constraint checker with no meaningful content (Step 6). The evidence is that of one expensive pipeline: most ablations are single 8B runs with effects of about a point on the average, while the SFT seed alone moved the 70B average between 70.0 and 72.6; RLVR was tried on three checkable skills and with PPO only; and comparisons with closed models cannot rule out that those models trained on the benchmarks.

Step 1

The evaluations are fixed before training, and training prompts are decontaminated by 8-gram overlap. Each development benchmark has one fixed formulation in the released evaluation code, down to the answer extraction, which alone moves scores by more than many effects measured here: on MATH, trying three answer formats in place of one raised reported scores by up to 10 points for models that ignored the examples' format. The unseen suite was designed separately, with prompts written as users write them (no worked examples, an instruction on the answer format), and its scores were not looked at during development. Overlap is measured why: completions in training sets are often regenerated by a language model, so the prompt is what links a training example to a test item: a test token matches a training instance if the two share an 8-gram containing it, and a test instance overlaps when more than half of its tokens match one training instance. Partial matching catches near copies such as a math problem with its numbers changed; embedding similarity could not tell a paraphrase from text on the same topic. A training set overlapping more than 2% of any evaluation's instances counted as contaminated; against the unseen suite such sets were dropped, and against the development suite they were dropped if that cost little and otherwise cleaned instance by instance. Popular sets failed the check: the code-instruction set Evol CodeAlpaca overlaps 70.7% of HumanEval, the math set NuminaMath-TIR 18.2% of MATH, and LMSys Chat 1M, a log of real user chats, 46.5% of AlpacaEval.

Step 2

The SFT mix is assembled one skill at a time, and each targeted source raises its own benchmarks. For each lagging skill the authors first found the data that did best on it alone (an estimate of what the setup could reach), then combined these mixes and added, removed, decontaminated and downsampled sources while tracking the average. Public sets came in for diversity, such as a large public log of real user conversations with chat models; the subset answered by GPT-4 is used, and for specific skills, with licenses traced through each composite dataset. Gaps were filled by prompting GPT-4o to write a problem as a given persona would pose it, such as “a machine learning researcher focused on neural networks”, with about 250k personas to keep the data varied, which produced about 220k math problems, 35k coding problems and 30k prompts with IFEval-style constraints. Removing one source from the final 8B mix lowers its own benchmarks: without the math data GSM8K falls from 76.2 to 64.1 and MATH from 31.5 to 23.5; without the persona data IFEval falls from 72.8 to 53.6; without the safety data the safety average falls from 93.1 to 74.7 while other skills barely move; without WildChat AlpacaEval falls from 12.4 to 7.5. More data helped on average up to the full mix. The base model limits what the mix can do: the same mix gives 56.4 on MATH on Qwen 2.5 Math 7B against 31.5 on Llama 3.1 8B.

Step 3

Summing the token losses in SFT removes a dependence on how batches are split, and at 70B the seed alone moves the average by 2.6 points. Early SFT runs in the authors' code scored below the same runs elsewhere, and the cause was how the loss was averaged. Take a batch of two sequences, with the number of non-padding tokens of sequence jj and the summed next-token loss over the non-padding tokens of sequence jj. One forward pass on both averages over tokens, while gradient accumulation with one sequence per micro-batch averages the per-sequence means:one pass:ℓ1+ℓ2n1+n2,accumulated:12(ℓ1n1+ℓ2n2).\begin{aligned}\text{one pass:}\quad&\frac{\ell_1+\ell_2}{n_1+n_2},\\ \text{accumulated:}\quad&\frac12\Big(\frac{\ell_1}{n_1}+\frac{\ell_2}{n_2}\Big).\end{aligned}The first weights each token equally and the second each sequence equally, so changing the accumulation steps or the number of devices reweights the data. The sum ℓ1+ℓ2\ell_1+\ell_2 gives the same gradient however the batch is split and weights tokens equally, which also scored better on early mixes; the learning rate must be retuned, since the gradient now grows with the tokens per batch. The final runs use learning rates of 5×10−65\times10^{-6} at 8B and 2×10−62\times10^{-6} at 70B for two epochs, and more epochs did not help in a sweep. The seed alone moved the average between 59.8 and 60.1 at 8B and between 70.0 and 72.6 at 70B, and a a model whose weights are the average of the weights of several fine-tuned models with the same starting point of two seeds did not reliably beat the best single seed, so the final SFT models are best single runs.

Step 4

Preference data improves with distinct prompts and with the model's own responses, and the choice of LLM judge hardly matters. The pipeline extends that of a public preference dataset of about 64k prompts, each answered by four models and rated by GPT-4. Each prompt gets four responses from models drawn from a pool of 22, and on a share of prompts one response is the SFT model's own (generated by the model that the stage is about to train, here the SFT model data). GPT-4o rates each from 1 to 5 on helpfulness, instruction following, honesty and truthfulness; the response with the best mean rating is chosen and a random lower-rated one rejected. In ablations at 8B, more distinct prompts raised the scores, while expanding 64k UltraFeedback prompts to 383k pairs by re-pairing each prompt's four responses gave no gain on average. On the same prompts, including the SFT model's responses beat a fully off-policy set. Prompts unused in SFT did slightly better than reused ones, and a mix of both did best. Five judges, from GPT-4o to Llama 3.1 70B, rating the same 10k prompts gave DPO averages between 56.6 and 57.3. The final mix beat DPO on UltraFeedback by 1.8 points at 8B and 3.3 at 70B. Of three persona preference sets, only instruction following helped; in its pairs the rejected response answers a rewrite of the prompt with one constraint relaxed, so it fails the original constraint.

Step 5

Length-normalized DPO was the only preference loss that beat its starting model, and PPO came close to it at about 14 times the compute. DPO's implicit reward for a response, βlog⁡(πθ(y∣x)/πref(y∣x))\beta\log(\htmlData{gr=g15}{\pi_\theta}(y|x)/\pi_{\rm ref}(y|x)), is a sum over tokens, so its size grows with length, and judges tend to prefer longer responses. Length-normalized DPO divides each log ratio by the length the number of tokens in response yy. With the chosen response of a preference pair; yry_r is the rejected one and yry_r the rejected one, and the logistic function σ(z)=1/(1+e−z)\sigma(z)=1/(1+e^{-z}) the logistic function, it minimizesL=−E log⁡σ(m(yc)−m(yr)),m(y)=β∣y∣log⁡πθ(y∣x)πref(y∣x)⏟β × log ratio per token,\begin{aligned}\mathcal L&=-\mathbb E\,\log\sigma\big(m(y_c)-m(y_r)\big),\\ m(y)&=\underbrace{\frac{\htmlData{gr=g19}{\beta}}{|y|}\log\frac{\pi_\theta(y|x)}{\pi_{\rm ref}(y|x)}}_{\beta\ \times\ \text{log ratio per token}},\end{aligned}over preference triples (x,yc,yr)(x,y_c,y_r), with πref\pi_{\rm ref} the SFT model. On UltraFeedback from an early SFT checkpoint averaging 55.7, the best run of each loss scored 57.3 for length-normalized DPO, 55.2 for DPO, 52.9 for a preference loss on length-normalized log-probabilities with no reference model and a fixed target margin between chosen and rejected and 55.5 for PPO against a reward model. The final setting is β=5\beta=5, one epoch, batch 128 and a learning rate of 5×10−75\times10^{-7} at 8B (2×10−72\times10^{-7} at 70B); β\beta is large next to the 0.1 of the plain DPO run presumably because it multiplies the log ratio divided by a length of hundreds of tokens. The result was sensitive to the settings: with three epochs, β=2\beta=2 scored 46.8 against 53.4 at β=5\beta=5, and one epoch in place of three gave 57.3. In a later comparison on the same prompts, PPO with a reward model trained on that mix averaged slightly below DPO and took 28 hours on two nodes against 4 on one, so PPO was kept for RLVR alone.

Step 6

RLVR raises the checked skills, a reward model is the best start for the value model, and adding its score to the reward does not help. The PPO setup follows earlier open PPO work: the value model starts from a reward model trained on general preference data, why: PPO's ratio compares a token's probability at learning with its probability at sampling; dropout makes the two differ before any update, so ratios can be clipped and give no gradient, and the KL estimate is noisy, prompts are reshuffled each epoch, why: to push the policy to finish its responses within the length limit, and advantages are standardized. In ablations from an intermediate DPO model with β\beta between 0.01 and 0.1, training on each of GSM8K, MATH and the constraint prompts raised the training reward and the matching test score, while the average over all benchmarks did not always rise. Initializing the value model from the general reward model gave a better GSM8K score and average than initializing it from the DPO policy. Adding the reward model's score to the checker's did worse on GSM8K and made the average noisier. Starting from the weaker SFT model reached the same training reward at a larger KL, and the stronger start usually tested better. As β\beta fell and the KL grew, the average generally fell; on the constraint prompts at β=0.01\beta=0.01, asked for a pen's length in centimeters with the keywords “timberlike” and “unconnectedly” included, the policy answered “timberlike, unconnectedly”, which passes the checker and says nothing about the pen; at β=0.1\beta=0.1 it estimated 15 to 20 cm.

Step 7

The final RLVR runs choose checkpoints on the development suite, and their gains shrink where a benchmark is near its ceiling. The final runs start from the best DPO models and train on all three prompt sources together. Checkpoints were scored every 100 steps (40 at 70B) and at 8B the one best on MATH and IFEval kept; some 8B runs reached 89.4 on GSM8K and 84.8 on IFEval but did worse elsewhere. At 70B, GSM8K started at 93.5 and did not move, and the KL stayed below 1, which the authors attribute to the learning rate of 10−710^{-7} (a higher one made the KL explode early). At 405B, GSM8K was saturated after DPO and the constraint prompts did not help early on, so RLVR used only MATH, which rose more than 5 points within 25 steps and was still rising when compute ran out at step 75. Generation and training run asynchronously: an open inference engine that serves many generations at once by storing the attention key-value cache in pages generates on dedicated GPUs while the learners update, why: when generation runs ahead of training, how stale the samples are varies from step to step; fixing the lag at one update keeps runs reproducible, and new weights are broadcast after each update. At 405B an iteration took about 550 seconds of generation and 1,500 of training, with an 8B value model to save compute.

Step 8

The unseen suite shows which development choices generalized. Each skill pairs a development and an unseen benchmark: MMLU with very hard multiple-choice questions in biology, physics and chemistry written by domain experts, BigBenchHard with multiple-choice questions from admission and qualification exams such as the SAT and LSAT; the English subset is used, MATH with generated questions in 56 categories of arithmetic, algebra and calculus, with answers compared symbolically, HumanEval with harder Python tasks that call common libraries, scored by unit tests; its hard subset of 148 tasks is used, and IFEval with a new benchmark built like IFEval on unseen WildChat prompts, with 52 constraint types disjoint from IFEval's 25. Averaged over these five pairs, the final models score best on both sides: at 8B, 64.9 on the development benchmarks and 29.9 on the unseen ones after SFT against 68.8 and 32.4 at the end; at 70B, 78.1 and 41.0 against 80.7 and 44.4. Without the math data MATH falls 8.0 points and DeepMind Mathematics 9.0, so that data carried over. Without the persona data IFEval falls from 72.8 to 53.6 while IFEval-OOD moves from 17.6 to 18.0, so that data did not carry over. Every model tested scores far lower on IFEval-OOD than on IFEval (Tülu 3 8B 24.3 against 82.4, Llama 3.1 8B Instruct 26.1 against 80.6), which the authors read as models fitting IFEval's own constraint types. More DPO data raised MATH more than DeepMind Mathematics, which the authors trace to the models writing LaTeX where DeepMind Mathematics does not expect it, which broke answer extraction.

Step 9

Online DPO did not help, and rejection sampling gained little for its compute. DPO on pairs sampled from the current policy during training and labeled by a reward model or judge, in place of a fixed dataset, run for 200k episodes on math prompts with a reward model further trained on math preferences, gave little or no gain on GSM8K and lowered MATH across the temperatures and KL coefficients tried. generating several responses per SFT prompt with the trained model, keeping the one a reward model or judge ranks best, and rerunning the pipeline on the new data gave small gains for its compute; open judges struggled to pick the best candidate, and including the original response among the candidates worked much better than choosing among new ones alone.

Terms

RLVR
maximize E v(x,y)−β KL(πθ∥πref)\mathbb E\,v(x,y)-\beta\,\mathrm{KL}(\pi_\theta\|\pi_{\rm ref}) with v=αv=\alpha if a program accepts the response, else 0; optimized with PPO
Development vs unseen suite
development benchmarks drive every decision; unseen ones, one or two per skill, are scored only at the end to measure overfitting
Decontamination
8-gram matches on prompts; a set is contaminated if it overlaps more than 2% of an evaluation's instances
Skill-by-skill SFT mix
find the best data for each skill alone, then combine and prune while watching the average
Persona-driven synthesis
GPT-4o writes prompts as one of about 250k personas would, to keep synthetic data varied
Sum loss
sum token losses, ℓ1+ℓ2\ell_1+\ell_2, so batch splitting and accumulation do not change how sequences are weighted
Preference pipeline
four responses per prompt from a pool of 22 models plus the SFT model; GPT-4o ratings; highest mean chosen, a lower one rejected
Length-normalized DPO
DPO with each log ratio divided by ∣y∣|y|; β=5\beta=5; the only loss that beat its starting model
Value model from a reward model
best initialization for RLVR's PPO critic; adding the reward model's score to the reward did not help
Checker overoptimization
at β=0.01\beta=0.01 the policy passed constraint checks with no meaningful content; checkpoints are chosen on the development suite
Stage gains at 8B
average 60.6 after SFT, 64.7 after DPO, 65.1 after RLVR; RLVR adds 3.3 on GSM8K, 1.7 on MATH, 1.3 on IFEval
IFEval vs IFEval-OOD
disjoint constraint types; every model scores far lower on the new one, a sign of fitting IFEval itself

Quiz

  1. Why do the final length-normalized DPO runs use β=5\beta=5, when the plain DPO runs of the same sweep used 0.1?
  2. Why is dropout turned off in RLVR's PPO training?
  3. RLVR raised GSM8K by 3.3 points at 8B and left it unchanged at 70B, while at 405B RLVR on MATH alone raised MATH by 7.4 points. What best explains the pattern?

Sources