AI Engineering · Module 12
Fine-tuning and model customization
- Lessons
- 9
- Free
- 0
- Reading
- ~3 h
Your progress
0 / 9 lessons done
Sign in to trackLessons
- Prompting, RAG or fine-tuning: choosing the right fixSooner or later someone on your team says “just fine-tune it”. Knowing which problems training fixes, and which it makes worse, saves weeks of work and a model you then have to keep alive.
- Fine-tuning basics: what changes in the modelWhen a narrow job must run on a model you host, fine-tuning is how a small open model learns it. Knowing what training changes tells you what it can fix, what it can break and what hardware it needs.
- Preparing data for fine-tuningA fine-tuned model learns exactly what is in its training file, including the duplicates, the typos in the labels and the customer’s email address. Most of the work, and most of the mistakes, happen before training starts.
- LoRA: fine-tuning with small add-on weightsWhen you fine-tune an open model, the GPU you have often can’t hold a full training run, and every extra task would need another full copy of the model. LoRA solves both, and its rank, alpha and target modules appear in almost every fine-tuning configuration you will read.
- Distillation: training a small model from a large oneWhen one narrow job runs on a large hosted model, someone asks whether a small model you run yourself could learn it from the large model’s answers. Building that small model is a data job, and it starts with the provider’s terms.
- Preference tuning: RLHF and DPO in plain termsAny product where people edit AI output collects better-and-worse pairs for free. Knowing what those pairs can teach a model, and what they can’t, decides whether you train on them or write the lesson into a prompt.
- Synthetic data: generating training examplesSooner or later a classifier needs a category nobody has labelled yet, or one with a few dozen examples. Asking a large model to write the missing examples takes an afternoon; knowing which of them to trust takes engineering.
- Evaluating a fine-tuned modelA fine-tuned model arrives with one good-looking score from its own training run. Before it touches real traffic, someone has to find out what that score hides, and decide which inputs the model may handle alone.
- Lab: fine-tuning a small open model with LoRAReading about LoRA tells you the shape of the idea. Training one end to end, from a JSON Lines file to a 40 MB adapter that beats the base model on tickets it never saw, shows where the real work and the real traps are.
Practise with
Terms this module teaches 48
Open glossaryAdapter (LoRA)
The small set of trained LoRA matrices for one task, saved as its own file and applied on top of the base model it was trained with.
Alpha (LoRA)
A scale for LoRA’s learned change: the change is multiplied by alpha ÷ rank. Changing it acts much like changing the learning rate.
Batch (training)
The small group of training examples whose loss is averaged before one update of the model’s weights.
Calibration
How well a model’s stated confidence matches how often it is right: of the answers it gives with 90% confidence, a calibrated model gets about 90% right.
Catastrophic forgetting
When training on a narrow task makes a model worse at things it could do before.
Chat template
The fixed text format, with special tokens, that an open model uses to mark each user and assistant turn; training data and served prompts must both use it.
Completion-only loss
Training that scores only the tokens of the answer, not the prompt, so the model learns to produce answers rather than to reproduce inputs.
Confidence threshold
The confidence below which a model’s answer isn’t used and the input goes to a fallback, such as a larger model or a person.
Distillation temperature
A number that divides the teacher’s logits before the softmax, so its probabilities spread onto wrong answers and the student can learn from them. The student is trained at the same temperature and then runs at 1.
DPO (Direct Preference Optimization)
A preference tuning method that learns straight from preference pairs with a classification loss, without a separate reward model or reinforcement learning. It raises chosen answers relative to rejected ones, measured against a reference model.
Epoch (training)
One full pass over all the training examples.
Fine-tuning
Training an existing model further on your own examples, which changes its weights. It teaches habits, formats and narrow skills well, and new facts poorly.
Full fine-tuning
Fine-tuning that updates every weight of a model. Training keeps a gradient and optimizer state for each weight, about 16 bytes per weight.
Gradient
For each weight, how much the loss would change if that weight grew a little; training moves each weight against its gradient.
GRPO (Group Relative Policy Optimization)
A reinforcement learning method that samples several outputs for the same input and rewards each by how it scores compared with the rest of that group.
Hard label
A training label that gives only the answer, with no information about how close the other answers were.
Jaccard similarity
How much two sets overlap: the number of items they share divided by the number of items in either. 1 means identical, 0 means nothing in common.
Knowledge distillation
Training a small, fast model (the student) to reproduce the judgments of a large, slow one (the teacher), so the large model runs only when making training data.
Learning curve
A model’s test score plotted against the number of training examples. Where the curve flattens, more data of the same kind stops helping.
Learning rate
The setting that controls how far each weight moves in one training step.
LoRA (low-rank adaptation)
A fine-tuning method that trains small add-on weight matrices while the model’s own weights stay frozen.
Loss (training)
One number that measures how far a model’s predictions are from the wanted outputs; training changes the weights to make it smaller.
Macro-F1
A classifier score that computes F1 (the balance of precision and recall) for each category separately, then averages them, so rare categories count as much as common ones.
MinHash
A way to estimate Jaccard similarity quickly: each set is reduced to a short list of minimum hash values, and similar sets tend to share many of them. Grouping these values into bands finds likely near duplicates without comparing every pair.
Mixed precision
Training that does most of its arithmetic in a 16-bit number format (fp16 or bf16) to run faster, while keeping the values that need accuracy in 32-bit. bf16 needs a recent GPU, such as NVIDIA Ampere or newer; older GPUs such as the T4 use fp16.
Model collapse
The gradual loss of the real data distribution when models are trained on output from earlier models, round after round. Rare cases disappear first.
Multi-adapter serving
Serving several LoRA adapters on one copy of the base model, with each request naming the adapter it needs, so requests for different tasks can share a batch.
Near duplicate
A piece of text that shares almost all its wording with another, such as the same template with a different name or number. In training data it adds weight without adding information.
NF4 (4-bit NormalFloat)
A 4-bit number format introduced with QLoRA, designed for model weights that follow a normal distribution.
Overfitting
When a model learns quirks of its training examples that don’t carry over to new ones: training loss keeps falling while validation loss rises.
Parameter-efficient fine-tuning
Fine-tuning that freezes a model’s original weights and trains a small set of added ones, so it needs far less GPU memory.
Preference pair
One input with two answers to it, labelled with which one a person or judge preferred: the chosen answer and the rejected one. Preference tuning trains on many of them.
QLoRA
LoRA training on a base model stored in 4 bits. Each weight is unpacked to 16 bits when used, and only the 16-bit adapters are trained.
Rank (LoRA)
The width r of LoRA’s two small matrices. A higher rank trains more numbers and can express a bigger change to a layer.
Reference model
A frozen copy of the model as it was before preference tuning. Training compares the tuned model with it to limit how far the tuned model drifts.
Reinforcement learning
Training a model by letting it produce outputs, scoring each with a reward, and adjusting the model toward outputs that score higher.
Seed example
A real or hand-written sample placed in a generation prompt so the model imitates its style, not its content.
Slice (evaluation)
A group of test inputs that share one trait, such as a language or a ticket length, scored on its own so a weak spot isn’t hidden by the overall average.
Soft label
A training label that gives the teacher’s probability for every possible answer, so the student also learns which wrong answers were close. The original distillation paper calls these soft targets.
Student model
In distillation, the smaller model trained to reproduce a teacher model’s answers.
Supervised fine-tuning
Further training a model on example inputs paired with the outputs you want, so it learns to produce outputs like them.
Synthetic data
Training or test examples written by a model instead of collected from real use. Useful for rare or new cases; it can’t show how often things really happen.
Target modules
The weight matrices of a model that get a LoRA adapter, named by their layer names, such as q_proj or down_proj.
Teacher model
In distillation, the large model whose answers become the training labels for a smaller model.
Training-use consent
A customer’s explicit permission for its data to be used to train a model, separate from permission to process it or to test with it. A trained model keeps what it learned, so withdrawing consent takes effect at the next retraining.
Upsampling
Repeating examples of a rare class in the training set so the model sees it more often. It adds weight, not new information, so too many copies lead the model to memorise those examples.
Validation split
Examples held back from training and scored during it, to see whether the model works on data it hasn’t learned from and to choose when to stop.
β (beta) in DPO
The DPO setting that limits drift from the reference model. A higher β means a smaller change already satisfies each pair, so the tuned model stays closer to where it started.