From a base model to an assistant: post-training
Adapting pretrained parameters, and what stays in the context
A pretrained base model predicts likely continuations of text; it was not trained to follow instructions or to hold a conversation. Post-training adapts its parameters to that end. The mechanism is the training loop already studied, applied to a model that starts from learned parameters and uses different data, targets, or training signals.
Two different things can change an answer.
- Change the parameters (post-training): run the training loop on new data. The change persists in the checkpoint and applies to every later prompt.
- Change the context (prompting, examples, retrieved documents): supply different input to fixed parameters. The change applies to that request only.
Post-training methods differ in which data, which tokens contribute to the loss, and which parameters are updated. They are not synonyms and are not all used for every model.
What stays the same: the loop
Post-training starts from the parameters \(\theta_0\) obtained by pretraining, not from a random initialization. Each step still performs a forward pass, a loss, a gradient and an update. What changes is the training data and which positions the loss counts.
| Method | Data | Training signal | Parameters changed |
|---|---|---|---|
| Pretraining | Large unannotated text corpus | Next-token cross-entropy on every valid target position | All |
| Supervised fine-tuning (SFT) / instruction tuning | Curated instruction–response demonstrations | Next-token cross-entropy, typically on the response tokens only | Usually all, or a small added subset (see below) |
| Preference-based methods (RLHF, DPO) | Comparisons between candidate responses to the same prompt | A learned reward (RLHF) or a loss defined directly on the preferred and rejected responses (DPO) | Usually all, or a small added subset |
| Prompting, few-shot examples, RAG | Text placed in the context at request time | None: no training | None |
The table states typical practice; individual systems differ and public documentation does not always say which combination a given model used.
Supervised fine-tuning: the same loss, a different mask
An instruction–response pair is concatenated into one token sequence, for example a prompt followed by the desired answer. SFT then applies the next-token objective from Loss. The common choice is to let only the response tokens contribute to the loss: prompt positions provide context through the causal mask but are excluded from the mean through the loss mask. Counting the prompt as well is also possible and changes the objective.
This is why the loss mask matters: it selects which targets contribute to the objective; it does not decide which positions the attention can read. Nothing else in the forward pass changes. SFT shifts the model’s distribution toward the demonstrated answers: it makes continuations resembling the training responses more likely, without guaranteeing that a given answer will be correct, useful, or even consistently produced.
SFT teaches by imitation of the demonstrations. It does not by itself tell the model which of two acceptable answers a person would prefer, and its quality depends on the quality and coverage of the demonstrations.
Conversation format: chat templates
Before training an assistant, messages must be serialized into a token sequence. A chat template defines this representation: role markers (system, user, assistant), content, message boundaries, and control markers indicating, for example, whether the assistant turn has ended or control is being handed to a tool.
This format is a model-specific input/output convention, not a universal structure. Two models can represent the same conversation with different special tokens and rules. Use the template expected by the model and preserve it with the dataset provenance and tokenizer revision.
During SFT, a mismatched template can teach the model role boundaries or end markers that are incompatible with those used at inference. The template prepares the sequence; the loss mask separately determines which positions contribute to the objective. Do not confuse the two.
Templates can also encode tool calls. They represent control structure in the sequence, but do not execute the tool themselves: the host application interprets and executes the call.
See the Hugging Face documentation on chat templates and Chapter 11 of the course.
Preference-based methods
Preference data records which of two (or more) candidate responses to the same prompt a person or another judge preferred. Two families are common.
- Reward-model RLHF. First, a reward model is trained to assign higher scores to preferred responses. Then the language model is optimized with a reinforcement-learning algorithm (often PPO) to produce responses that score well, usually with a penalty that keeps it close to the starting model. The reward is a learned proxy for the preference data, not a measure of truth or quality.
- Direct preference optimization (DPO). The language model is trained directly with a loss on preferred versus rejected responses, without a separate reward model and RL loop.
Both change the parameters, so both are post-training. They differ from SFT in that the signal is a comparison, not a single target sequence. Both remain optimizing a proxy: data collected from particular raters, prompts and criteria. Their derivations, variants and trade-offs are outside this lesson; see the glossary entries and the sources below.
Updating fewer parameters
Fine-tuning every parameter of a large model requires storing gradients and optimizer state for all of them. Parameter-efficient methods freeze the pretrained weights and train a small number of added parameters. LoRA, for example, learns a low-rank correction to selected weight matrices (Hu et al., 2021). This changes how many parameters the optimizer updates, not the objective: the loop is the same, and the result is the pretrained weights plus a small trained addition.
Changing the context instead
Some methods leave the parameters untouched.
- Prompting and in-context examples: instructions or demonstrations placed in the prompt shape the continuation without any update. See In-context learning for what examples can and cannot do.
- Retrieval-augmented generation (RAG): a retrieval step fetches documents and inserts them into the prompt (Lewis et al., 2020). New information can be added by updating the document store, without training; the answer is only as good as retrieval and the model’s use of the retrieved text.
- “Fine-tuning adds knowledge the way a database insert does.” It adjusts parameters toward the training signal; it may shape style and format reliably, and facts less reliably, and can degrade behaviour outside the tuning data.
- “Instruction tuning changes the architecture.” The network is the same; the parameters differ.
- “RLHF and DPO are interchangeable names for fine-tuning.” They use comparison data and different objectives; SFT uses demonstrations.
- “A model that follows instructions is therefore truthful.” Post-training shapes the distribution toward preferred outputs; it does not guarantee factual accuracy. See LLM limits.
Choosing between context and parameters
Start with the cheapest change that your measurements justify: the model as is, then context (examples, retrieval), then parameters. Adapting is justified when a format, domain or behaviour is not obtained from the context alone and enough good data exists. The decision rests on measured quality, cost, latency, confidentiality, data provenance and maintenance, as in the LLM panorama. A few successful prompts are not an evaluation; see Experimental evaluation.
For the position of these methods in the history of assistant models, see LLM evolution. The from-scratch Build path does not cover adaptation; its status is tracked in the Build path.
Practice
Check the distinctions between SFT, RLHF, DPO, LoRA and retrieval on the dedicated post-training exercise page.
Supplementary resources Experiment, explore further, and practise the ideas from this lesson.
Further reading
- Ouyang et al. — Training language models to follow instructions with human feedback: supervised fine-tuning, a reward model and PPO in one documented pipeline.
- Wei et al. — Finetuned Language Models Are Zero-Shot Learners (FLAN): instruction tuning on many tasks phrased as instructions.
- Rafailov et al. — Direct Preference Optimization: preference learning without a separate reward model.
- Hu et al. — LoRA: Low-Rank Adaptation of Large Language Models: parameter-efficient adaptation by low-rank updates.
- Lewis et al. — Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks: retrieval inserted into the context at inference time.
- Andrej Karpathy — Deep Dive into LLMs like ChatGPT (2025, English video, about 3 h 31): an educational overview of pretraining, SFT, RL, DeepSeek-R1, and RLHF. Use it to connect the stages, then consult primary papers for algorithmic details.