Papa Programmer
Lesson 04 of 36

Kinds of fine-tuning

9 min read

Optional

Two questions decide the method

Every fine-tuning method answers two separate questions.

  1. What do the examples teach? A label, a reply to a request, a preference between two replies, or just more text.
  2. Which weights change? All of them, or a small added set.

Keeping the questions apart avoids a common muddle. "LoRA" answers the second question. "Instruction tuning" answers the first. You can combine them, and most practical projects do: instruction examples, trained with LoRA.

What the examples teach

Classification tuning. Each example is a text and one label from a fixed list, such as billing, access or technical. The model gets a small output layer, called a head, that produces one score per label. It is the cheapest kind and the easiest to measure, because an answer is either the right label or not. The Lesson Fine-tune a classifier builds one.

Instruction tuning. Each example is a request and the reply you want. The model learns to follow your kind of request in your style and format. This is how a base model that only continues text becomes an assistant. Fine-tune a model to follow instructions walks through it. Chat tuning is the same idea with several turns, written in the chat format the model expects.

Continued pre-training. The examples are plain text from your field, such as maintenance manuals or legal filings. The goal is the same as pre-training, to predict the next token, but on narrower text. It can help a model with unfamiliar vocabulary. It does not teach a response format, because the text has no requests or replies.

Preference tuning. Each example is a request with a better reply and a worse one. The model learns to prefer the better. It comes after instruction tuning, and Tuning with preferences: RLHF and DPO covers it.

Which weights change

Full fine-tuning updates every weight. It is the most flexible method. It is also the hungriest, because the training run must hold the gradients and optimiser state for all of them in memory, which costs several times the size of the model.

Parameter-efficient fine-tuning freezes the base weights and trains a small added set. LoRALow-rank adaptation. A method that trains small matrices on selected layers while keeping the base model weights frozen. is the most used. You save only the small set, called an adapter, and load it on top of the unchanged base model. The Lessons Why train fewer parameters and How LoRA works explain why this works so well.

How much each method trains

The program below counts the trainable weights for three choices on a model with 32 layers and a width of 4,096, about the size of a 7 billion parameter model. The full count uses the common estimate of 12 times the width squared per layer. The LoRA count adds a rank 8 adapter to two matrices per layer. The head count is a single layer from width to three labels.

python
layers, width = 32, 4096

full = 12 * width * width * layers
lora = 2 * (2 * width * 8) * layers
head = width * 3 + 3

for name, count in [("full fine-tuning", full), ("LoRA, rank 8", lora), ("classification head", head)]:
	print(f"{name:20} {count:>14,} trainable  ({count / full:.4%} of full)")

It prints:

text
full fine-tuning      6,442,450,944 trainable  (100.0000% of full)
LoRA, rank 8              4,194,304 trainable  (0.0651% of full)
classification head          12,291 trainable  (0.0002% of full)

A LoRA adapter here trains less than a tenth of one percent as many weights as full fine-tuning. A head on a frozen model trains almost nothing. These figures are rough, because real models differ in layout, but the scale of the difference is the point.

Share trainedWhat you save
Full fine-tuning100%A full copy of the model
LoRA, rank 8about 0.07%A small adapter file
Classification headabout 0.0002%A small added layer
Trainable weights compared with full fine-tuning

Choosing between them

Use it whenWatch for
Classification headThe output is one label from a fixed listNeeds labelled examples, and a fixed label set
Instruction tuningYou want a style, format or behaviour in repliesExamples must match real requests
Continued pre-trainingThe field has words and facts the model lacksDoes not teach it to answer
Preference tuningReplies are fine but not the ones people preferNeeds pairs, and a sound way to judge them
LoRA or other PEFTYou have limited memory, or several tasksSmall adapters may fall short on large shifts
Full fine-tuningYou have the memory and a large, clean datasetHigher cost, and more forgetting risk
Which method fits which job

When in doubt, start small: a prompt, then a classification head or an instruction-tuned LoRA adapter. Compare each with the untuned model on the same test questions. RAG or fine-tuning? helps with the earlier decision of whether to train at all.

For the library behind the efficient methods, see the Hugging Face PEFT overview.

Two questionsWhat do the examples teach, and which weights change? Answer each separately.
Adapters are smallLoRA trains a tiny fraction of the weights and leaves the base model intact.
Match method to jobA label needs a head, a style needs instruction examples, and new vocabulary needs more text.

Your reading position is saved

0%

0 of 36 complete

Contents

Learning tools