What are LoRA and PEFT?
What are LoRA and parameter-efficient fine-tuning (PEFT), and why are they used?
TL;DR
Full fine-tuning updates every weight of a model, which needs a lot of GPU memory and produces a full copy of the model per task. PEFT methods freeze the base model and train only a small number of new parameters. The most popular is LoRA (low-rank adaptation): for selected weight matrices W, it learns a low-rank update ΔW = B·A, where A and B are thin matrices (rank r, often 8–64). That's often under 1% of the parameters, so training needs far less memory, and each task's adapter is just megabytes. QLoRA goes further by loading the frozen base in 4-bit precision, so large models fit on a single GPU.
Key points
- Inference: either merge the adapter into W (no extra latency), or keep adapters separate and swap them per request, serving many tasks from one base model.
- Hyperparameters: rank r (capacity), alpha (scaling), and which layers get adapters (attention projections, often MLP layers too).
- Quality is usually close to full fine-tuning for narrow tasks (format, style, classification, domain language). Full fine-tuning can still win for large shifts in capability.
- Other PEFT methods: prefix tuning, prompt tuning, and (IA)³. LoRA dominates in practice.
- Tooling: Hugging Face
peft, Unsloth and Axolotl; hosted fine-tuning APIs often use LoRA-like methods behind the scenes. - Data quality matters more than the method: a few thousand clean, representative examples beat a large noisy set.
Example
from peft import LoraConfig, get_peft_model
config = LoraConfig(r=16, lora_alpha=32, lora_dropout=0.05,
target_modules=["q_proj", "v_proj"], task_type="CAUSAL_LM")
model = get_peft_model(base_model, config)
model.print_trainable_parameters()
# trainable params: 6.8M || all params: 8.0B || trainable%: 0.085Common follow-ups
- Why does a low-rank update work? The weight changes needed to adapt a pretrained model to a task have low "intrinsic rank", so a small update captures most of them.
- How do you check for overfitting or forgetting? Hold out a validation set, and also re-run general benchmarks or your broader eval set.
What interviewers look for
Tip
Frozen base plus a small trained update, the ΔW = B·A idea, the memory and storage savings, and QLoRA's 4-bit trick.
- Red flag: thinking LoRA makes the model itself smaller or faster at inference.