Skip to main content

πŸ“ Post-Training

Description​

< What is it? >​

  • [The idea]

    • Pre-training produces a base model β†’ builds KNOWLEDGE
      It makes the model a next-token predictor that has absorbed an enormous text corpus. It can continue any document, but it does not answer questions, follow instructions, hold a format, reason step by step, or decline anything β€” those behaviours were never the objective.
    • Post-training produces an instruct model β†’ teaches BEHAVIOR
      It is everything done to that base model afterwards to turn it into a usable assistant. Same architecture, same weights being updated by the same gradient descent β€” only the data and the objective change.
      • Historically post-training used a tiny fraction of pretraining's compute. That is no longer safe to assume: RL-heavy reasoning training has grown into a major cost centre of its own.
    • Fine-tuning creates a specialist model β†’ creates EXPERTISE
  • [Base vs instruct, concretely]

    prompt: "What is the capital of France?"

    base model β†’ " What is the capital of Germany?
    What is the capital of Italy? …" (it continues the document)

    instruct model β†’ "Paris." (it answers)
    • The instruct model is not more knowledgeable. It has been taught which behaviour the prompt is asking for.
  • [The stages]

    StageDataObjectiveWhat it buys
    PretrainingTrillions of tokens, unlabelledNext-token predictionKnowledge, grammar, latent skills
    Mid-trainingCurated domain / long-context dataNext-token predictionDomain depth, longer context, code
    SFT10³–10⁢ promptβ†’response pairsNext-token prediction on responsesInstruction following, format, tone
    Preference optimizationHuman/AI comparisonsRLHF, DPO and relativesHelpfulness, style, refusal behaviour
    RLVRProblems with checkable answersRL against a verifierReasoning, math, code correctness
    DistillationTeacher outputsMatch the teacherA small model that behaves like a large one
    • The stages are cumulative and ordered β€” preference optimization on a model that has not been through SFT has almost nothing sensible to rank.

< Supervised fine-tuning (SFT) >​

  • Ordinary supervised learning: promptβ†’response pairs, cross-entropy loss, backprop. The one twist is loss masking β€” the loss is computed on the response tokens only. Training the model to predict the user's own prompt teaches it to imagine questions, not to answer them.
  • Data quality dominates quantity. A few thousand carefully written, consistently formatted examples routinely beat hundreds of thousands of scraped ones; the LIMA result is the canonical demonstration. SFT is teaching behaviour, and behaviour is learned from consistency.
  • The chat template is part of the model. Special tokens and role markers used in training must be reproduced byte-for-byte at inference. A mismatched template is the same class of bug as a mismatched scaler in data normalization β€” the model silently receives something it never saw in training.
  • Catastrophic forgetting is real: narrow fine-tuning data degrades unrelated capabilities. Mix in general instruction data, keep learning rates small, and keep epochs few.

< Learning from preferences >​

  • [Why preferences and not more SFT]

    • For open-ended questions there is no single correct response to imitate, and SFT can only imitate. Humans are also far more reliable at comparing two answers than at writing the ideal one. So the signal is collected as pairs: given a prompt, which response is better?
  • [RLHF β€” the classic three-step pipeline]

    1. Collect comparisons. Sample two or more responses per prompt; annotators pick the winner y_w over the loser y_l.

    2. Fit a reward model. A copy of the model with a scalar head, trained under the Bradley–Terry assumption that the probability of preferring one response is a sigmoid of the reward difference:

      P(yw≻yl∣x)=σ ⁣(rΟ•(x,yw)βˆ’rΟ•(x,yl))P(y_w \succ y_l \mid x)=\sigma\!\left(r_\phi(x,y_w)-r_\phi(x,y_l)\right)
    3. Optimize the policy against that reward with PPO, held near the SFT model by a KL penalty:

      maxβ‘Ο€ΞΈβ€…β€ŠEx∼D,β€…β€ŠyβˆΌΟ€ΞΈ(β‹…βˆ£x)[rΟ•(x,y)]βˆ’Ξ²β€‰KL ⁣[πθ(y∣x) βˆ₯ πref(y∣x)]\max_{\pi_\theta}\; \mathbb{E}_{x\sim D,\; y\sim\pi_\theta(\cdot\mid x)}\left[r_\phi(x,y)\right] -\beta\,\mathrm{KL}\!\left[\pi_\theta(y\mid x)\,\|\,\pi_{\mathrm{ref}}(y\mid x)\right]
    • The KL term is the whole safety net. Without it the policy walks off to whatever gibberish maximizes an imperfect reward model β€” reward hacking, the defining failure of RLHF. Ξ² trades alignment against staying coherent, and is exactly a regularization strength: it pulls the policy back toward a reference rather than toward zero.
  • [DPO β€” the same thing without the reward model]

    • Direct Preference Optimization rewrites the constrained RL problem in closed form, so the reward model and the RL loop both disappear and preference pairs become a single classification loss:

      LDPO=βˆ’β€‰E(x,yw,yl)∼D[log⁑σ ⁣(Ξ²log⁑πθ(yw∣x)Ο€ref(yw∣x)βˆ’Ξ²log⁑πθ(yl∣x)Ο€ref(yl∣x))]\mathcal{L}_{\mathrm{DPO}}=-\,\mathbb{E}_{(x,y_w,y_l)\sim D} \left[\log\sigma\!\left( \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)} \right)\right]
    • Far simpler and cheaper β€” two models in memory instead of four, no sampling loop. The cost is that it learns only from the fixed offline dataset, whereas online RL keeps generating fresh responses to be judged.

< RL with verifiable rewards (RLVR) >​

  • When the answer can be checked β€” a unit test passes, a math result matches, a program compiles β€” the reward needs no human and no learned reward model, so there is nothing to hack. That removes the ceiling on how long the model can be trained.
  • This is the mechanism behind reasoning models: rewarded for reaching correct answers, the model learns to spend more tokens thinking before committing, and long chains of thought emerge from the incentive rather than from imitation.
  • GRPO is the workhorse algorithm here β€” it samples a group of responses per prompt and uses their mean reward as the baseline, dropping PPO's separate value network.
  • The limit is scope: it only applies where a verifier exists. Taste, tone and safety still need human or AI preferences.

Key points​

< Full fine-tuning vs PEFT >​

MethodTrainable paramsMemoryUse when
Full fine-tuning100%Highest β€” weights + gradients + optimizer stateYou have the compute and want maximum quality
LoRA~0.1–1% (low-rank adapters)Much lower; base weights frozenThe default for most teams. Adapters swap at serve time
QLoRASame as LoRALowest β€” 4-bit frozen baseSingle-GPU fine-tuning of a large model
Prompt / prefix tuningTinyMinimalLight task steering; weaker than LoRA in practice
  • LoRA's real operational win is many variants, one base: dozens of adapters can be served against a single set of frozen weights.

< Prompt vs RAG vs post-train >​

NeedReach forWhy
Different wording, format, or a rolePrompt engineeringInstant, free, reversible. Always try first
The model lacks factsRAGKnowledge should be retrieved, not baked in β€” it changes
The model lacks a behaviour or a house styleSFTBehaviour is what fine-tuning actually teaches
Rankable quality with no single right answerPreference optimizationComparisons carry signal that imitation cannot
Checkable correctness at high volumeRLVRA verifier gives unlimited, unhackable reward
Lower latency/cost at similar qualityDistillationMove the behaviour into a smaller model
  • Fine-tuning to inject facts is the most common expensive mistake: it is a poor way to store knowledge, and the knowledge goes stale in the weights where you cannot update or cite it.

< Data is the product >​

  • Annotator agreement is the ceiling on reward-model quality. If two humans disagree on which response is better, no model can learn the difference β€” write the guidelines first.
  • Synthetic data works, but only with filtering. Generate broadly, then verify, deduplicate and rank. Unfiltered model-generated data narrows diversity with every round.
  • Check for contamination: benchmark items leaking into training data produce a model that scores well and behaves no better.

< Evaluating a post-trained model >​

  • Pairwise win rate against the previous checkpoint is the standard headline metric β€” usually via an LLM judge, which is fast and cheap but biased toward longer, more confident, and self-authored answers. Calibrate against human judgement periodically; never let a judge be the only signal.
  • Track a capability suite alongside it. Alignment work can quietly cost accuracy elsewhere β€” the alignment tax β€” and a win-rate-only dashboard will not show it.
  • Evaluate refusals in both directions. Over-refusal on benign requests is a real failure, not a safe default, and it is the predictable overshoot of harmlessness training.

< Failure modes >​

SymptomCauseFix
Sycophancy β€” agrees with whatever the user assertsAnnotators preferred agreeable answersPreference data that rewards correct disagreement
Verbosity β€” long, padded, list-everything answersLength correlates with human and judge preferenceLength-control terms; penalize in the reward
Mode collapse β€” every answer sounds identicalOver-optimized against the reward; KL too weakRaise Ξ², fewer RL steps, more diverse prompts
Reward hacking β€” high reward, useless outputReward model exploited off-distributionStronger KL, fresh preference data, cap training steps
Catastrophic forgettingNarrow SFT dataMix in general data, lower LR, fewer epochs
Format brittleness β€” breaks on a slightly different promptTemplates too uniform in trainingVary phrasing and system prompts in the SFT set
Over-refusalHarmlessness signal overshotAdd benign-but-adjacent examples that should be answered

< Practical hyperparameters >​

  • Learning rates are far smaller than pretraining: roughly 1e-5–2e-5 for full SFT, 1e-4–3e-4 for LoRA. Too large and the model forgets; too small and nothing moves.
  • 1–3 epochs. SFT sets are small and memorize fast β€” a rising validation loss with a still-falling training loss is ordinary overfitting, and the response is early stopping, not a bigger run.
  • AdamW with cosine decay and a short warmup is the standard recipe (see Gradient Descent).
  • Read samples by hand every run. Post-training failures are behavioural, and loss curves do not show sycophancy.

Crash course​

Reference​