AI Systems

Fine-tuning — Specializing the Model

Fine-tuning adapts a pre-trained model's weights using task-specific demonstrations. Where prompting and RAG inject knowledge at inference time, fine-tuning bakes behavior directly into the weights: consistent style, structured output adherence, domain-specific reasoning patterns, and shorter prompts since learned behavior replaces lengthy instructions. The cost is curated data, compute, evaluation overhead, and an extra model artifact to version and serve.

Quick reference
What it is
Updating a pre-trained model's weights on task-specific examples, instead of only steering it through the prompt.
Mental model
Prompting is giving someone instructions for one task; fine-tuning is actually training them — slower and more expensive up front, but they don't need the instructions repeated every time afterward.
Key numbers
LoRA typically updates well under 1% of total parameters (rank 8–64); a few hundred to low thousands of high-quality examples routinely beats tens of thousands of noisy ones.
Reach for it when
A quantified prompt-engineering and RAG baseline has already been tried and measurably falls short — never as the first tool reached for.
A curated dataset drives a LoRA or full fine-tune, producing an adapted checkpoint that must pass a held-out evaluation gate before it ships Curated Dataset quality over quantity LoRA / Full fine-tune Adapted checkpoint Held-out eval gate rank r, alpha
A checkpoint that fails the held-out gate never ships — the gate is not optional QA, it's the difference between "fine-tuned" and "fine-tuned and verified."

Full fine-tuning

Every parameter is updated on the task-specific dataset. This gives maximum expressiveness and suits a target domain that diverges significantly from the base model's pretraining distribution — turning a general-purpose model into a specialized biomedical or legal one, for instance. The costs are real: full-parameter gradients and optimizer states need several times the model's parameter count in GPU memory, catastrophic forgetting of general capabilities is a genuine risk without careful data mixing, and the result is a full model checkpoint to serve and version on its own. Proposing full fine-tuning without justifying why PEFT is insufficient is a weak system-design answer, not a strong one.

Parameter-efficient fine-tuning (PEFT)

LoRA injects trainable low-rank decomposition matrices (rank r, typically 8 to 64) into the attention projection layers while freezing the base weights — updating well under 1 percent of total parameters. QLoRA adds 4-bit quantization of the frozen base model, making it possible to fine-tune a 70B-parameter model on a single high-memory GPU. Because the base weights never move, one shared base model can serve many task-specific adapters, hot-swapped per request — the standard production pattern for multi-tenant fine-tuning, and the default answer unless full fine-tuning is explicitly justified.

Instruction and preference tuning

RLHF trains a separate reward model on human preference pairs, then optimizes the policy model against that reward using PPO. DPO (Direct Preference Optimization) reformulates the same objective as a single supervised loss directly on preference pairs, removing the reward model and the RL loop entirely — which is why it has largely displaced RLHF for practical fine-tuning pipelines outside frontier labs. These methods tune for preferred behavior — helpfulness, tone, refusal calibration — rather than narrow task accuracy, and are a distinct lever from task-specific supervised fine-tuning.

Productionizing this pattern

What changes past a demo

Real-world applications

Embedded applications

Gotchas

Field notes