insideout Get Pro
Learn
AI engineering · Module 05

Training and Tuning

How a base model is trained, then turned into an assistant.

Start here · Lesson 01

Building a pretraining dataset

Where training text comes from, and how it's cleaned and mixed.

Start lesson

LessonsAll lessons

  1. 01 Building a pretraining datasetWhere training text comes from, and how it's cleaned and mixed. Free
  2. 02 PretrainingNext-token prediction over a huge pile of text, and what the model learns from it. Free
  3. 03 Scaling lawsHow loss falls with parameters, data and compute, and how to split a budget. Free
  4. 04 Fixed-budget experimentsCompare ideas fairly by giving each the same time on the same machine. Pro
  5. 05 Instruction tuningTurning a base model into one that follows requests. Pro
  6. 06 Learning from preferencesRLHF and DPO, trained on people's choices between two answers. Pro
  7. 07 Rewarding checkable answersReinforcement learning on maths and code, where a program grades the answer. Pro
  8. 08 Adapters and LoRATrain a small add-on instead of the whole model. Pro
  9. 09 Prompt, retrieve or fine-tuneHow to choose between the three ways to adapt a model to your task. Pro
  10. 10 Inside the RL step: policy gradients and PPOHow a reward becomes a change in the model's weights. Pro
  11. 11 Training across many GPUsHow one training run spreads across many GPUs. Pro
  12. 12 DistillationTrain a small model on a big one's outputs. Pro
  13. 13 A fine-tuning run end to endData, training, evaluation and release for one fine-tuned model. Pro

Build it yourself · on your own machine

A small model fine-tuned with LoRA

A LoRA adapter that teaches a 0.5B model to sort bank customers' messages into 77 intents, measured against the best prompt you can write.
  1. Load banking77 from Hugging Face (13,083 bank customer messages, each labelled with one of 77 intents) and set 200 test messages aside.
  2. Score Qwen2.5-0.5B-Instruct on them with an instruction that lists all 77 intents, then with five examples added, counting exact matches.
  3. Turn 2,000 training rows into chat-format prompt and reply pairs, and train a LoRA adapter on q_proj and v_proj with TRL's SFTTrainer.
  4. Log training and validation loss, keep a checkpoint after each pass, and pick one by its validation score.
  5. Score that adapter once on the 200 test messages, and ask it five general questions to see what the tuning cost it.
  6. Price each setup by its prompt tokens per request, and note the adapter's size on disk.

How you'll know it worksA table of exact-match accuracy, prompt tokens per request and size for the bare prompt, five examples and the adapter on the same 200 test messages, with the adapter ahead of the best prompt.

Python with transformers, peft, trl and datasets. A 0.5B model trains with LoRA on a laptop (Apple Silicon or a recent CPU) in an evening, with no API. Uses lessons 05 to 13.