06 / 16
Fine-tuning & Adaptation
Changing the weights: when it pays, and which knob to turn.
Climb only as high as you must: prompt, few-shot, RAG for missing knowledge, fine-tuning for behavior, format or cost. RAG adds facts; fine-tuning changes form. Pretraining is almost never the answer.
Keep training a pretrained model on (prompt, ideal response) pairs so it imitates them. It teaches format, style and task behavior; a few thousand curated examples usually beat a million noisy ones.
Freeze the model and train a low-rank update per weight matrix: usually under 1% of parameters, saved as a megabyte-sized adapter. QLoRA stores the frozen base in 4-bit, so big models fine-tune on one GPU.
Humans pick the better of two answers, a reward model learns those preferences, and PPO pushes the model toward high reward while a KL penalty keeps it near the original. It turned GPT-3 into InstructGPT.
Tune a model directly on (prompt, chosen, rejected) pairs with a simple classification-style loss: the RLHF objective without a reward model or an RL loop, so it is cheaper and far more stable than PPO.
Reinforcement learning where a program, not a person, scores each answer (tests pass, result matches). GRPO makes it cheap: sample a group of answers per prompt and reinforce those that beat the group average.
Train a small student to imitate a large teacher, via its probabilities or its generated text, keeping most of the quality on your task at a fraction of the cost and latency.
Use LLMs to generate training or eval data, then filter, dedup and verify it. It's cheap coverage for rare cases, but it inherits the generator's blind spots, so humans still check eval labels.
Quality beats quantity: remove exact and near duplicates, filter junk with heuristics and classifiers, decontaminate against evals, scrub PII and balance the mix. A smaller clean set routinely beats a bigger dirty one.
Fine-tuning on narrow data overwrites what the model already knew, degrading general skills, instruction following and even safety. Mitigate with LoRA, general-data replay, lower learning rates and fewer epochs, and gate on general evals.
Keep training a base model with the plain next-token objective on billions of unlabeled domain tokens so it absorbs a new domain or language; powerful but expensive, and for most enterprises RAG plus SFT wins.
Train your retriever on domain (query, relevant passage) pairs with a contrastive loss, using LLM-generated queries and mined hard negatives. A tuned embedder means re-indexing everything; a tuned reranker doesn't.
Split training across GPUs by data (replicate model, split batch), by state (FSDP/ZeRO shard weights, gradients, optimizer), inside layers (tensor) or across layers (pipeline). Mixed-precision Adam needs ~16 bytes per parameter.