Course · Post-training: SFT, LoRA, reward models and RLHFPhase 18 · Study guide

Which parameters and signals change during adaptation?

Training Systems · Local CPULaptop CPU5 lessons (~8.8h)

Revision v0.18.1 ·

A pretrained model can be adapted with demonstrations, low-rank updates or preference evidence, but these methods ask different questions of the data. Response-only SFT scores demonstrated tokens; LoRA restricts which parameter changes are available; reward learning and preference objectives use comparisons between alternatives. Keep the base, reference, behavior policy and reward model identities separate as you follow a concrete example through each objective. Derive the scored positions and likelihood reductions before comparing curves. The PPO route needs its RL preparation, while DPO follows its own reference-scoring branch; shared bookkeeping does not make the algorithms interchangeable.

Preparation: Self-supervised pretraining: masked and contrastive learning

Runtime: Executed CPU synthetic objectives; large-scale and human-feedback evaluation remain separate

Check your starting point

Should response-only loss remove prompt tokens from the model context?

Compare your reasoning

No. Prompt inputs remain visible under the causal attention contract; the shifted response mask controls which targets receive loss. The PPO branch additionally requires the declared RL lessons. Test your readiness by explaining why old behavior log probabilities stay frozen during multiple optimizer epochs. SFT, LoRA and DPO can be studied without taking that branch.

If this is unfamiliar, work through Supervised fine-tuning with response-only token loss before attempting the project.

Build in stages

1. Supervised fine-tuning with response-only token loss

Write an input/next-target/role table, audit ragged likelihood sums, identify supervised positions in the gradient map, and demonstrate a context distinction the transition model cannot represent.

2. LoRA: adapt, save and merge low-rank updates

Derive and check both adapter-factor gradients, explain asymmetric initialization, verify nonunit merge scaling, and calculate a rank-one capacity limit before interpreting the adaptation curve.

3. Learn a reward model from pairwise preferences

Derive preference likelihood and its linear gradient, inspect contradictory labels, distinguish offsets from scale, and explain the measured comparison margins before handing off a reward model.

4. RLHF mechanics: a frozen reward and PPO policy updates

First complete rl-01 through rl-04. Explain which mask stops reset leakage, how a frozen behavior log probability differs from the current policy, and which unit is an evaluation replicate. Then identify current, behavior, reference and reward states; work both clipping signs and verify the small bandit against its exact optimum. The optional saved-decoder appendix remains a separate mechanics/replay result with a failed quality gate.

5. Direct preference optimization and reference-corrected margins

Work through reference correction and its gradient, reproduce a falling chosen-probability counterexample, and explain why positive margins do not by themselves prove improved response behavior.

Try a changed condition

Make a prediction before opening the reasoning. Keep your answer and the evidence you would collect.

A preference update changes chosen/rejected log probabilities from (−2,−3)(-2,-3) to (−3,−5)(-3,-5), with the reference fixed. Did the chosen absolute probability increase?

Compare an approach

No. The log-probability margin improves from 1 to 2 while the chosen probability falls. DPO compares reference-corrected relative likelihoods. Record chosen, rejected and margin values separately, and use independent task/retention evaluation before calling the model better.

Diagnose a likely failure

Symptom: A PPO ratio is always one during multiple optimizer epochs.

Check next: Check whether old log probabilities are incorrectly recomputed from the changing policy.

Decide what is ready

Complete stages 4–8 of training-methods. Retain shifted token-mask checks, frozen-base/merge evidence, preference oracles, signed PPO clipping and fixed-reference DPO comparisons. Add the new lesson evidence: ragged likelihood oracle, rank-capacity counterexample, conflicting preferences, exact bandit optimum and a DPO ratio improvement with lower chosen probability. State which model integrations remain absent. Complete the saved-decoder SFT and sequence-scoring handoffs with a frozen reference, held-out preference/disagreement cases and source retention. Use the full course workspace for the pinned inference package and tokenizer. Enforce the LoRA base manifest on reload.

Where to put your project code

Write your code in: projects/posttraining-audit/starter/model.py (copy projects/posttraining-audit/starter/model.py first: cp projects/posttraining-audit/starter/model.py projects/posttraining-audit/starter/model.py).

Verify your implementation: python3 projects/posttraining-audit/tests/check.py --stage all --impl projects/posttraining-audit/starter/model.py

Run the staged project checks on your implementation in projects/posttraining-audit/starter/model.py and record your transfer experiment results in your portfolio.

Open Audit SFT, DPO and sequence PPO

Open Audit pretraining and post-training objectives

What still needs further work

The PPO lesson uses a terminal synthetic preference bandit. The optional, registered project Stage 5 table-policy exercise adds a separate synthetic sequence PPO exercise with a learned table critic and a declared deterministic continuation target at the collection boundary. The optional saved-decoder appendix demonstrates bounded sequence-PPO mechanics and replay, but its strict heldout reward quality floor failed; this is not evidence of language-model quality. Keep it separate from registered Stage 5. Neither exercise is full language-model RLHF. Real preference provenance, large-model PEFT, task quality, retention and held-out human evaluation remain separate work. Complete rl-01 through rl-04 before the learned-reward PPO lesson; rl-05 is useful optional preparation for project Stage 5. Response-only SFT and dense LoRA do not require the RL phase.