Mirage Academy · Fine-tuning

LLM fine-tuning course: choose, train with LoRA, test against a baseline

You have a model that almost works for your domain, and your team asks whether to fine-tune it. This course teaches you to make that call and defend it: when to adapt a model instead of retrieving, how to prepare data, how to train efficiently, and how to show the improvement against a baseline.

Open the fine-tuning courseCompare it with the RLHF course

The course

Eight chapters take you from the decision to a tuned model and a memo

Masters level, taught in English, and aimed at engineers and product people who ship AI features. Watch the intro, then follow the route.

Still from the intro video for the course Fine-Tuning & Post-Training LLMs
Intro video, 1 min 3 s. Transcript below.
Read the transcript

You have a model that almost works for your domain, and a team asking whether to fine-tune it. This course is for the engineer who has to make that call and defend it. First you learn to choose. Retrieval and prompting suit knowledge that changes. Fine-tuning suits behaviour you want built into the model. Either way, you check against a baseline. Then you run the loop. You prepare training data, including instruction and synthetic examples. You train with supervised fine-tuning, LoRA and QLoRA. You align with preference optimisation and DPO. You evaluate before and after, and repeat until the model beats its baseline. The course ends with a capstone: you build a domain model and prove it beats its baseline. If you need to decide, train and show the result, start with the first chapter.

Open the course: Fine-Tuning & Post-Training LLMs

The route

  1. Chapter 1Retrieval, prompting or fine-tuning: choosing
  2. Chapter 2Preparing training data
  3. Chapter 3Supervised fine-tuning
  4. Chapter 4Parameter-efficient fine-tuning: LoRA and QLoRA
  5. Chapter 5Instruction tuning and synthetic data
  6. Chapter 6Preference optimisation and DPO
  7. Chapter 7Evaluating before and after training
  8. Chapter 8Capstone: a domain model that beats its baseline
The intro video of the course on the left, the eight chapters in order on the right, the last one in cyan.

Chapter 1

Decide between retrieval, prompting and fine-tuning before you train anything

Retrieval and prompting suit knowledge that changes. Fine-tuning suits behavior you want built into the model. Whichever you pick, you measure it next to a baseline.

A model that almost works

  • The knowledge changesRetrieval or prompting
  • The behavior should be built inFine-tuning

Both paths end at the baseline.

  1. 01

    Diagnose failures first

    Look at how the current model fails, then pick the remedy that fits that failure.

  2. 02

    The cost arithmetic

    Set prompts and fine-tuning side by side, with the numbers of your own case.

  3. 03

    Baselines and noise

    Measure a baseline before training, and learn how far a score moves without any change.

  4. 04

    Limits and the decision record

    Write down what fine-tuning cannot do, the risks, and why you chose it.

A decision fork: changing knowledge goes to retrieval or prompting, built in behavior goes to fine-tuning, and both end at the baseline check.

When retrieval fits better: the RAG course →Cheaper first: the prompt engineering course →

Chapter 2

Prepare the training data and keep the test set out of it

Training data decides what the model learns. This chapter covers the formats, the cleaning, the quality of the labels, the splits and the size of the data.

Example records, invented for this page

  • Train
    • Where is my invoice?IN TWO SPLITS
    • Change my delivery address
    • How do I reset my password?
  • Validation
    • Cancel my subscription
    • Update my phone number
  • Test
    • Where is my invoice?IN TWO SPLITS
    • Report a damaged parcel

The rule: a record sits in one split only. When the same text is in training and in test, the test score rewards memory, not skill.

  1. 01

    Record formats

    How a training example is written down for the model.

  2. 02

    Cleaning

    Remove duplicates and broken records before they teach the wrong thing.

  3. 03

    Label quality

    Check that the answers you train on are the answers you want.

  4. 04

    Splits and leakage

    Keep training, validation and test apart, and find the places where they mix.

  5. 05

    Size, tokens and cost

    Count what the data will cost to train on before you start.

Seven example records in three splits. One record appears in both the training and the test split and is outlined in cyan.

Chapter 3

Supervised fine-tuning: read the loss curves to see when training stops helping

Training loss keeps falling as the model fits the examples. Validation loss falls too, and then turns up once the model starts to memorize. One common reading: the lowest point of the validation curve is where to stop.

An illustration of a shape, with no measured values

Training lossValidation lossDotted line: lowest validation loss, one common stopping point

loss / training steps

  1. 01

    The training objective

    What the model is asked to get right at each step.

  2. 02

    Steps, batch size and learning rate

    The three settings that shape a run most.

  3. 03

    Reading loss curves

    Tell a healthy run from a model that has started to memorize.

  4. 04

    Memory for full fine-tuning

    Work out what a full run needs before you rent anything.

  5. 05

    Templates and sequence length

    Keep the prompt format and the length limits consistent.

Training loss falls all the way, validation loss falls and then rises, and a dotted line marks the lowest validation point.

Chapter 4

LoRA and QLoRA train a small fraction of the numbers in a matrix

Full fine-tuning updates all weights. LoRA keeps the matrix frozen and learns a small low-rank change beside it, and QLoRA does that on a compressed base. Try the arithmetic yourself.

How many numbers does LoRA train?

Both matrix shapes are examples for this page, not the shapes of a named model.

Example matrix (rows x columns)
Rank

Frozen matrix, not trainedThe two thin matrices LoRA trains (drawn thicker for a higher rank, not to scale)

Numbers in the matrix
16,777,216
Numbers LoRA trains
65,536
Share of the matrix
0.39%
Times fewer
256

Matrix 4,096 x 4,096, rank 8: LoRA trains 65,536 numbers, 0.39% of the matrix, 256 times fewer.

The rule: a matrix with d rows and k columns holds d x k numbers. LoRA freezes it and trains two thin matrices, one d x r and one r x k, which is r x (d + k) numbers. The share is the trained numbers divided by all the numbers in the matrix.

  1. 01

    The low-rank idea

    Learn a small change beside a big matrix instead of rewriting it.

  2. 02

    Rank, alpha and target modules

    Choose how large the change is and which layers get one.

  3. 03

    Quantized base models (QLoRA)

    Keep the frozen base in compressed form so training needs less memory.

  4. 04

    Merging and serving

    Fold the adapter into the base model, or serve it beside the base.

  5. 05

    LoRA or full fine-tuning

    Decide which one your case needs, and write down why.

An interactive count of trained numbers: pick an example matrix and a rank and read how many numbers LoRA trains compared with the whole matrix.

Chapters 5 and 6

Instruction data, synthetic data and preference pairs each teach something different

Chapter 5 is about teaching a model to follow instructions and about data a stronger model generates. Chapter 6 moves to preferences, from RLHF to the DPO loss, which you work through by hand.

Examples, invented for this page

  1. Instruction tuningPROMPTSummarize this ticket in one sentence.ANSWERThe customer cannot find the invoice for March.
  2. Synthetic dataA stronger model drafts the examples, and you read a sample before you train on them.AUDIT A SAMPLE
  3. Preference pairReply to a customer who asks for a refund.CHOSENThanks for writing. I have started the refund; it should reach you in five working days.REJECTEDRefunds are handled by another team. Please contact them.DPO learns directly from pairs like this one.
  1. 01

    Instruction tuning

    Teach the model to follow a request and answer in the format you need.

  2. 02

    A stronger model as data source

    Generate examples with a stronger model, and audit a sample of them.

  3. 03

    Rights and contamination

    Check that test items did not leak into the generated data.

  4. 04

    The DPO loss by hand

    Work the preference loss through on a small example, then read the result.

Three kinds of training example: an instruction with its answer, a generated batch with one checked sample, and a preference pair with a chosen and a rejected answer.

The whole preference pipeline: the RLHF course →

Chapter 7

Evaluate before and after: count what the tuning fixed and what it broke

A better average can hide a broken case. The chapter has you freeze the protocol first, then compare the tuned model with the baseline case by case.

Example counts, invented for this page: 100 test cases

A two by two table of one hundred example test cases: right or wrong before tuning against right or wrong after it, with totals below.
Tuned rightTuned wrong
Baseline right62right both times5broken by the tuning
Baseline wrong21fixed by the tuning12wrong both times
Right before
67%
Right after
83%
Fixed minus broken
+16
  1. 01

    A frozen protocol

    Fix the test set and the scoring before the first run, and keep them.

  2. 02

    Fixed and broken

    Count the cases the tuning repaired and the cases it damaged.

  3. 03

    Regression and slices

    Look at groups of cases as well as the overall score.

  4. 04

    Judges and humans

    Know when a model can grade the answers and when a person must.

A two by two table of one hundred example test cases: right or wrong before tuning against right or wrong after it, with totals below.

Chapter 8

The capstone: a domain model that beats its baseline

You scope the target, prepare the data, plan the runs, evaluate against the baseline and write the memo.

The capstone in five steps

  1. 01Scope and target
  2. 02Data
  3. 03The run plan
  4. 04Evaluate against the baseline
  5. 05The memo

The goal: compare the tuned model with the baseline on your frozen test.

The five lessons of the capstone chapter as five stations, from the scope to the memo.

How you learn

A coach that asks about your tuning choices, and a certificate

In the Academy, an AI coach you talk to by voice follows the lessons.

AI coachAIby voice
  1. It asks you to explain

    Per the app, the coach asks follow-up questions after a lesson and tests what you understood about training and evaluation.

  2. Your notes carry over

    You save notes, and the app starts your next session from them.

  3. A certificate at the end

    At the end there is a certificate, or a confirmation of participation, depending on your path through the course. It is a PDF with a verification code, checkable by anyone on a public page. Mirage issues it, and it is not a state-recognized qualification.

Three nodes on one thread: the coach asks about your choices, your notes carry over, and the certificate ends the course.

All rules for the certificate →

Questions about the fine-tuning course

  • Who is the fine-tuning course for?

    People who build AI features: software engineers and technical product people. The level is Masters.

  • What is the difference between fine-tuning and retrieval?

    Retrieval brings knowledge to a model at question time, and fine-tuning changes how the model behaves. Chapter 1 teaches you to diagnose failures, weigh the cost and write down the decision.

  • What is LoRA?

    LoRA keeps a model's weight matrix frozen and trains two thin matrices beside it, so far fewer numbers change. The island on this page counts them for two example matrices. QLoRA applies the idea to a compressed base model, in chapter 4.

  • Does the course cover DPO?

    Yes. Chapter 6 covers preference optimization and DPO, from RLHF to the DPO loss, and it includes the role of beta and the reference model. The RLHF course goes through the whole preference pipeline.

  • How do I know the tuned model is better?

    By measuring both models on a protocol you froze before training. Chapter 7 covers precision, recall and F1, the cases fixed and broken, regression and slices, and when judges and humans grade.

  • What is the capstone project?

    The capstone: a domain model that beats its baseline. You scope the target, prepare the data, plan the runs, evaluate against the baseline and write a memo.

  • Is the course in English?

    The course is in English only, and so is this page. No German version exists.

  • Do I get a certificate?

    Yes, with one note: depending on how you went through the course, it ends with a certificate or a confirmation of participation. A verification code lets anyone check it on a public page. The page about certificates says it is not state-recognized.