COMP5046 — Natural Language Processing

Lecture 9: Training — Pretraining, Finetuning & PEFT

Foundation models · full fine-tuning cost · LoRA low-rank deltas · QLoRA on quantised bases · adapters & prompt tuning · choosing a recipe.

How to use: learn each method's parameter footprint and trade-offs · close the page and answer Recall lines.

Foundation

Pretraining vs finetuning

RecallWhat objective is used in pretraining a decoder-only LM, and what changes during finetuning?

All weights move

Full finetuning

RecallWhy does full FT on a 7B model usually need multi-GPU memory?

Tune few, freeze many

Parameter-Efficient Fine-Tuning (PEFT)

RecallWhat property of the finetuning update justifies PEFT?

Low-rank deltas

LoRA — Low-Rank Adaptation

x W_0 (frozen) d × d A (r×d) B (d×r) trainable + h h = W_0 x + B A x
LoRA: frozen \(W_0\) computes the main path; a rank-\(r\) bypass \(BA\) adds a learnable delta. At init \(B=0\) so the model starts identical to pretrained.

RecallWrite the trainable parameter count of one LoRA-adapted \(d \times d\) matrix.

Quantise the base

QLoRA — LoRA on a quantised model

RecallWhy is QLoRA more memory-efficient than vanilla LoRA?

Other PEFT families

Adapters, prompt tuning, prefix tuning

RecallPrompt tuning vs prefix tuning: what is added, and where?

Practical recipe

When to use what

RecallWhy is LoRA preferred over adapters when inference latency matters?

Lab

Workshop & materials

Quick practice

For a \(d=4096\) weight matrix with LoRA rank \(r=8\), how many trainable parameters does LoRA add (vs full FT)?
\(d^2 = 16{,}777{,}216\) (same as full FT)
\(2dr = 65{,}536\) — roughly 250× fewer
\(r^2 = 64\)
\(d + r = 4104\)
What is the key memory trick that distinguishes QLoRA from plain LoRA?
QLoRA uses a higher LoRA rank
QLoRA replaces Adam with SGD
QLoRA keeps the frozen base model in 4-bit quantised form
QLoRA finetunes all layers, LoRA only finetunes the last
Why is LoRA usually preferred over adapters when inference latency matters?
\(W_0 + BA\) can be merged into one matrix — no extra layers at inference
LoRA has more trainable parameters
LoRA does not need a pretrained base
Adapters cannot be applied to attention layers

Chapter quizzes

Retrieval practice for this lecture.

Open Quiz Hub Chapter flashcards