Fine-Tuning
Advanced 13 min read Fine-Tuning

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.

lorapeftadaptersefficient tuningrankfrozen weights
Prerequisites: Dataset Preparation
Before we start

What you will learn

  • Explain how LoRA works
  • Choose rank and targets
  • Serve and swap adapters
Introduction

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.

Motivation

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.
Think about it

Mental model

Imagine

Interchangeable lenses on a camera

Think of

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.

Mechanics

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.

Base
Inject
Train
Save
Swap
Real world

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.
Guidelines

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.
Watch out

Common mistakes

  • Rank guessing (too high → overfit, too low → underfit).
  • Training adapters on an unstable base snapshot.
  • Deploying adapters without per-adapter eval.
Root cause analysis

Common issues

Error
Adapter degrades other skills
Root cause

Target layers too broad

Fix

Restrict targets; lower rank; eval cross-domain.

Error
Adapter won't load on upgrade
Root cause

Base version drift

Fix

Pin base; retrain adapter on the new base.

When things break

Debugging tips

  • Underfit → raise rank/targets or lengthen epochs.
  • Overfit → reduce rank, add augmentation, holdout check.
  • Adapter conflicts → separate bases or merge carefully.
Interviews

Interview checkpoint

Practice

Hands-on lab

Low-Rank LoRA Math
30 min · intermediate
In progress
Objectives
  • 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

0/3 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

LoRA trains…

2

Adapters can share one base model in serving.

Go deeper

Official documentation