Fine-tuning

Tiny Adapters

One layer of Robo's brain is a grid of 32 × 32 = 1,024 knobs. It is great at its old job. To learn a new job, do we really have to turn all 1,024 knobs? A LoRA adapter clips on two thin strips of knobs instead, and multiplies them into a whole grid of changes.

The old grid stays locked. Only the thin strips A and B learn. Press Train adapter and watch how much of Job B it learns.

How to play: choose a job and an adapter size (the rank), then press Train adapter. Compare with turning every knob (full fine-tune).

Inside the layer step 0

Blue = plus, orange = minus. B is tall and thin, A is short and wide. Multiplied together they paint a full 32 × 32 grid of changes.

Job learned
0%
Knobs trained
-
Full fine-tune
-

How much of the job is learned

LoRA adapterfull fine-tune (all 1,024 knobs)

Strength of each "direction" in the change (singular values)

Any grid of changes can be split into simple "directions". The adapter can never have more than rank of them.

Score for every adapter size

Challenges

Tiny but mighty: learn at least 90% of Job B while training fewer than 25% of the knobs a full fine-tune needs.
Count the directions: with rank 1, look at the singular values. How many bars are not zero?
Backpack: save a good adapter for Job B and one for Job C, then swap between them.
Melt it in: merge an adapter into the layer and check the score stays the same.

What just happened?

How it works

  1. The layer turns 32 numbers in into 32 numbers out using its grid W.
  2. Each new job is "a different grid": the old one plus a hidden change made of a few strong directions and a little fuzz.
  3. The adapter starts with A random and B all zeros, so at first it changes nothing.
  4. Robo shows the layer 160 examples of the new job, measures the mistakes, and nudges only A and B.
  5. "Job learned" = how much of the old layer's mistake on 300 new inputs the adapter has fixed.
For grown-ups: what's really going on

LoRA (Hu et al., 2021) freezes a pretrained weight W0 ∈ ℝd×d and learns h = (W0 + (α/r)·BA)x with B ∈ ℝd×r, A ∈ ℝr×d. Here d = 32, α = 4, A ~ 𝒩(0, 1/d), B = 0 so training starts exactly at the pretrained model. Trainable parameters: 2dr versus d².

  • Task: linear regression y = W*x + ε with W* = W0 + ΔW*; ΔW* has singular values (2.2, 1.5, 0.9) for Job B and (2.0, 1.1) for Job C plus i.i.d. fuzz (σ = 0.02). MSE, Adam (lr 0.02), full batch of 160; "job learned" = 1 − ‖Ŷ−Y‖² / ‖Y0−Y‖² on 300 test inputs.
  • Gradients: with G = ∂L/∂ΔW = (2/n)EᵀX, ∂L/∂B = (α/r)·G·Aᵀ and ∂L/∂A = (α/r)·Bᵀ·G.
  • rank(BA) ≤ r always; the singular-value chart (Jacobi eigen-decomposition of ΔWᵀΔW) shows exactly r non-zero values. The hypothesis behind LoRA is that fine-tuning updates have low intrinsic rank, which this toy builds in.
  • Merging: W = W0 + (α/r)BA gives zero inference overhead; keeping adapters separate allows instant task switching with one shared base (multi-LoRA serving). QLoRA adds a 4-bit quantised base.