How do you fine-tune a large model with LoRA/PEFT, and why has it become the default over full fine-tuning?
Quick Answer
LoRA freezes the base weights and trains small low-rank adapter matrices injected into attention/MLP projections — typically <1% of parameters. You get near-full-fine-tune quality with a fraction of the GPU memory, checkpoints of a few hundred MB instead of the full model, and cheap multi-tenant serving by swapping adapters.
Detailed Answer
LoRA reparameterizes weight updates as W + BA where B and A are low-rank (r=8-64). With PEFT: wrap the model in get_peft_model(model, LoraConfig(...)), train normally (Trainer/TRL), and save only the adapter. QLoRA goes further — base model in 4-bit, adapters in bf16 — bringing 70B fine-tunes into single-node reach. Why it won: (1) memory — no optimizer states for frozen weights, which is where most training memory goes; (2) artifact size — adapters are MBs, so per-customer/per-task variants are storable and auditable; (3) serving economics — engines like vLLM and LoRAX hot-load many adapters over one shared base model, making 50 fine-tunes cost roughly one deployment; (4) merge option — merge_and_unload() folds adapters into the base for zero inference overhead when you only need one variant. Know the knobs: rank r and lora_alpha scale capacity, target_modules choose which projections get adapters, and full fine-tuning still wins when you must shift the model's behavior broadly (new language/domain) rather than specialize a task.
Code Example
from peft import LoraConfig, get_peft_model
cfg = LoraConfig(r=16, lora_alpha=32, target_modules=['q_proj','v_proj'],
lora_dropout=0.05, task_type='CAUSAL_LM')
model = get_peft_model(base_model, cfg)
model.print_trainable_parameters() # ~0.2% trainable
# after training:
model.save_pretrained('adapters/support-bot-v3') # few hundred MBInterview Tip
Tie LoRA to serving economics (many adapters, one base model in vLLM/LoRAX) — interviewers hiring for platform roles care more about that than the low-rank math.