Lesson deck
PEFT, LoRA and QLoRA in depth flashcards
Reviewing needs JavaScript. You can read every card in the list below.
Loading your cards...
Back to the lesson12 cards in this deck
Read all 12 cards as a list
- Front
- How many trainable numbers does a rank-r LoRA adapter have for a d-output, k-input matrix, and what is its limit?
- Back
- r × (d + k), against d × k for a full update. The product B·A has rank at most r, so it can move the layer only within an r-dimensional family: good for narrow changes, weaker for big new skills.
- Front
- Why is B initialised to zero and A random, not both zero?
- Back
- The gradient of each factor depends on the other. With both at zero neither moves. With B at zero and A random, the update starts at zero (the base model) and B receives a non-zero gradient first.
- Front
- What does alpha over r do in a LoRA layer?
- Back
- It multiplies the B·A term, setting how loudly the adapter speaks. Change rank without alpha and the scale changes. PEFT defaults are r=8, alpha=8, so a scale of 1.
- Front
- How do you count a whole model's LoRA parameters?
- Back
- For every adapted matrix add r × (inputs + outputs), then sum over matrices and layers. Narrower matrices (such as grouped-query key and value projections) add less.
- Front
- How do you turn an adapter count into training memory?
- Back
- Multiply by the 16 bytes per trained parameter of states with Adam in mixed precision. A 15-million-parameter adapter is about 0.24 GB. The frozen base adds only its storage.
- Front
- Targets or rank: which do the papers say to change first?
- Back
- Targets. LoRA on all linear layers was needed to match full fine-tuning in the QLoRA study, and rank was close to flat in both papers' tests. Test two ranks on held-out data before raising it.
- Front
- What learning rates did the QLoRA paper use?
- Back
- 2e-4 for the 7B and 13B models, 1e-4 for 33B and 65B, with a bigger batch for the larger ones. One team's setup, not a default: sweep your own.
- Front
- What does NF4 do, and what is the block size in QLoRA?
- Back
- A 4-bit data type fitted to bell-shaped, zero-centred weights, not evenly spaced. Weights are quantised in blocks of 64, each with its own constant, so an outlier harms only its block.
- Front
- What does double quantisation save?
- Back
- It quantises the per-block constants to 8 bits in blocks of 256, cutting their overhead from 0.5 to 0.127 bits per parameter. About 0.11 GB instead of 0.44 GB for a 7B base.
- Front
- What do paged optimisers do, and what stays in 16-bit in QLoRA?
- Back
- They move optimiser state between GPU and CPU memory (unified memory) to survive memory spikes, at the cost of slower steps. The adapter, its gradients and the matrix multiply stay in 16-bit; only storage is 4-bit.
- Front
- When does full fine-tuning beat LoRA?
- Back
- On demanding domains with lots of data, such as code and maths with continued pretraining, where low-rank LoRA substantially underperformed in one study. LoRA forgot less. Ladder: LoRA on all linear layers, then higher rank, then full tune only if the gap justifies the cost.
- Front
- Merge an adapter or keep it swappable?
- Back
- Merge (W + (alpha/r)·B·A) for one dominant adapter: no added latency. Swap for many tenants on one base: small files, shared base, and mixed-task batching is awkward after merging. Merge a 4-bit-trained adapter into a 16-bit copy and re-evaluate.