PEFT & LoRA
Tune a sliver, keep the stem
Parameter-efficient fine-tuning (LoRA especially) updates small adapter matrices rather than the whole model: cheaper, faster, and serial-compatible. Adapters become portable artifacts you can A/B and swap.
What you will learn
- Explain how LoRA works
- Choose rank and targets
- Serve and swap adapters
What is this?
PEFT freezes the base model and tunes small parameter sets. LoRA adds low-rank matrices (rank r) to attention projections, drastically cutting trainable parameters and VRAM. Adapters are small portable artifacts: separate tuned behaviors sharing one base — served, A/B'd, and swapped independently.
Why do you need it?
- A fraction of the training cost and tokens.
- Base remains intact; adapters don't forget other worlds.
- Multiple adapters share one base for cheap multi-behavior service.
- Fast iteration: adapter swap day-of.
Mental model
Interchangeable lenses on a camera
LoRA adapters
Same camera body (base model), screw on a portrait lens (adapter for style A) or a wide macro (style B). Lenses are small, portable, and swap in seconds — versus buying a whole new camera body for each shot style. That's the LoRA design.
How it works
- Freeze base weights; inject low-rank matrices on target layers (attn/q,k,v,o).
- Train only the adapters (rank r, often 8-128).
- Save the adapter file (tiny, additive).
- At inference: merge adapters into the base or apply at runtime.
- Swap/eval adapters per behavior.
LoRA anatomy.
In production
- One base model serves style/tone adapters per team.
- Open-source LoRA home in small GPU environments.
- Domain intents served as adapters evaluated per region.
Best practices
- Start with small rank; scale only if underfit.
- Eval each adapter against the frozen base baseline.
- Pin base model + adapter versions together.
- Prefer adapters for multi-behavior single-base serving.
Common mistakes
- Rank guessing (too high → overfit, too low → underfit).
- Training adapters on an unstable base snapshot.
- Deploying adapters without per-adapter eval.
Common issues
Adapter degrades other skillsTarget layers too broad
Restrict targets; lower rank; eval cross-domain.
Adapter won't load on upgradeBase version drift
Pin base; retrain adapter on the new base.
Debugging tips
- Underfit → raise rank/targets or lengthen epochs.
- Overfit → reduce rank, add augmentation, holdout check.
- Adapter conflicts → separate bases or merge carefully.
Interview checkpoint
Hands-on lab
- Factor a weight delta into two low-rank matrices
- Update the frozen weights with an alpha-scaled product
- Count parameters saved versus full fine-tuning
Low-Rank LoRA Math
30 min · intermediate
Quick quiz
LoRA trains…
Adapters can share one base model in serving.