Post-training
Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8
7 cards in “8.2 Parameter-efficient fine-tuning” · whole deck
8.2 Parameter-efficient fine-tuning
- Besides instruction tuning, when might we fine-tune a pretrained model?To adapt it to a new task, domain (legal, medical) or language/variety whose data wasn’t sufficiently represented in pretraining.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 213
- Why is it hard to fine-tune all the parameters of very large LMs?Every batch must backpropagate through enormous numbers of parameters in many huge layers, which is very expensive in compute, memory and time; many labs can’t do it.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 214
- What is parameter-efficient fine-tuning (PEFT)?Fine-tuning that freezes most parameters and updates only a small chosen subset.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 214
- What is the intuition of LoRA?Low-Rank Adaptation: freeze the dense weight matrices (e.g. \(W^Q, W^K, W^V, W^O\)) and instead learn a low-rank update with far fewer parameters.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 214
- How does LoRA update a frozen matrix \(W\) of shape \([k \times d]\)?It learns \(A\) \([k \times r]\) and \(B\) \([r \times d]\) with \(r \ll \min(d, k)\), replacing \(W + \Delta W\) by \(W + AB\). The forward pass becomes \(h = xW + xAB\).
With small r, A and B have far fewer parameters than W. - Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 214
- What are the advantages of LoRA?Much lower hardware requirements (no gradients for most parameters); no extra inference time, since \(AB\) has the shape of \(W\) and can be added into it; and modules for different domains can be swapped in and out by adding or subtracting them.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, pp. 214–215
- To which matrices was LoRA originally applied?Only the attention matrices: \(W^Q, W^K, W^V, W^O\). Many variants exist.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 8, §8.2, p. 215
Source
- Daniel Jurafsky and James H. Martin. Speech and Language Processing. 3rd edition (draft). https://web.stanford.edu/~jurafsky/slp3/