Training

Pinned sources The Llama 3 Herd of Models (arXiv 2407.21783v3), whose results are all for Llama 3.1 · for Llama 3, its model card (meta‑llama/llama3 @ a0940f9) and Meta’s post of April 2024 · no training code is published

  1. Start of training
  2. Initial pre‑trainingat 4K, then 8K15.6T8KNTPWhat trains: all
  3. Long‑context pre‑trainingsix stages, 8K to 128K800B128KNTPWhat trains: allcontext to 128K
  4. Annealinglearning rate to 040M128KNTPWhat trains: all
  5. Pre-trained model
  6. × 6 roundsRejection sampling and SFTthen DPO, each roundnot stated128KSFTRS and synthetic datanot statednot stated: tokens, what trains
  7. DPOafter SFT, each roundnot statedshort contextDPO+ NLL 0.2not statednot stated: tokens, what trains
  8. Llama 3.1 405B Instruct
  • tokens, log scale
  • NTPdashed: concluded, no source names it
  • not stated by the sources
  • the architecture changes
  • checkpoint
  • checkpoint, weights published
  • a join the sources leave unexplained
  • data from a branch into a stage
  • stages repeated together

DPO

×

Direct preference optimization on the latest preference data, with the formatting tokens masked out of the loss and a negative log-likelihood term on the chosen responses.

DPO, direct preference optimization

From pairs of a preferred and a rejected response, the model is trained to raise the preferred one’s probability, measured against a frozen reference model, more than the rejected one’s, with no separate reward model.

LDPO=−log⁡σ(βlog⁡πθ(yw∣x)πref(yw∣x)−βlog⁡πθ(yl∣x)πref(yl∣x))\begin{aligned}\mathcal L_{\mathrm{DPO}}=-\log\sigma\Big(&\beta\log\frac{\pi_\theta(y_w\mid x)}{\pi_{\mathrm{ref}}(y_w\mid x)}\\&-\beta\log\frac{\pi_\theta(y_l\mid x)}{\pi_{\mathrm{ref}}(y_l\mid x)}\Big)\end{aligned}

DPO paper, eq. 7, for one pair

What the letters mean

ywy_w, yly_l: the preferred and the rejected response to the prompt xx; πθ\pi_\theta: the model being trained; πref\pi_{\mathrm{ref}}: the reference model; σ\sigma: the logistic function; β\beta: how far the model may move from the reference.

Meta’s total: L=LDPO+0.2 LNLL\mathcal L=\mathcal L_{\mathrm{DPO}}+0.2\,\mathcal L_{\mathrm{NLL}}.

Learning rate and β
10⁻⁵; β = 0.1
Rounds
six, each an SFT followed by DPO

Not disclosed Tokens

Why

PPO was explored; DPO required less compute for large models and performed better, especially on instruction following. Llama 3 paper §4.1.4, p. 16

Masking the formatting tokens stabilizes training. The paper hypothesizes that, since they are in both chosen and rejected responses, the contrastive loss would push their likelihood up and down at once. The NLL term keeps the chosen responses’ log probability from falling. Llama 3 paper §4.1.4, p. 16

What the terms meanNLL · SFT · PPO
NLL
Negative log-likelihood: the cross-entropy of a response’s own tokens, as in SFT.
SFT
The model is trained on examples of the answers wanted, prompts with their responses, by the cross-entropy of next-token prediction on the responses.
PPO
Proximal policy optimization: reinforcement learning whose baseline for a response is a learned value model, with each update clipped near the policy that wrote the samples. GRPO keeps the clip and takes the group’s mean reward as the baseline.
All settings8
Rounds
Six rounds, each an SFT followed by DPO. Each round’s data are generated with the best models of the previous round: “Best model for next round” (Figure 7), “sampling synthetic data from the latest models”. The paper says SFT fine-tunes pre-trained checkpoints; that a round starts from the previous round’s model is not stated.
Objective
DPO, with the formatting tokens masked out of the loss in chosen and rejected responses, and an NLL term with coefficient 0.2 on the chosen sequences
Learning rate and β
10⁻⁵; β = 0.1
Data
Mostly the latest batches of preference data, collected with the best models of the previous rounds; only samples labelled significantly better or better
Context
Short-context data only, on top of the long-context SFT checkpoints
Steps
Fewer optimizer steps than SFT
Model averaging
Models from experiments with various data or hyperparameters are averaged at each RM, SFT and DPO stage
Against PPO
PPO was explored; DPO “required less compute for large-scale models and performed better”
Sources4