Shaf Lab

Fine-tuning

Continuing to train an existing model on a smaller, task-specific dataset to change its behavior.

Fine-tuning continues training an existing model on a smaller, task-specific dataset so it learns a new skill, output format, tone, or domain style. The most common form is supervised fine-tuning: you supply example inputs paired with ideal outputs, and training nudges the weights so the model produces outputs like them. The base model's broad abilities stay, and the new data shapes how they are used.

Fine-tuning is better at teaching behavior than at adding facts. It reliably teaches a format, a classification scheme, a house style, or a narrow skill. It is unreliable for knowledge that changes or must be cited, because facts learned this way are hard to update, hard to verify, and can be recalled wrongly with confidence. The usual rule is fine-tune for skill, retrieve for knowledge.

Data quality decides the outcome. A few hundred to a few thousand clean, consistent, representative examples usually beat a large noisy pile. Hold out a test set before training, compare against a well-prompted base model, and check for regressions on general tasks, since narrow training can erode abilities you did not test, an effect known as catastrophic forgetting.

Try prompting and retrieval first; they are cheaper to iterate and easier to undo. Fine-tune when prompts have plateaued, when you need a smaller and cheaper model to match a larger one on a narrow task, or when you need consistent output that instructions alone cannot hold. Parameter-efficient methods make this practical on modest hardware.

LoRA

Low-rank adaptation: fine-tuning by training small add-on matrices while the original weights stay frozen.

LoRA, short for low-rank adaptation, is a parameter-efficient way to fine-tune a model. The original weights stay frozen. For selected weight matrices, usually in the attention layers, LoRA trains two small matrices whose product forms a low-rank update added to the original. Only a tiny fraction of the parameters train, often well under one percent, which cuts memory needs and makes training much cheaper.

The resulting adapter is small, often a few megabytes to a few hundred, so you can keep one per task or customer and swap them on a shared base model. An adapter can also be merged into the base weights after training, so it adds no cost at inference. The main settings are the rank, which sets the update's capacity, and which matrices get adapters. LoRA usually comes close to full fine-tuning on narrow tasks, though it can fall short when the new task is very different from the base model's training.

QLoRA

LoRA fine-tuning on top of a base model stored in 4-bit precision, to fit large models on modest hardware.

QLoRA combines LoRA with quantization. The frozen base model is stored in 4-bit precision, while the small LoRA adapters train at higher precision on top of it. Its 2023 paper added a 4-bit number format suited to the typical distribution of model weights, a second round of quantization for the scaling constants, and paged optimizer memory to absorb spikes.

The result is that fine-tuning a model with tens of billions of parameters fits on a single large GPU, and smaller models fit on consumer cards, with quality close to 16-bit LoRA on many tasks. Training is somewhat slower because weights are dequantized on the fly, and as with any quantization, check quality on your own evaluation set.