W0+αrBAW_0 + \frac{\alpha}{r}BA

LoRA — low-rank adaptation

Read "W zero plus alpha over r, B A". Keep the pretrained weights W₀ frozen and learn a small low-rank correction BA to add to them.

B∈Rd×rB \in \mathbb{R}^{d \times r} and A∈Rr×kA \in \mathbb{R}^{r \times k}, with rr much smaller than dd (written r≪dr \ll d). Their product BABA has the same d×kd \times k shape as W0W_0 but needs only r(d+k)r(d + k) numbers. The factor α/r\alpha/r scales the correction so that changing rr does not require retuning the learning rate.

BB starts at all zeros, so ΔW=BA=0\Delta W = BA = 0 at the first step and training begins from exactly the pretrained model. After training, BABA can be added into W0W_0 once, so running the model costs nothing extra.

Example

d=k=4096,  r=8:8×(4096+4096)=65,536 vs 40962≈16.8Md = k = 4096,\; r = 8: \quad 8 \times (4096 + 4096) = 65{,}536 \text{ vs } 4096^2 \approx 16.8\text{M}

The correction trains about 0.4% as many numbers as the full matrix.

Where the course uses it

Related terms