Short answer
What is LoRA? LoRA (Low-Rank Adaptation) is a technique for fine-tuning large AI models cheaply. Instead of updating all of a model's billions of weights, LoRA freezes the original model and trains two small matrices per layer whose product represents the change. Introduced by Microsoft researchers (Hu et al.) in 2021, it cut trainable parameters for GPT-3 175B by about 10,000× and GPU memory by about 3×, with quality comparable to full fine-tuning. Typical LoRA adapters are just megabytes to a few hundred megabytes, can be swapped like plugins, and add no inference latency once merged. Combined with 4-bit quantization (QLoRA), you can fine-tune an 8B model on a single consumer GPU with about 8–12 GB of VRAM.
Why LoRA exists
Fine-tuning adapts a pretrained model to a task or style. Full fine-tuning updates every weight, which is expensive:
- Memory: with the Adam optimizer in mixed precision, full fine-tuning needs roughly 16 bytes per parameter (weights, gradients and optimizer states), so an 8B model needs over 120 GB before activations.
- Storage: every fine-tuned version is a full copy of the model.
- Compute: updating all weights is slow.
LoRA's insight: the *change* needed to adapt a model usually has a low "intrinsic rank," so it can be represented with far fewer numbers.
How LoRA works
For a weight matrix W (size d × k), LoRA learns an update ΔW = B·A, where:
- A has size r × k
- B has size d × r
- r (the rank) is small, typically 8–64
The layer's output becomes:
h = W·x + (alpha / r) · B·A·x- W stays frozen.
- B is initialised to zero, so training starts from the original model's behaviour.
- alpha scales the update.
- After training, B·A can be merged into W, so inference speed is unchanged.
Worked example: how many parameters?
For one attention projection with d = k = 4,096:
| Method | Trainable parameters | Share |
|---|---|---|
| Full fine-tuning | 4,096 × 4,096 = 16,777,216 | 100% |
| LoRA r = 8 | 2 × 4,096 × 8 = 65,536 | 0.39% |
| LoRA r = 16 | 2 × 4,096 × 16 = 131,072 | 0.78% |
| LoRA r = 64 | 2 × 4,096 × 64 = 524,288 | 3.1% |
Applied across all attention and MLP layers of an 8B model, LoRA at r = 16 typically trains roughly 0.5% of parameters, tens of millions instead of billions.
LoRA vs other fine-tuning methods
| Method | What is trained | Memory | Quality | Best for |
|---|---|---|---|---|
| Full fine-tuning | All weights | Very high | Highest ceiling | Large budgets, major domain shifts |
| LoRA | Low-rank adapters (16-bit base) | Moderate | Close to full fine-tuning for most tasks | Most fine-tuning on capable GPUs |
| QLoRA | LoRA on a 4-bit quantized base | Low | Close to LoRA | Consumer GPUs, large models |
| DoRA (2024) | Decomposes weights into magnitude and direction, LoRA on direction | Slightly above LoRA | Often slightly better than LoRA | When you want extra quality at low rank |
| Prefix / prompt tuning | Small learned prompt vectors | Very low | Lower on hard tasks | Lightweight task adaptation |
| Adapters (bottleneck layers) | Small inserted layers | Low | Good | Older PEFT approach; adds latency |
Other variants include rsLoRA (better scaling at high ranks), LoRA+ (different learning rates for A and B), PiSSA (initialising from principal components) and VeRA (even fewer parameters).
QLoRA: fine-tuning big models on small GPUs
QLoRA (Dettmers et al., 2023) combines LoRA with a 4-bit quantized base model. Its key ideas:
- NF4 (4-bit NormalFloat) data type designed for normally distributed weights.
- Double quantization of the quantization constants to save more memory.
- Paged optimizers to handle memory spikes.
The paper showed a 65B model could be fine-tuned on a single 48 GB GPU. See LLM quantization explained.
How much VRAM do you need?
Approximate requirements for fine-tuning with a short sequence length (around 2K tokens), batch size 1–2 and gradient checkpointing. Longer sequences and bigger batches need more.
| Model size | Full fine-tuning (16-bit + Adam) | LoRA (16-bit base) | QLoRA (4-bit base) | Example GPUs for QLoRA |
|---|---|---|---|---|
| 1–3B | 24–60 GB | 8–12 GB | 4–6 GB | RTX 3060 12 GB |
| 7–8B | 120+ GB | 18–24 GB | 8–12 GB | RTX 4060 Ti 16 GB, RTX 3090 |
| 13–14B | 220+ GB | 32–40 GB | 12–18 GB | RTX 4090 / 5090 |
| 30–32B | 500+ GB | 70–80 GB | 22–30 GB | RTX 5090 32 GB, RTX PRO 6000 |
| 70B | 1+ TB | 150+ GB | 42–50 GB | 2 × 24 GB, RTX PRO 6000 96 GB, H100 80 GB |
Use our VRAM calculator for inference sizing and see best GPU for deep learning. Renting is often easiest for one-off runs; see the GPU cloud price tracker.
Recommended LoRA hyperparameters
| Setting | Typical starting value | Notes |
|---|---|---|
| Rank (r) | 16 (try 8–64) | Higher rank = more capacity, more memory; complex tasks may need 64+ |
| Alpha | Equal to r or 2 × r | Controls update strength; changing r without alpha changes effective learning rate |
| Dropout | 0–0.1 | Small datasets benefit from some dropout |
| Target modules | All linear layers (q, k, v, o, gate, up, down) | Targeting all layers usually beats attention-only |
| Learning rate | 1e-4 to 2e-4 | Much higher than full fine-tuning (around 1e-5) |
| Epochs | 1–3 | More risks overfitting |
| Batch size | Effective 16–64 via gradient accumulation | |
| Scheduler | Cosine or linear with warmup |
Example: LoRA with Hugging Face PEFT
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import LoraConfig, get_peft_model
model_id = "your-base-model"
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="bfloat16", device_map="auto")
config = LoraConfig(
r=16,
lora_alpha=32,
lora_dropout=0.05,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
task_type="CAUSAL_LM",
)
model = get_peft_model(model, config)
model.print_trainable_parameters()
# then train with the Trainer or TRL's SFTTrainerFor QLoRA, load the model with BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4") and call prepare_model_for_kbit_training before adding the adapter.
After training, merge for deployment:
model = model.merge_and_unload()
model.save_pretrained("merged-model")Tools for LoRA fine-tuning
| Tool | Best for |
|---|---|
| Hugging Face PEFT + TRL | Standard, flexible Python workflows |
| Unsloth | Fast, memory-efficient fine-tuning on a single GPU |
| Axolotl | Config-driven training, multi-GPU |
| LLaMA-Factory | Web UI and many models |
| torchtune | PyTorch-native recipes |
| kohya_ss / AI Toolkit | LoRAs for image models (Stable Diffusion, FLUX) |
LoRA for image models
LoRA is hugely popular for Stable Diffusion and FLUX, where small adapters teach a model a new character, object or style from a few dozen images. Image LoRAs are often only 10–200 MB and can be combined with weighting. See What is a diffusion model? and best GPU for Stable Diffusion.
Serving many LoRAs efficiently
Because adapters are small, one base model can serve many customers or tasks. Inference engines such as vLLM and SGLang support multi-LoRA serving, loading different adapters per request. See LLM inference engines compared.
When LoRA is not enough
- Teaching large amounts of new knowledge (LoRA is better at style, format and behaviour than memorising facts; consider RAG).
- Major changes such as a new language or modality may benefit from higher ranks or full fine-tuning.
- Very small datasets may overfit; quality data matters more than settings.
Common mistakes
1. Learning rate too low (copying full fine-tuning values). 2. Targeting only attention layers when all linear layers work better. 3. Wrong chat template during training versus inference. 4. Training too long and overfitting. 5. Poor data: a few hundred high-quality examples often beat thousands of noisy ones. 6. Forgetting to evaluate against the base model.
Frequently asked questions
What does LoRA stand for?
Low-Rank Adaptation, a parameter-efficient fine-tuning method introduced in the 2021 paper "LoRA: Low-Rank Adaptation of Large Language Models."
Is LoRA as good as full fine-tuning?
For most instruction tuning and style adaptation tasks, LoRA gets close. Full fine-tuning can still win when learning large amounts of new information.
What rank should I use for LoRA?
Start with r = 16 and alpha = 16–32. Increase rank for complex tasks or large datasets.
Can I fine-tune a 70B model with LoRA on one GPU?
With QLoRA, yes, on a GPU with roughly 48 GB or more (for example, an RTX PRO 6000 or H100), at short sequence lengths.
Does LoRA slow down inference?
Not once merged into the base weights. Unmerged adapters add a small overhead.
Sources and further reading
- Hu et al., LoRA: Low-Rank Adaptation of Large Language Models (2021)
- Dettmers et al., QLoRA: Efficient Finetuning of Quantized LLMs (2023)
- Liu et al., DoRA: Weight-Decomposed Low-Rank Adaptation (2024)
- Hugging Face, PEFT documentation
- IBM, What is LoRA?




Leave a Reply