What LoRA does
Instead of updating every weight matrix W (which is huge), LoRA learns a low-rank delta ΔW = B A where B is d×r and A is r×k for a small r (typically 8-64). The original W is frozen; only B and A train. The number of trainable parameters drops by 100-1000x. Inference: W' = W + B A, applied at runtime or merged into W.
Why LoRA wins
- Trainable params: 0.1-1% of full fine-tune.
- VRAM: training a 7B with LoRA fits on a single 24GB GPU; full fine-tune needs 8x A100.
- Composability: you can swap LoRA adapters at inference (different style per request) without reloading the base model.
- Storage: a LoRA adapter is ~50MB for a 7B model. Full fine-tune is 14GB.
The hyperparameters
r(rank) — capacity. 8 for very small adaptations, 16 default, 32-64 for harder tasks.lora_alpha— scaling factor. Effective LR scaling =alpha / r. Common:alpha = 2*r.target_modules— which layers to adapt.q_proj, k_proj, v_proj, o_projfor attention;gate_proj, up_proj, down_projfor MLP."all-linear"targets every Linear in the model.lora_dropout— usually 0.05-0.1.