You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit cd4622d
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
*From a prompt to a fine-tuned, aligned, monitored assistant: every technique for adapting an open-weights LLM to your domain, on a single GPU, with reproducible numbers and the honesty to show when a technique does not win.*
4
4
5
-

5
+

6
6
7
7
Welcome to the code repository for **LLM Customization and Fine-Tuning: Adaptation, Distillation, and Alignment** (Manning Publications).
8
8
@@ -39,7 +39,7 @@ You need working Python and comfort at the command line; the book teaches the LL
39
39
40
40
- Choose the right adaptation technique (prompting/RAG vs LoRA/QLoRA vs full SFT vs distillation vs DPO) with an explicit cost, latency, privacy, and ROI framework.
41
41
- Fine-tune an LLM end to end with LoRA and QLoRA: data prep, training, evaluation, and inference.
42
-
- Build a training-data pipeline: curate and quality-gate real data, generate synthetic data with a frontier teacher, and track lineage and versioning.
42
+
- Build a training-data pipeline: curate and quality-gate real data, generate teacher-model training data (a local teacher in the book for reproducibility, a frontier API teacher in production), and track lineage and versioning.
43
43
- Distill a smaller, cheaper student from a stronger teacher, and align a model with DPO, with a safety-regression check at each step.
44
44
- Operate models in production: a model and data registry, drift detection with canary prompts, rollback procedures, a red-team safety monitor, and an outcome-based retraining cadence.
45
45
@@ -48,7 +48,7 @@ You need working Python and comfort at the command line; the book teaches the LL
48
48
-**The vendor-neutral, do-it-yourself counterpart to managed fine-tuning.** As the major vendors turn enterprise fine-tuning into a managed service, this book teaches the underlying methods and the operations layer those services abstract away, so you can run them on your own models and your own hardware and weigh build versus buy with real numbers.
49
49
-**The full technique spectrum in one running example.** A single fictitious enterprise (Contoso) and its IT help desk is threaded from prompting all the way through alignment and operations, so you see the same problem solved at every rung, with an explicit cost, latency, privacy, and ROI framework for choosing between the techniques.
50
50
-**Runnable and reproducible on a single GPU.** Every chapter runs on one GPU (LoRA and QLoRA on a modest consumer card; full fine-tuning and DPO on a single 24 GB card) and reproduces the book's published numbers within run-to-run variance. Validated on NVIDIA, AMD, and Apple Silicon.
51
-
-**Honest engineering.** The book shows when a technique does *not* win (for example, where DPO matches SFT on objective accuracy), anchors claims to real cost economics, and runs a safety-regression check at each step.
51
+
-**Honest engineering, in the open.** The book shows when a technique does *not* win (for example, where DPO matches SFT on objective accuracy), anchors claims to real cost economics, and runs a safety-regression check at each step. The code, the trained models, and the training and evaluation logs are all public, including the experiments that did not work, so you can verify every result and learn as much from what failed as from what worked.
52
52
-**The operational layer most LLM books skip.** Drift detection, versioning, rollback, and continuous safety monitoring, the part that decides whether a fine-tuned model survives past launch.
53
53
54
54
It uses a small open-weights model (Qwen3-4B) so every result reproduces on modest hardware, but the techniques themselves (LoRA, QLoRA, SFT, distillation, DPO) are model-size-agnostic and apply unchanged to larger frontier models, where scaling up is a matter of more memory and compute, not different methods.
@@ -100,15 +100,15 @@ The builder needs `beautifulsoup4` and `datasets` (both in the base install). Pe
100
100
101
101
| Chapter and topic | What you build |
102
102
|---|---|
103
-
|**[Chapter 1: Why Model Adaptation?](code/chapter01/README.md)**| A reproducibility script for the §1.6 sidebar. Runs the same prompt through base Qwen3-4B, the Chapter 5 LoRA adapter, and the Chapter 6 SFT model side by side; degrades gracefully if the later-chapter artifacts are not yet built. |
104
-
|**[Chapter 2: How Do I Do Model Adaptation?](code/chapter02/README.md)**| A five-step LoRA fine-tuning quickstart on Qwen3-4B-Instruct-2507 using a 40-example slice of the IT-support dataset (TRL's `SFTTrainer` plus PEFT): dataset prep, LoRA training, generation, and adapter save. Runs in under 10 minutes on a 12 GB GPU, and on Apple Silicon via MPS. |
105
-
|**[Chapter 3: What Data Do I Need?](code/chapter03/README.md)**| Data-quality experiment that trains the same model on four versions of Financial PhraseBank and compares results on a held-out test set; a six-step synthetic data generation pipeline (load → prompt → generate → quality-gate → distribution-check → mix-and-save) using a frontier teacher; and a standalone `DatasetManifest` module for content hashing, lineage tracking, and retention scheduling. |
106
-
|**[Chapter 4: In-Context Learning, Few-Shot, and RAG](code/chapter04/README.md)**| Few-shot ticket classifier, prompt validator with run-to-run variability measurement, minimal RAG pipeline (50 lines), and a Precision@k / Recall@k / Hit@1 retrieval evaluator. CPU-friendly; GPU optional. |
107
-
|**[Chapter 5: Parameter-Efficient Fine-Tuning (LoRA and QLoRA)](code/chapter05/README.md)**| LoRA and QLoRA adapters trained on the IT-support dataset (real Stack Exchange IT Q&A plus a Dolly slice) with Qwen3-4B-Instruct-2507, evaluated against the base model with per-category Token-F1 and a safety regression suite. |
108
-
|**[Chapter 6: Supervised Fine-Tuning (SFT)](code/chapter06/README.md)**| A full-parameter SFT of Qwen3-4B-Instruct-2507 on the IT-support dataset, with overfit monitoring, three-way base-vs-LoRA-vs-SFT comparison, behavioral tests, and a separate safety regression suite. |
109
-
|**[Chapter 7: Knowledge Distillation](code/chapter07/README.md)**| Black-box distillation from the chapter 6 SFT teacher into a chapter 5-style LoRA student, with quality filtering, three-way base-vs-teacher-vs-student evaluation, safety robustness check, and an optional OpenRouter-backed SFT-vs-frontier-API comparison. |
110
-
|**[Chapter 8: DPO and Advanced Alignment](code/chapter08/README.md)**| Preference-optimisation of the chapter 6 SFT model using TRL's `DPOTrainer`; three-way base-vs-SFT-vs-DPO comparison; safety regression after DPO. |
111
-
|**[Chapter 9: Managing Model Evolution, Drift, and Versioning](code/chapter09/README.md)**| A JSON-backed model registry, a TF-IDF drift detector, a simulated rollback workflow, a canary-prompt monitor, and a red-team safety monitor with per-category alerting. |
103
+
|**[Chapter 1: Why model adaptation?](code/chapter01/README.md)**| A reproducibility script for the §1.6 sidebar. Runs the same prompt through base Qwen3-4B, the Chapter 5 LoRA adapter, and the Chapter 6 SFT model side by side; degrades gracefully if the later-chapter artifacts are not yet built. |
104
+
|**[Chapter 2: How to do model adaptation](code/chapter02/README.md)**| A five-step LoRA fine-tuning quickstart on Qwen3-4B-Instruct-2507 using a 40-example slice of the IT-support dataset (TRL's `SFTTrainer` plus PEFT): dataset prep, LoRA training, generation, and adapter save. Runs in under 10 minutes on a 12 GB GPU, and on Apple Silicon via MPS. |
105
+
|**[Chapter 3: What data do I need for model adaptation?](code/chapter03/README.md)**| Data-quality experiment that trains the same model on four versions of Financial PhraseBank and compares results on a held-out test set; a six-step synthetic data generation pipeline (load → prompt → generate → quality-gate → distribution-check → mix-and-save) using a frontier teacher; and a standalone `DatasetManifest` module for content hashing, lineage tracking, and retention scheduling. |
106
+
|**[Chapter 4: In-context learning, few-shot, and RAG](code/chapter04/README.md)**| Few-shot ticket classifier, prompt validator with run-to-run variability measurement, minimal RAG pipeline (50 lines), and a Precision@k / Recall@k / Hit@1 retrieval evaluator. CPU-friendly; GPU optional. |
107
+
|**[Chapter 5: Parameter-efficient fine-tuning: LoRA and QLoRA](code/chapter05/README.md)**| LoRA and QLoRA adapters trained on the IT-support dataset (real Stack Exchange IT Q&A plus a Dolly slice) with Qwen3-4B-Instruct-2507, evaluated against the base model with per-category Token-F1 and a safety regression suite. |
108
+
|**[Chapter 6: Supervised fine-tuning: maximum expressiveness](code/chapter06/README.md)**| A full-parameter SFT of Qwen3-4B-Instruct-2507 on the IT-support dataset, with overfit monitoring, three-way base-vs-LoRA-vs-SFT comparison, behavioral tests, and a separate safety regression suite. |
109
+
|**[Chapter 7: Knowledge distillation: capturing frontier model intelligence](code/chapter07/README.md)**| Black-box distillation from the chapter 6 SFT teacher into a chapter 5-style LoRA student, with quality filtering, three-way base-vs-teacher-vs-student evaluation, safety robustness check, and an optional OpenRouter-backed SFT-vs-frontier-API comparison. |
110
+
|**[Chapter 8: Preference optimization: teaching your model to judge](code/chapter08/README.md)**| Preference-optimisation of the chapter 6 SFT model using TRL's `DPOTrainer`; three-way base-vs-SFT-vs-DPO comparison; safety regression after DPO. |
111
+
|**[Chapter 9: Managing model evolution, drift, and versioning](code/chapter09/README.md)**| A JSON-backed model registry, a TF-IDF drift detector, a simulated rollback workflow, a canary-prompt monitor, and a red-team safety monitor with per-category alerting. |
112
112
113
113
**Start here:**
114
114
1.[code/README.md](code/README.md): set up your Python environment and install the package.
0 commit comments