Should I fine-tune a model?

3 min readMarkdown

Probably not. Fine-tuning changes how a model behaves, not what it knows, and most problems people try to fix with it have cheaper fixes.

When you need it

Fine-tuning trains an existing model a little further on your own examples. It is good at teaching a consistent format, tone or narrow skill. It is bad at adding facts, because the model learns the facts loosely and still makes things up around them.

Try these first, in this order:

  1. 1Better prompt
  2. 2Add documents with RAG
  3. 3Bigger model
  4. 4Fine-tune
Each step costs more effort than the one before. Most people stop at step two or three.
  1. A better prompt. Put clear instructions and two or three examples of good output in the system promptSystem promptStanding instructions placed before the conversation.Read more. This fixes most format and tone problems in an afternoon.
  2. RAGRAGRetrieval-augmented generation. The app finds relevant passages and pastes them into the prompt.Read more. If the model needs to know your documents, give it the documents at question time. How do I chat with my documents? shows how. It stays current when the documents change, and fine-tuning does not.
  3. A bigger model. If the model is not smart enough, move up a class. Which size of model do I need? shows what each step buys you.

Fine-tuning earns its place when you have hundreds of good examples of a narrow task, and prompting still gets it wrong. Classic cases are a strict output format, a house writing style, or a small model you want to do one job as well as a bigger one.

The catch

Fine-tuning needs a good dataset, and building one is most of the work. A few hundred clean examples beat thousands of messy ones. Plan for the data to take longer than the training.

QLoRA, briefly

QLoRA is the method that made fine-tuning possible on home hardware. It loads the base model at 4-bit and freezes it, so those weightsWeightsThe full set of a model's parameters, stored in a file.Read more never change.

Then it trains a small set of extra weights, called a LoRA adapter, that sit beside the frozen layers and nudge their output.

The adapter is often only tens or hundreds of MB, and you can load it on top of the base model or merge it in to make a new file. You train a sliver of the model while the rest sits still, which is why it fits in consumer memory.

Memory needed

QLoRA on a single machine handles 7 to 8B on 12 to 16 GB, up to about 14B on 24 GB. That covers the small class and the bottom of the mid class.

Rule of thumb

For QLoRA, you need roughly the memory to run the model at 4-bit, plus a few GB for training state and a short context. Longer training examples need more.

On an NVIDIA GPU, most people use Hugging Face's PEFT and TRL libraries, or tools built on them such as Unsloth and Axolotl. On a Mac, MLXMLXApple's machine learning framework for Apple silicon.Read more has LoRA training built into its language model package. Which NVIDIA card should I get? and Is a Mac good for local AI? cover the hardware.

Try it

Before you train anything, write your ten best examples into the system prompt and run your ten-prompt test. If the score barely moves, fine-tuning on the same examples is unlikely to move it much further.

Full fine-tuning stays in the datacenter

Full fine-tuning updates every weight in the model. Training needs the weights, their gradients and the optimizer's state in memory at the same time, at higher precision than you run them.

With the usual setup that comes to about 16 bytes per parameterParameterOne learned number inside a model. An 8B model has about eight billion of them.Read more before any context. An 8B model needs about 128 GB, and a 70B needs over 1 TB. That is a job for rented datacenter GPUs, not a home machine. Local or cloud: which should I use? covers when renting makes sense.

Go deeperThat's enough

Why LoRA works

The changes fine-tuning makes to a big weight matrix turn out to be simple. They can be written as the product of two thin matrices. LoRA trains only those two thin matrices, which often hold well under 1% of the model's parameters, and gets most of the benefit of updating the whole thing.

What can go wrong

Train too long on a small dataset and the model memorises it, then answers everything in the style of your examples. Train on a narrow task and the model can lose general skills it had before. Keep a held-out set of prompts, test before and after, and stop early.

Running a fine-tuned model

A merged model can be converted to GGUFGGUFThe single-file model format used by llama.cpp and the apps built on it.Read more like any other and run in Ollama or LM Studio. Some runtimesRuntimeThe software that loads a model file and runs it.Read more, including llama.cpp, can also load a LoRA adapter on top of a base GGUF at start-up. What is llama.cpp? covers the options.