13/31
Part 3 of 6 · Scale, count and placementLearn and do

Count the numbers in A and B

A full update to one weight trains in × out numbers. LoRA trains AA and BB:

r×in⏟A+out×r⏟B=r (in+out)\underbrace{r \times \text{in}}_{A} + \underbrace{\text{out} \times r}_{B} = r\,(\text{in} + \text{out})

The paper treats each attention projection of GPT-3 175B as a 12,288 × 12,288 matrix. Below, WqW_q, WkW_k, WvW_v and WoW_o are the query, key, value and output projections.

ComputationTrainable numbers
one full WqW_q12,288 × 12,288150,994,944
LoRA, r=1r = 11 × (12,288 + 12,288)24,576
LoRA, r=4r = 44 × 24,57698,304, or 0.065% of WqW_q
LoRA, r=8r = 88 × 24,576196,608, or 0.13% of WqW_q
WqW_q and WvW_v at r=4r = 4, all 96 layers96 × 2 × 98,30418,874,368
# Wq and Wv at r = 4, 96 layers
total = 96 * 2 * 4 * (12_288 + 12_288)
print(f"{total:,}", total * 2 / 2**20, "MiB at 2 bytes a number")
print(f"{round(175e9 / total):,}", "times fewer than the full model")
18,874,368 36.0 MiB at 2 bytes a number
9,272 times fewer than the full model

That last row of the table is the paper's whole budget for its study of which layers to adapt.

  • At 2 bytes a number it's 36 MiB: the roughly 35MB checkpoint the paper reports, against 350GB for a full fine-tune.
  • The paper rounds the 9,272 to 10,000.
  • The paper's GPT-3 results table lists LoRA runs with 4.7M and 37.7M trainable parameters. Those are the same WqW_q and WvW_v count at r=1r = 1 and r=8r = 8.

In the editor, write lora_params(shapes, r): how many numbers train when LoRA at rank r adapts every weight in shapes, a list of (out, in) pairs. Each weight adds r(in+out)r(\text{in} + \text{out}).