← Post-training series

Series 02 / Post-training

Post-training a language model.

A transcript-grounded path from base checkpoint to assistant: conversation demonstrations, preferences, reinforcement learning, tools, working memory, security boundaries, and independent evaluation.

SERIES 02 / CHAPTER 01

01
POST-TRAININGSHAPE THE ASSISTANT

DEMONSTRATIONS → PREFERENCES → POLICY

  • SFT
  • Feedback
  • RL

Pre-training builds capability; post-training decides how that capability is expressed. The job is to transform a broad next-token model into a policy that follows instructions without destroying useful knowledge or learning shortcuts in the feedback.

POST-TRAINING MODELSSERIES 02
The post-training systemA base model learns from demonstrations through supervised tuning. Preference pairs then support either a reward-model and PPO path or a direct preference path. Both produce a policy that is independently evaluated.SKETCH 01 / THE POST-TRAINING SYSTEMBASEMODELSFTdemonstrationsassistant lossPREFERENCEPAIRSy⁺ vs y⁻REWARD MODELscore responsesDPOpairwise lossPPOASSISTANTPOLICYindependent evaluation loops back into datatwo optimization paths
Sketch 01 Demonstrations establish the assistant role; preferences then shape the policy through two different optimization paths.

Define the behavior before choosing the optimizer.

Post-training begins with a behavior specification: which instructions should be followed, which constraints outrank others, when the assistant should ask a question, which actions require permission, what counts as task completion, and which failures are unacceptable. A dataset is useful only when it encodes that contract consistently.

A base model, an assistant, and an agent are different artifacts. Pre-training learns broad statistical capability from next-token targets. Supervised tuning teaches the conversation role and response format. Preference learning and reinforcement learning shift the policy toward judgments or outcomes that ordinary text does not supply densely.

ArtifactTraining signalContract learned
Base model

Observed next tokens

Complete a statistical text distribution

Assistant

Curated demonstrations

Roles, format, instructions, and uncertainty

Aligned policy

Rankings, rewards, or verified outcomes

Behavioral priorities and strategies

Agent

Trajectories and environment outcomes

When to act, inspect, recover, and stop

Keep those stages distinguishable in experiments. If the chat template, policy data, generation settings, and weights all change together, an observed improvement cannot be assigned to one cause. Preserve the base checkpoint, version every derivative policy, and test both newly learned behavior and retained base capability.

Use one canonical conversation schema across demonstration, preference, and evaluation data. Preserve role boundaries as explicit tokens or structured fields. Keep tool calls and tool results distinct from natural-language messages, and attach source, policy, annotator, and version metadata to every example.

FieldContents
example_id, task_id

Stable identity and grouping

messages[]

Role, content, and content type in order

tools[]

Names, JSON schemas, permissions, and budgets

labels

Demonstration, ranking, criterion, or scalar score

provenance

Author, model, policy, source, and timestamps

split, cluster_id

Leakage-safe partitioning

Split by task and semantic cluster, not by individual response. If two variants of the same prompt land in train and evaluation sets, the score measures memorization of the annotation pattern. Balance task domains, difficulty, languages, refusal cases, tool-use cases, and response lengths explicitly.

Teach the response format with assistant-only loss.

Supervised fine-tuning starts from a pre-trained checkpoint and optimizes high-quality demonstrations. A conversation is serialized into one token sequence, but the loss mask normally selects only tokens the assistant is responsible for generating. System and user tokens provide conditioning; assistant tokens provide targets.

Masked supervised objectiveLSFT = − (1 / Σₜ mₜ) Σₜ mₜ log πθ(yₜ | x, y<t)

mₜ = 1 on assistant target tokens and zero on prompt, padding, or ignored spans.

input_ids = serialize(messages)
labels = input_ids.clone()
labels[role != "assistant"] = -100
labels[padding] = -100
loss = model(input_ids, labels=labels).loss

Masking is easy to get subtly wrong at role separators, tool results, and multi-turn boundaries. Unit tests should decode every supervised span and verify that the first predicted assistant token sees the complete prompt but no future response token.

SFT data quality dominates raw volume. Strong demonstrations should be correct, direct, appropriately detailed, and internally consistent about policy. Oversampling one response style can make the model verbose or formulaic. Monitor task loss separately from format compliance, refusal precision, answer length, and held-out base capabilities.

Collect comparisons that isolate meaningful differences.

A preference record contains a prompt x, a preferred response y⁺, a rejected response y⁻, and the criteria behind the choice. The pair is informative only when the evaluator can make a stable distinction. Two equally good answers create noise; one obviously broken answer teaches little about the decision boundary.

FieldRequirement
prompt

Exact serialized context and available tools

chosen, rejected

Unmodified candidate outputs

criteria[]

Correctness, completion, clarity, safety, efficiency

rationale

Decision evidence, not a vague score

annotator_confidence

Agreement and ambiguity signal

candidate_metadata

Policy version, sampling settings, length, tool trace

Randomize left-right order and hide model identity. Control for length: evaluators often reward longer answers even when detail adds no value. Preserve per-criterion judgments before producing an overall preference so later audits can separate factual correctness from style or safety.

Mine pairs near the current policy’s capability frontier. If candidates are drawn only from an old or much weaker policy, the optimized model quickly outruns the dataset. Refreshing candidate generation and keeping an untouched evaluation pool prevents the signal from going stale.

Turn pairwise judgment into a learned scalar carefully.

A reward model reads the prompt and response, then emits a scalar. With the Bradley–Terry formulation, the probability that y⁺ is preferred is a sigmoid of the reward difference. Training minimizes the negative log-probability of the observed ordering.

Preference probabilityP(y⁺ ≻ y⁻ | x) = σ(rφ(x,y⁺) − rφ(x,y⁻))

Only reward differences are identified; absolute reward values have no standalone meaning.

Reward-model lossLRM = − log σ(rφ(x,y⁺) − rφ(x,y⁻))

Average across pairs, then report accuracy and calibration by task and criterion.

Hold out prompts—not only pairs—to test generalization. Slice performance by language, response length, safety category, task difficulty, and candidate source. A high overall ranking accuracy can hide a model that rewards verbosity, familiar formatting, or confident tone.

The reward model is a proxy. Once a policy is optimized against it, small proxy errors become attractive strategies. Maintain adversarial sets, disagreement reviews, and periodic human comparison of high-reward outputs. The closer optimization pushes to the edge of the reward model’s training distribution, the less its scalar should be trusted without direct evidence.

Let the model practice where outcomes can be checked.

Supervised demonstrations ask the model to imitate solutions written by people or stronger systems. Reinforcement learning can instead let the policy sample many candidate trajectories and reinforce the ones that satisfy an external verifier. Mathematics, code, games, and constrained tool tasks are useful because correctness can often be checked without asking a judge to estimate quality from style.

Task distributionSample trajectoriesExecute or verifyAssign rewardUpdate policy

The AlphaGo analogy in the lecture is structural: expert demonstrations establish a competent starting policy, then self-play creates experience beyond the human dataset because the game supplies an exact outcome. Language tasks rarely offer such a complete simulator, but the same pattern applies wherever tests, equations, schemas, or environment state can determine success.

A verifier changes the data bottleneck. The model can generate its own practice attempts, but only if the task distribution is diverse, the checker is difficult to exploit, and failed attempts are retained for analysis. A reward of one for passing a weak test invites reward hacking; require hidden tests, adversarial cases, resource limits, and independent evaluation.

SignalStrengthPrimary risk
Demonstration

Dense token-level target

Copies annotator strategy and ceiling

Human preference

Works for subjective qualities

Bias, inconsistency, and proxy exploitation

Programmatic verifier

Scalable exact outcome on bounded tasks

Checker loopholes and narrow task distribution

Environment outcome

Measures end-to-end completion

Sparse credit and unsafe exploration

Improve reward without letting the policy drift freely.

In PPO-style human-feedback training, the current policy samples a response. The reward model scores it, and a penalty compares the policy against a frozen reference model. A value head estimates expected return so the optimizer can compute lower-variance advantages.

KL-regularized sequence rewardR = rφ(x,y) − β [log πθ(y|x) − log πref(y|x)]

β controls how expensive it is to move away from the reference policy.

Clipped policy objectiveLPPO = −E[min(ρₜAₜ, clip(ρₜ,1−ε,1+ε)Aₜ)]

ρₜ = πθ(aₜ|sₜ) / πold(aₜ|sₜ); clipping limits destructive updates.

The practical loop is rollout generation, reward computation, advantage estimation, several minibatch updates, and evaluation. Log reward-model score, KL, response length, entropy, value loss, clip fraction, task success, and independent human preference. A reward increase with collapsing entropy, exploding length, or falling task success is not progress.

Stability depends on rollout freshness, learning rate, KL control, batch size, reward normalization, value accuracy, and the number of optimizer passes over each rollout. Reuse a batch too aggressively and the policy becomes far from the policy that generated it. Move too conservatively and the run spends substantial compute for little behavior change.

Optimize pairwise preferences without a separate reward model.

Direct preference optimization compares how the current policy and a frozen reference policy score the chosen and rejected responses. It increases the relative log-probability of the chosen response while retaining an implicit constraint to the reference.

DPO objectiveLDPO = −log σ(β[(log πθ(y⁺|x) − log πref(y⁺|x)) − (log πθ(y⁻|x) − log πref(y⁻|x))])

Sequence log-probabilities are sums over response tokens only; prompt and padding tokens are masked.

DPO removes rollout generation, value estimation, and a separately trained reward network from the optimization loop. That simplicity does not remove data risk. Pair quality, policy coverage, sequence-length treatment, reference choice, and β still determine the behavior learned.

chosen_margin  = logp_policy_chosen  - logp_ref_chosen
rejected_margin = logp_policy_rejected - logp_ref_rejected
loss = -logsigmoid(beta * (chosen_margin - rejected_margin)).mean()

Track chosen and rejected log-probabilities separately. A falling loss can come from increasing the chosen response, suppressing the rejected response, or both. Evaluate base capabilities and calibration after every checkpoint; preference optimization can narrow the policy if the pair distribution is too small or stylistically uniform.

A tool-use trajectoryA task leads to a decision, structured tool call, observation, state update, and verifier. A failed check loops back to a revised decision; a passed check produces the final answer.SKETCH 02 / ONE COMPLETE TOOL-USE TRAJECTORYUSERTASKDECIDEsubgoalTOOL CALLnameargumentsOBSERVEresult + errorVERIFYcriterion evidenceFINALANSWERcheck fails → revise the decision with the new stateobservation updates the environment stateCAPTURE: TURN ID · TOOL NAME · ARGUMENTS · RESULT · STATE DELTA · ARTIFACTS · SCORE
Sketch 02 A useful trajectory keeps the causal link from decision to action, observation, state change, and proof.

Train the process when the outcome depends on a process.

For multi-step tasks, the supervision target is not only the final answer. The model must learn when to decompose, when to inspect the environment, which tool to call, how to read the observation, and when evidence is sufficient to stop. Store concise decision summaries rather than private internal monologues.

An autoregressive model receives a roughly fixed amount of computation per generated token. Producing intermediate tokens gives it more sequential compute and a writable scratch space in context. This helps only when training rewards useful decomposition and verification; extra length by itself can produce confident detours.

tasksubgoaltool callobservationstate changecheck

Tool calls should be trained as structured outputs with strict schemas. Tool results belong to a separate role and must be treated as untrusted data. Reward the verified task outcome, then keep process criteria distinct: required tool use, prohibited actions, total turns, retries, latency, and irreversible side effects.

FailureEntry pointControl to teach and enforce
Instruction override

User-controlled prompt

Role hierarchy and adversarial examples

Prompt injection

Untrusted tool or document text

Data–instruction separation and permission checks

Unsafe action

Generated tool call

Least privilege, validation, and confirmation

Model behavior is only one layer of the security boundary. Sandboxes, allowlists, scoped credentials, user confirmation, output validation, rate limits, and audit logs must constrain what generated text can cause. Training should expose attempted overrides and malicious observations, while the runtime must remain safe even when the model makes the wrong decision.

Reasoning data needs its own quality controls. Long traces can contain unsupported steps, copied errors, or unnecessary verbosity. Outcome-based filtering alone keeps lucky reasoning. Add step-level checks where possible, compare alternate approaches, and include recovery examples in which an observation invalidates the current plan.

A post-trained agent should learn when to act, when to verify, and when to stop.

An assistant must know which information is in weights, context, or tools.

Pre-training compresses patterns into weights. The conversation supplies temporary working memory. Tools can provide current or exact external state. Post-training should teach the policy to distinguish these sources: answer stable, well-supported knowledge directly; use a tool when freshness or precision matters; and express uncertainty when neither source is adequate.

Hallucination is encouraged when the training format always contains an answer, even when the prompt asks about a nonexistent fact or a future event. Include examples that verify premises, decline unsupported specificity, ask for missing context, or call an appropriate tool. Tool use should be rewarded for correctness and necessity, not merely frequency.

Models also have imperfect self-knowledge. A training cutoff or system identity supplied in a prompt is context, not a fact the base weights can reliably derive about themselves. Keep version, date, permissions, available tools, and policy constraints in explicit system metadata.

SourcePersistenceFailure mode
Model weights

Fixed until training changes them

Stale, compressed, or incorrectly generalized knowledge

Context

Current session only

Finite length, distraction, and instruction conflict

Tool observation

External system controls persistence

Untrusted content, errors, and permission risk

Generated scratch work

Current trajectory

Compounding unsupported steps

Capability remains jagged. Tokenization makes spelling and character operations unlike ordinary human reading; stochastic generation makes repeated attempts differ; strong performance in one domain does not imply reliable performance in an adjacent one. Post-training should calibrate behavior around this uneven map rather than hide it behind a single confidence style.

Evaluate behavior as a vector, not one reward.

Use separate suites for instruction following, factual correctness, coding, reasoning, tool use, calibration, safety, and long-horizon completion. Combine deterministic checks with blinded human comparisons. Keep the base checkpoint, SFT checkpoint, and each preference-optimized checkpoint in the same evaluation table.

LayerEvidenceFailure exposed
Output

Exact checks and criterion scores

Incorrect or incomplete answers

Preference

Blind pairwise wins with confidence

Style and usefulness regressions

Process

Trajectory, tool counts, turn budget

Loops and unsafe actions

Operations

Latency, tokens, failures, cost

Unusable system behavior

Watch for regressions hidden by averages: unnecessary refusals, reward hacking, length inflation, loss of multilingual ability, brittle formatting, overuse of tools, and confident answers when uncertainty should be expressed. Run targeted red-team suites and inspect examples where automated checks and humans disagree.

The final post-training artifact includes more than model weights. Ship the tokenizer, chat template, tool schemas, policy configuration, generation settings, evaluation report, dataset manifests, and versioned behavior specification together. Without that bundle, the assistant cannot be reproduced or audited.

Verified transcript rangeMaterial used in this chapter
14:14–25:43 ↗

Assistant tuning, comparison data, human feedback, synthetic data, and evaluation

27:43–42:15 ↗

Tools, modalities, deliberate computation, customization, and system structure

45:43–59:23 ↗

Instruction attacks, malicious tool content, data poisoning, and system security boundaries

59:23–01:20:32 ↗

Transition from a base model to conversation data and assistant behavior

01:20:32–02:07:28 ↗

Hallucinations, tools, knowledge and working memory, self-knowledge, deliberate tokens, and jagged capability

02:07:28–03:09:39 ↗

Supervised tuning, reinforcement learning, verifiable domains, AlphaGo, and human feedback

Verified transcripts and primary references

The verified lecture transcripts supply the conceptual progression and examples. The primary papers supply the optimization details. The chapter’s data contracts, tests, and system recommendations are Vikram Kharvi’s synthesis.

Continue to model serving