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 and :
The paper treats each attention projection of GPT-3 175B as a 12,288 × 12,288 matrix. Below, , , and are the query, key, value and output projections.
| Computation | Trainable numbers | |
|---|---|---|
| one full | 12,288 × 12,288 | 150,994,944 |
| LoRA, | 1 × (12,288 + 12,288) | 24,576 |
| LoRA, | 4 × 24,576 | 98,304, or 0.065% of |
| LoRA, | 8 × 24,576 | 196,608, or 0.13% of |
| and at , all 96 layers | 96 × 2 × 98,304 | 18,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 and count at and .
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 .