Skip to content

LoRA Fine-Tuning for Mere Mortals

A language model answers in the average of every style it has ever read. If you need it to answer in one style — your support desk's voice, your house format, the same careful shape every time — you can show it examples and let it adjust: that is fine-tuning. Doing it to every one of the model's billions of numbers is expensive and final. LoRA — Low-Rank Adaptation — freezes the model exactly as it is and learns a small change instead, kept in a small file called an adapter, which can be attached or removed in seconds.

This guide explains how that works and then does it, at the smallest scale that still teaches the mechanism honestly: a model of 82 million parameters, 24 examples, a computer with no graphics card. The examples are support answers from a fictional company about a fictional kettle, every one in the same fixed house style, so that what training bought is easy to see. The guide then asks the trained model questions it never saw, prints its answers next to the untrained model's, and reports the result without varnish: the voice transferred completely, and the facts mostly did not. Both halves of that sentence are the lesson.

The rule that governs everything here is stated in chapter 1 and worked through in chapter 3: train only on data you have the right to use. Your own writing and licensed data, yes; other people's books, inboxes and manuals, no, however easy they are to copy. The lab obeyed the rule the easy way — every example was invented for the occasion — and chapter 10 extends the same rule to images of people, where it becomes a question of consent.

The lab behind this guide ran the real thing: torch 2.14.1, transformers 5.20.2 and peft 0.21.2, installed with pip into a fresh virtual environment on a small Linux machine, training distilgpt2 on CPU. LoRA was configured at rank 8 with alpha 16, attached to the attention layers only: of the model's 82 million parameters, 147,456 were allowed to move. Over 20 passes through the 24 examples the logged loss fell from 3.92 to a noisy plateau around 2.3, and the finished adapter was saved — 591,352 bytes of it — then loaded in a fresh process and put to the held-out test.

What the lab could not do, it did not fake. There was no graphics card, so GPU training is described, not demonstrated. Merging an adapter into a whole model and exporting it to GGUF for other tools (chapter 9) is taught from the documentation and labelled as such. Teaching an image model a face or a style (chapter 10) is a survey of a neighbouring craft, not a lab: the mechanism is the same, the tools are different, and the chapter says plainly that none of it was run. criteria.md keeps the full ledger of what was run and what was only read.

What this guide covers

  • What fine-tuning is — changing a model's behaviour with examples, and the honest comparison with the two cheaper tools: prompting and RAG
  • What LoRA actually does — frozen weights, two thin tables, and the two numbers that size an adapter: rank and alpha
  • The dataset is the lesson — the rights rule in practice, and the three properties that decide what data teaches: consistency, correctness, coverage
  • Preparing examples — the instruction format, JSONL, and grading the model on its answers only
  • The training run, knob by knob — the setup, the script, and each setting explained: learning rate, epochs, batch, rank, seed
  • Watching the loss — reading the one number training gives you: what its fall means, what its plateau means, and its three blindnesses
  • Saving and loading an adapter — what is actually in the adapter folder, the config that names its base model, and loading it in a fresh process
  • Before and after — held-out questions, the base model beside the adapted one, and the unvarnished verdict: style 5/5, facts 0/4
  • Merging and exporting — folding an adapter into a whole model, and the road to GGUF — documented, not run, and labelled so
  • Image LoRA — the same idea for pictures: what transfers, what changes, and the consent question (a survey, not a lab)
  • The neighbours — full fine-tuning, prompt engineering, RAG, and LoRA's parameter-efficient cousins, honestly compared
  • Limits — the base model as a ceiling, facts held as soft tendencies, and an adapter you cannot open and audit
  • Troubleshooting — the loss that will not fall, the loss that falls too far, the right voice with the wrong facts, and the adapter that changes nothing
  • Glossary — the terms, collected in one place

What it doesn't cover

Training on data you have no right to use — that is not a harder chapter of this book; chapter 1 explains the rule and chapter 3 works it through. Training a model to imitate a living person's voice, or an image model to depict a real person without their consent, is likewise out. Production fine-tuning at scale — multi-billion parameter models, GPU clusters, hyperparameter sweeps, serving adapters to many users — is pointed at, not taught; this guide stays with one person, one small model, and a run they can hold in their head.

How to use this guide

Read chapter 1 before training anything: it may talk you out of it, correctly, in favour of a better prompt or a retrieved document. Chapters 3 and 4 are the real work — the dataset is the lesson, and an hour there is worth a week of knob-turning. Run the lab's training (chapter 5) before adapting it to your own data, so you have seen one complete, honest run, loss curve and disappointing facts and all. Chapter 8 is not the optional chapter: test on questions the model never saw, beside the untrained model's answers, or you do not know what you bought. The lab's dataset is lora-lab/dataset.jsonl, its scripts are lora-lab/train_lora.py and lora-lab/compare.py, its transcripts live in lora-lab/transcripts/, and its notes are examples/lab-notes.txt.


Part of the series

This guide is one of the For Mere Mortals guides: plain-language guides to the tools programmers and makers use.

Related guides:

License

The writing in this guide is licensed under CC BY 4.0. Code examples and lab scripts are licensed under the MIT License.