Chapter 7.6 — Fine-tuning, distillation and alignment in production¶
🎯 Objective¶
Treat fine-tuning as an engineering discipline, with a criterion for when to use it, when not to, and what the minimum operational obligations are. This chapter speaks directly with Ch. 2.2 (quantization + LoRA/QLoRA) and with Ch. 2.10 (RAG vs FT vs prompt).
🧠 What fine-tuning is really for¶
Fine-tuning is good for changing:
- Format (a recurring output structure that prompt + structured output do not stabilize sufficiently yet).
- Style / voice (company tone, specific terminology, domain technical language).
- Tool calling behavior with well-defined schemas and a stable dataset.
- A specialized domain with vocabulary far outside the training distribution.
Fine-tuning is bad for:
- Mutable factual knowledge -> use RAG.
- Business rules -> use policy-as-code.
- "Guaranteeing" safety behavior -> use authorization + policy.
🧠 Three independent axes¶
"DPO or LoRA?" is a malformed question: they are answers to different questions. There are three axes, and any combination of them is valid when the implementation supports it.
| Axis | Question | Options | Note |
|---|---|---|---|
| Objective and signal | What should the model learn, and from which data? | SFT (demonstrations); preference optimization: DPO and variants, RLHF with a reward model (chosen/rejected pairs); RL with verifiable reward, RLVR (tests, verifiers) | Defines the dataset you need to produce and review |
| Updated parameters | Which weights change? | Full fine-tuning; low-rank adapters (LoRA, DoRA) | LoRA learns less and forgets less. On small and medium datasets and in RL it tends to match full FT (even at low rank), provided it is applied to all linear layers, including MLP, and with a learning rate about 10× higher; in continued pretraining over billions of tokens it falls behind |
| Base representation | In what precision does the base sit during training? | BF16/FP16; frozen quantized base + adapters (QLoRA) | QLoRA is a memory shortcut, not a training objective |
In the most used post-training library, the SFT, DPO and GRPO trainers accept adapters and a quantized base; in DPO with an adapter, the reference policy is obtained by disabling the adapter, without loading a second model. Distillation is not a fourth axis: it is a data-acquisition pattern (a teacher's outputs become the student's demonstrations) that enters the first axis as SFT. Distillation guarantees neither savings nor fidelity: compare total cost and regressions. Cost depends on model, context, data quantity and quality, references, rollouts and evaluation, without a universal ordering across these methods. Ch. 7.8 details phases, data and operation.
🧠 Knowledge: what weights give and what they do not¶
| Need | Weights (continued pretraining / SFT) | Retrieval + tools | Typical decision |
|---|---|---|---|
| Vocabulary, conventions and reasoning of a stable domain | Yes: this is the use case for continued pretraining on a domain corpus (medicine, law), followed by a behavior-restoration step | Partial | Train, with a regression eval |
| Facts that change every week | Small SFT learns new facts slowly and increases hallucination as it learns them; updating is expensive | Yes | Retrieval |
| Answer with a verifiable citation | No (a weight carries no pointer to the source) | Yes | Retrieval |
| Authorization per document or tenant | No (a weight does not know who is asking) | Yes, in storage | Retrieval + filters |
| Audit of "where it came from" | No | Yes | Retrieval |
| Format, style, tool use | Yes: this is what fine-tuning does well | No | SFT/DPO, typically with LoRA |
The rule "does not know X → RAG" holds for mutable facts, for citable evidence and for governed access. For domain adaptation with stable knowledge, training is legitimate, provided the evaluation is independent, includes regressions and plans for behavior restoration: in a published case, mid-training on internal documents raised internal QA from 18% to 43% and dropped instruction following from 85% to 45%; with 30% chat data in the mix the drop stopped at 79%, and a distillation step brought it to 83% (internal QA at 41%). Beware of misquoted examples: not every "domain LLM" was obtained by continued pretraining (some were trained from scratch; others used prompt tuning), and those cases do not show that fine-tuning adds knowledge.
🧠 The difference between behavior, format, style and knowledge¶
In a typical planning conversation:
- If the frustration is "the model does not respond in format X" -> use structured outputs, prompt and function calling. Fine-tuning only when the problem persists at scale.
- If the frustration is "the model does not talk like us" -> use light fine-tuning (LoRA) for style, keeping knowledge in RAG.
- If the frustration is "the model does not know X", distinguish access to mutable facts from domain adaptation. RAG/tools helps updates, authorization, and evidence; training can also incorporate knowledge, with cost, memorization, and regressions to evaluate.
- If the frustration is "the model sometimes ignores the policy" -> use policy-as-code and HITL. Not fine-tuning.
🛡️ Minimum operational obligations¶
- Pre- and post-FT eval on golden + adversarial + regression. Compare against the baseline on all relevant dimensions, not just the one that motivated the FT.
- Immutable version + moving alias. A fine-tuned model is a versioned artifact; it lives in the registry.
- A defined rollback. Which model comes back? In how long?
- Regression metrics monitored in production. FT can fix A and silently break B.
- Dataset documentation (datasheet/dataset card): origin, license, known bias, legal basis.
🚨 Failure modes¶
- FT on a dataset with untreated PII -> leakage via memorization.
- FT with a small, noisy dataset -> catastrophic overfitting.
- FT used as the only source of mutable facts -> updates and factual recall are not guaranteed.
- Mixing QLoRA adapters trained on different versions of the 4-bit base.
- Promoting an FT model without a comparative eval.
⚠️ On RLHF / DPO within this book's scope¶
RLHF names a family of methods that use human feedback: in the classical recipe, demonstrations feed SFT, preferences train a reward model, and an RL algorithm updates the policy while controlling deviation from a reference. DPO optimizes chosen/rejected pairs directly, relative to a reference policy, with no separate reward model and no online loop. Neither requires training a model from scratch or updating every weight: teams that consume open-weight models apply DPO with LoRA adapters, and current post-training libraries accept adapters in SFT, DPO and RL. What this book does not cover is the algorithmic detail of RL (PPO, GRPO, advantage estimation); what it covers, in Ch. 7.8, is what a production team needs to decide, produce data, measure and operate.
📚 References¶
- Hu et al. — LoRA: Low-Rank Adaptation of Large Language Models: https://arxiv.org/abs/2106.09685
- Dettmers et al. — QLoRA: Efficient Finetuning of Quantized LLMs: https://arxiv.org/abs/2305.14314
- Sebastian Raschka — LoRA vs full fine-tuning: https://sebastianraschka.com/faq/docs/lora-vs-full-finetuning.html
- Hinton et al. — Distilling the Knowledge in a Neural Network: https://arxiv.org/abs/1503.02531
- Rafailov et al. — DPO: Direct Preference Optimization: https://arxiv.org/abs/2305.18290
- OpenAI — Supervised fine-tuning: https://developers.openai.com/api/docs/guides/supervised-fine-tuning
- Hugging Face TRL — PEFT integration (LoRA adapters in SFT, DPO and GRPO): https://huggingface.co/docs/trl/peft_integration
- Biderman et al. — LoRA Learns Less and Forgets Less (TMLR 2024): https://arxiv.org/abs/2405.09673
- Schulman et al. (Thinking Machines) — LoRA Without Regret (2025): https://thinkingmachines.ai/blog/lora/
- Gekhman et al. — Does Fine-Tuning LLMs on New Knowledge Encourage Hallucinations? (EMNLP 2024): https://arxiv.org/abs/2405.05904
- Ovadia et al. — Fine-Tuning or Retrieval? Comparing Knowledge Injection in LLMs (2024): https://arxiv.org/abs/2312.05934
- Chen et al. — MEDITRON-70B: Scaling Medical Pretraining for Large Language Models (2023): https://arxiv.org/abs/2311.16079
- Colombo et al. — SaulLM-7B: A pioneering Large Language Model for Law (2024): https://arxiv.org/abs/2403.03883
- Lu et al. (Thinking Machines) — On-Policy Distillation (2025): https://thinkingmachines.ai/blog/on-policy-distillation/