Post-training

Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8

51 cards

Introduction

  1. In what two ways are pretrained-only LLMs insufficiently helpful?
    They aren’t good at following instructions (asked how to steal from a store, a base model may just generate a related question), and they aren’t always good at complex problem solving that needs long chains of reasoning.
  2. Why are pretrained-only LLMs also potentially harmful?
    Pretraining doesn’t make them safe: they can attack users, suggest harmful actions, or give dangerously false answers (e.g. medical).
  3. What is the underlying reason LLMs are too harmful and insufficiently helpful after pretraining?
    The pretraining objective (predicting words in text) is misaligned with the human need for models to be helpful and non-harmful.
  4. What are the three stages of post-training?
    (1) Instruction tuning (SFT): fine-tuning on instructions and responses. (2) Preference alignment (e.g. RLHF, DPO): using a model of human preferences to fine-tune the model. (3) RL with verifiable rewards (RLVR): training on tasks with clear right answers, like math or programming, to solve multi-step problems.
  5. What is a base model?
    A model that has been pretrained but hasn’t yet gone through any post-training steps.

8.1 Instruction tuning

  1. What is instruction tuning, and what does the model learn beyond the training tasks?
    Fine-tuning a base LLM on a corpus of instructions and responses for many tasks (translation, meal planning…). Beyond those tasks it learns to follow instructions in general, a form of meta-learning.
  2. What objective and which tokens are used in instruction tuning?
    The same language-modeling cross-entropy objective as pretraining, but trained only on the response: the instruction is the conditioning context, and the model predicts the response tokens one by one.
  3. Why is instruction tuning called supervised fine-tuning, though it uses next-token prediction?
    Unlike pretraining text, each instruction comes with a supervised target: a correct answer or response.
  4. What is fine-tuning in general?
    Taking a fully pretrained model and running additional training passes with cross-entropy loss on new data, adapting all or only some of the parameters.
  5. How much data does instruction tuning need compared to pretraining?
    Much less: several epochs over instruction datasets of at most millions of examples rather than trillions of tokens, so it costs a small fraction of pretraining.
  6. What kinds of content can instructions contain?
    Anything: code to write, questions to answer, translations, writing tasks, shopping lists; with parts like length restrictions, personas to assume, and demonstrations.
  7. What instruction-tuning datasets exist?
    Aya (multilingual, many tasks, partly written by volunteer fluent speakers of many languages), Super-NaturalInstructions, Flan 2022, OPT-IML, Alpaca.
  8. Why use existing NLP datasets to create instruction data, and how?
    Writing high-quality instructions by hand is slow and costly. Fields of existing datasets (e.g. SQuAD QA, NLI premise/hypothesis/label, sentiment text/label) are extracted as key/value pairs and inserted into instruction templates, often paraphrased by LLMs for diversity.
  9. Give an example of an instruction template built from an NLI dataset.
    “Suppose {{premise}} Can we infer that {{hypothesis}}? Yes, no, or maybe?”, with the dataset’s label as the target response.
  10. What is the most common way to generate instruction-tuning data today?
    Having language models write it, based on various datasets.
  11. How can instruction data make models safer, and how much is needed?
    Take harmful questions, have an LLM paraphrase them and write safe refusals, review them manually, and add them to the instruction data. Even a few hundred safety instructions mixed into a large dataset substantially reduce harmfulness.
  12. How can annotation guidelines written for crowdworkers be reused?
    As prompts to an LLM to generate instruction-tuning examples for that task.
  13. How are instruction-tuned models evaluated, and why with task clusters?
    Since the goal is following instructions in general, they are tested on held-out tasks (leave-one-out). Many datasets are near-duplicates of a task, so datasets are grouped into clusters by task similarity and a whole cluster (e.g. all sentiment datasets) is withheld.

8.2 Parameter-efficient fine-tuning

  1. Besides instruction tuning, when might we fine-tune a pretrained model?
    To adapt it to a new task, domain (legal, medical) or language/variety whose data wasn’t sufficiently represented in pretraining.
  2. Why is it hard to fine-tune all the parameters of very large LMs?
    Every batch must backpropagate through enormous numbers of parameters in many huge layers, which is very expensive in compute, memory and time; many labs can’t do it.
  3. What is parameter-efficient fine-tuning (PEFT)?
    Fine-tuning that freezes most parameters and updates only a small chosen subset.
  4. What is the intuition of LoRA?
    Low-Rank Adaptation: freeze the dense weight matrices (e.g. \(W^Q, W^K, W^V, W^O\)) and instead learn a low-rank update with far fewer parameters.
  5. How does LoRA update a frozen matrix \(W\) of shape \([k \times d]\)?
    It learns \(A\) \([k \times r]\) and \(B\) \([r \times d]\) with \(r \ll \min(d, k)\), replacing \(W + \Delta W\) by \(W + AB\). The forward pass becomes \(h = xW + xAB\).
    W (frozen)k × d+Ak × r×Br × donly A, B trained
    With small r, A and B have far fewer parameters than W.
  6. What are the advantages of LoRA?
    Much lower hardware requirements (no gradients for most parameters); no extra inference time, since \(AB\) has the shape of \(W\) and can be added into it; and modules for different domains can be swapped in and out by adding or subtracting them.
  7. To which matrices was LoRA originally applied?
    Only the attention matrices: \(W^Q, W^K, W^V, W^O\). Many variants exist.

8.3 Learning from preferences

  1. What problems can remain after instruction tuning that preference learning addresses?
    Hallucinations, unsafe or harmful outputs, and responses that are technically correct but not as helpful as they could be; it targets qualities like honesty, helpfulness and harmlessness.
  2. Why are preference judgments easier to obtain than instructions?
    They don’t require knowing how to do something, only an opinion about the result. People can express preferences about outputs even with no expertise in producing them.
  3. What forms do preference judgments take?
    Picking the better of a pair, selecting one from a set, ranking a set of possibilities, or accepting/rejecting an option in isolation.
  4. What does LLM preference data consist of, and how is a preference written?
    A prompt \(x\) with several outputs \(o\) sampled from an LLM, and judgments such as \((o_i \succ o_j \mid x)\): \(o_i\) is preferred to \(o_j\) given \(x\).
  5. How many preference pairs does a ranking of \(N\) outputs give, and how many does choosing one best of \(N\) give?
    A full ranking of \(N\) outputs gives \(\binom{N}{2}\) pairs (e.g. 6 for 4 outputs); selecting the single best gives \(N - 1\) pairs.
  6. What are the three sources of preference data for LLM alignment?
    Human annotator judgments, implicit preferences extracted from online resources, and fully synthetic preferences from LLMs acting as annotators.
  7. How can social media provide implicit preference data?
    On sites like Reddit or StackExchange, a post serves as the prompt and the responses as sampled outputs; accumulated user votes rank the responses, which can be turned into preference pairs.
  8. How are synthetic preference datasets like UltraFeedback created?
    Outputs for each prompt are generated by a diverse set of LLMs, and a strong LLM (e.g. GPT-4) ranks them.
  9. What are aspect-based scalar judgments, and what is their advantage?
    Annotators (human or LLM) rate each output on a Likert scale along dimensions like helpfulness, honesty, correctness, complexity and verbosity. Pairs can be derived per dimension or from averages, avoiding costly pairwise comparisons.
  10. What is the Bradley-Terry model of preferences?
    Each item has a hidden scalar score; the probability that \(o_i\) is preferred to \(o_j\) is the sigmoid of the score difference: \(P(o_i \succ o_j \mid x) = \sigma(z_i - z_j)\).
  11. Why is the Bradley-Terry formulation convenient?
    Tiny score differences give probabilities near 0.5 (weak or no preference), larger differences quickly approach 0 or 1, and the sigmoid’s derivative allows learning with a binary cross-entropy loss. The score difference is interpreted as the log odds of the preference.
  12. How is a reward model trained from preference data?
    Learn \(r(x, o)\) that gives the scores in Bradley-Terry, minimizing \(-\log\sigma(r(x, o_w) - r(x, o_l))\) over pairs of preferred (winner) and dispreferred (loser) outputs, averaged over the preference dataset.
  13. How is a reward model typically built?
    Initialize it from a pretrained LLM, remove the language modeling head, and replace it with a single dense linear layer that outputs a scalar; train with the Bradley-Terry loss.
  14. Besides alignment, what are reward models used for?
    Best-of-N sampling (picking the preferred response among several sampled ones) and selecting data for instruction tuning.

8.4 Alignment via preference-based learning

  1. How do the elements of reinforcement learning map onto LLM alignment?
    RLLLM alignment
    actionchoice of the next token
    statecontext: tokens generated so far
    policy \(\pi\)the language model
    rewardscore from a reward model learned from preferences
  2. What objective does preference-based RL alignment optimize, in its simplest form?
    Find the policy that maximizes expected reward of its own outputs: \(\pi^* = \arg\max_{\pi_\theta}\mathbb{E}_{x \sim D,\, o \sim \pi_\theta(o \mid x)}[r(x, o)]\).
  3. What are two key differences between traditional RL and RL for LLM alignment?
    (1) The reward comes not from the environment (win or lose) but from a learned reward model, a noisy surrogate for the true reward. (2) Learning starts not from a random policy but from a strong pretrained, instruction-tuned model that should only be nudged toward preferred behavior.
  4. Why is a KL-divergence penalty added to the alignment objective?
    Optimizing only for reward on a small amount of preference data would make the model forget what it learned in pretraining. The penalty \(\beta D_{KL}[\pi_\theta \,\|\, \pi_{ref}]\) keeps the trained policy close to the reference (starting) model.
  5. Write the KL-constrained alignment objective.
    \(\pi^* = \arg\max_{\pi_\theta}\mathbb{E}\big[r(x, o) - \beta\log\frac{\pi_\theta(o \mid x)}{\pi_{ref}(o \mid x)}\big]\), where \(\beta\) controls the strength of the penalty.
  6. What does KL divergence measure?
    A distance between two probability distributions; for LLM policies, the log of the ratio of the trained policy’s probability to the reference policy’s.
  7. What are the two approaches to aligning LLMs with this objective?
    Train an explicit reward model and optimize the policy with RL (e.g. PPO), or rearrange the closed-form solution to fine-tune directly from preference data (DPO).
  8. What is Direct Preference Optimization (DPO)?
    A method (Rafailov et al., 2023) that optimizes an LLM directly on preference data with gradient descent, without learning an explicit reward model or sampling from the model being trained.
  9. What is the key insight of DPO?
    Rewrite the closed-form optimum of the KL-constrained objective so the reward is expressed through policies: \(r(x, o) = \beta\log\frac{\pi(o \mid x)}{\pi_{ref}(o \mid x)} + \beta\log Z(x)\). In the Bradley-Terry difference of two rewards, the intractable partition function \(Z(x)\) cancels.
  10. Write the DPO loss for one preference pair.
    \(L_{DPO} = -\log\sigma\Big(\beta\log\frac{\pi_\theta(o_w \mid x)}{\pi_{ref}(o_w \mid x)} - \beta\log\frac{\pi_\theta(o_l \mid x)}{\pi_{ref}(o_l \mid x)}\Big)\)
  11. What does the DPO update do, intuitively?
    It increases the likelihood of preferred outputs and decreases that of dispreferred ones, relative to the reference model, while the KL term (via \(\beta\), typically 0.01–0.1) keeps it from straying too far.
  12. What are the advantages of DPO over PPO?
    No explicit reward model to train; it learns directly from the preference dataset without expensive online sampling from the policy; and it keeps only 2 LLMs in memory during training instead of 4.

Source