Wandering Giants Compute · Learn
Guide

What Is LoRA and QLoRA? A Practical Guide

The short answer

LoRA (Low-Rank Adaptation) freezes a model's weights and trains small low-rank matrices added to its layers, cutting trainable parameters to well under 1%. QLoRA does the same on a base model quantised to 4-bit, so a 70B model fine-tunes on one 80 GB GPU instead of needing more than a terabyte of memory.

LoRA paper
Hu et al., 2021 (arXiv 2106.09685)
QLoRA paper
Dettmers et al., 2023 (arXiv 2305.14314)
Trainable parameters (8B, r=16, all linear)
≈ 42 million, about 0.5%
Base weights, 16-bit LoRA
2 bytes per parameter
Base weights, QLoRA (NF4)
≈ 0.5–0.6 bytes per parameter
70B QLoRA total VRAM
≈ 45–60 GB (one 80 GB card)
Typical learning rate
1e-4 to 2e-4

LoRA and QLoRA are the reason most people can fine-tune large language models at all. Instead of updating billions of weights, you train a few million new ones and leave the original model frozen. This guide explains how both methods work, what they cost in GPU memory, which settings to start with, and when each is the right call. It sits within our wider guide to GPU model training.

What is LoRA?

LoRA (Low-Rank Adaptation) is a fine-tuning method that freezes a pretrained model's weights and learns a small update for selected weight matrices, expressed as the product of two thin matrices. It was introduced by Hu et al. in 2021 (arXiv 2106.09685).

Take one weight matrix W in a transformer layer, of shape d × k. Full fine-tuning learns a change ΔW of the same shape, d × k numbers. LoRA instead writes ΔW = B × A, where B is d × r and A is r × k, and r (the rank) is small, typically 8 to 64. The layer's output becomes W·x + (α/r)·B·A·x. W never changes; only A and B are trained.

The saving is large. For a 4,096 × 4,096 attention projection:

ApproachTrainable numbersArithmetic
Full update16,777,2164,096 × 4,096
LoRA, r = 16131,07216 × (4,096 + 4,096)
LoRA, r = 64524,28864 × (4,096 + 4,096)

At r = 16 that is 0.8% of the matrix. Across a whole model the ratio is similar. For Llama 3.1 8B with adapters on every linear layer at r = 16, the count works out to about 42 million trainable parameters, roughly 0.5% of 8 billion. (Per layer: q and o projections 16 × 8,192 each, k and v 16 × 5,120 each, gate and up 16 × 18,432 each, down 16 × 18,432; summed and multiplied by 32 layers ≈ 42M.)

Why does a low-rank update work? The LoRA authors found that the change fine-tuning makes to a pretrained model tends to have low "intrinsic rank": most of the useful adjustment lives in a few directions. You are steering a model that already knows language, not teaching it from scratch.

What is QLoRA?

QLoRA is LoRA applied to a base model that is stored in 4-bit precision. It was introduced by Dettmers et al. in 2023 (arXiv 2305.14314) and is implemented in the bitsandbytes library.

QLoRA adds three ideas on top of LoRA:

  • 4-bit NormalFloat (NF4). A 4-bit data type designed for weights that are roughly normally distributed. The frozen base is stored in NF4 and dequantised to BF16 on the fly for each matrix multiply.
  • Double quantisation. The scaling constants used for 4-bit blocks are themselves quantised, saving roughly another 0.4 bits per parameter.
  • Paged optimisers. Optimiser state can page to CPU memory during spikes, which avoids out-of-memory crashes on long sequences.

The gradients still flow through the 4-bit base into the 16-bit LoRA adapters. Only the adapters are updated. The result is that the dominant memory cost, the base weights, falls from 2 bytes per parameter to about 0.5–0.6.

How much VRAM do LoRA and QLoRA need?

The base weights dominate, so the rule of thumb is: VRAM ≈ parameters × bytes per parameter for the base, plus a few GB for adapters, their optimiser state, activations and the CUDA context. Full fine-tuning with Adam in mixed precision needs about 16–20 bytes per parameter before activations, which is why it is out of reach on one card for anything but small models.

Model sizeFull fine-tune (16–20 B/param)LoRA, 16-bit base (2 B/param + overhead)QLoRA, 4-bit base (0.5–0.6 B/param + overhead)
3B48–60 GB6 GB + 4–8 GB ≈ 10–14 GB1.5–1.8 GB + 3–6 GB ≈ 5–8 GB
8B128–160 GB16 GB + 4–10 GB ≈ 20–26 GB4–4.8 GB + 4–8 GB ≈ 8–13 GB
14B224–280 GB28 GB + 5–12 GB ≈ 33–40 GB7–8.4 GB + 5–9 GB ≈ 12–17 GB
32B512–640 GB64 GB + 8–16 GB ≈ 72–80 GB16–19 GB + 6–12 GB ≈ 22–31 GB
70B1,120–1,400 GB140 GB + 10–25 GB ≈ 150–165 GB35–42 GB + 10–18 GB ≈ 45–60 GB

Rule-of-thumb estimates for a 2,048-token sequence, small batch, gradient checkpointing on. Long sequences and big batches add activation memory.

Mapping that to rentable cards:

Model sizeQLoRA fits on16-bit LoRA fits on
8BRTX 4090 (24 GB)RTX 4090 at short sequences; L40S (48 GB) comfortably
14BRTX 4090L40S
32BL40S or RTX 4090 at short sequencesA100 or H100 (80 GB), tight; RTX PRO 6000 (96 GB)
70BA100 80GB, H100 (80 GB)B200 (180 GB), or 2–4 × 80 GB cards with FSDP

This table is why QLoRA matters. A 70B model that would need a multi-node cluster to fully fine-tune fits on a single 80 GB GPU, such as the A100 80GB ($3.79/hr) or H100 ($4.99/hr) on Wandering Giants Compute. For a deeper walkthrough of where every gigabyte goes, see how much VRAM you need to fine-tune an LLM.

LoRA vs QLoRA: which should you use?

Use 16-bit LoRA when the base model fits in your GPU's memory with room for activations; use QLoRA when it does not. That is most of the decision.

LoRA (16-bit base)QLoRA (4-bit base)
Base weight memory2 bytes/param≈ 0.5–0.6 bytes/param
Step speedFasterSlower: dequantisation on every forward and backward pass
QualityReferenceClose to 16-bit on most tasks, per the QLoRA paper
Multi-GPUWorks with DDP, FSDP, DeepSpeedWorks with DDP; FSDP with QLoRA is supported in recent releases but fussier
Best for8B–32B models on 48–96 GB cards70B on one 80 GB card; 8–14B on a 24 GB card

Two practical points. First, QLoRA's slower steps can make it more expensive per run than 16-bit LoRA on a bigger card, because GPU time is what you pay for. If an 8B model fits in 16-bit on an L40S, that run is often quicker than QLoRA on the same card. Second, always merge or evaluate against the 16-bit base. The 4-bit quantisation is a training convenience, not the model you ship. Our explainer on quantisation covers what 4-bit does to weights.

Which LoRA settings should you start with?

Start with r = 16, lora_alpha = 32, dropout 0.05, adapters on all linear layers, learning rate 2e-4 with a cosine schedule and 3% warm-up. Those defaults work for most instruction-tuning jobs; change one thing at a time from there.

SettingStart atRaise it whenLower it when
r (rank)16Large, varied dataset; model underfitsSmall dataset; only changing style or format
lora_alpha2 × rUpdates feel too weakTraining is unstable
target_modules"all-linear"–Memory is very tight (try attention only)
lora_dropout0.05Overfitting on small dataLarge dataset (0 is fine)
Learning rate2e-4Loss falls very slowlyLoss spikes or diverges
Epochs1–3Underfitting on small dataEval loss rises (overfitting)

Older guides targeted only the query and value projections. Applying adapters to all linear layers, including the MLP, was one of the QLoRA paper's findings for matching full fine-tuning quality, and it is now the common default.

What does LoRA and QLoRA code look like?

The PEFT library adds adapters; bitsandbytes provides the 4-bit loading; TRL's SFTTrainer runs the training loop. Version assumptions: transformers 4.51+, PEFT 0.15+, TRL 0.20+, bitsandbytes 0.45+.

python
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training

model_id = "meta-llama/Llama-3.1-8B-Instruct"

# QLoRA: 4-bit NF4 base with double quantisation
bnb = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_use_double_quant=True,
    bnb_4bit_compute_dtype=torch.bfloat16,
)
model = AutoModelForCausalLM.from_pretrained(
    model_id, quantization_config=bnb, device_map={"": 0}
)
model = prepare_model_for_kbit_training(model)

lora = LoraConfig(
    r=16, lora_alpha=32, lora_dropout=0.05,
    target_modules="all-linear", task_type="CAUSAL_LM",
)
model = get_peft_model(model, lora)
model.print_trainable_parameters()
# prints trainable params (about 42M) vs all params, about 0.5% for this config

For plain 16-bit LoRA, drop the BitsAndBytesConfig and prepare_model_for_kbit_training lines and load with torch_dtype=torch.bfloat16. Passing peft_config=lora straight to SFTTrainer does the wrapping for you; the full training script is in our step-by-step Llama fine-tuning tutorial.

When training finishes, you have two options for using the adapter:

python
from peft import AutoPeftModelForCausalLM
import torch

# Option 1: merge into a standalone 16-bit model
m = AutoPeftModelForCausalLM.from_pretrained("out/final", torch_dtype=torch.bfloat16)
m.merge_and_unload().save_pretrained("merged-model", safe_serialization=True)
bash
# Option 2: keep it separate and let vLLM load it at serve time
vllm serve meta-llama/Llama-3.1-8B-Instruct --enable-lora \
  --lora-modules support-bot=./out/final --max-lora-rank 16

Option 2 lets one base model carry many adapters, one per customer or task, switched per request by the model name in the API call.

How long does a LoRA or QLoRA run take, and what does it cost?

Estimate compute as 6 × parameters × training tokens FLOPs, divided by the GPU's dense BF16 throughput times a utilisation factor. LoRA skips most weight-gradient work, so 6 × N × T is a conservative upper bound; QLoRA adds dequantisation overhead, which roughly cancels that saving. We assume 35% utilisation for 16-bit LoRA and 25% for QLoRA, and NVIDIA's published dense BF16 peaks (L40S ≈ 362 TFLOPS, A100 312, H100 PCIe ≈ 756).

Workload: 20 million training tokens (for example 10,000 examples × 1,000 tokens × 2 epochs).

JobGPUEstimated GPU-hoursOur price per GPU-hourCost
8B, 16-bit LoRAL40S2.1$1.89/hr$3.97
8B, QLoRAL40S3.0$1.89/hr$5.67
8B, QLoRARTX 40906.5$1.59/hr$10.34
32B, QLoRAH1005.6$4.99/hr$27.94
70B, QLoRAH10012.4$4.99/hr$61.88
70B, QLoRAA100 80GB29.9$3.79/hr$113.32

Compute estimates, not measurements. Prices as of November 2026. Budget 1.5–2× for evaluation, data loading and restarts. Example, 8B 16-bit LoRA on the L40S: 6 × 8×10⁹ × 2×10⁷ = 9.6×10¹⁷ FLOPs ÷ (362×10¹² × 0.35 = 1.27×10¹⁴ FLOP/s) ≈ 7,580 s ≈ 2.1 h. The 8B rows show the point made above: on the same L40S, 16-bit LoRA is estimated to finish sooner than QLoRA. More scenarios are in the cost to fine-tune an LLM.

When is LoRA the wrong tool?

LoRA is the right default for adapting a model's behaviour, but not for everything.

  • Teaching large amounts of new knowledge. Adapters capture behaviour well; facts injected by fine-tuning can be unreliable. Retrieval is often better for documents that change.
  • Changing the tokenizer or adding a language with a new script. That needs new embeddings, and usually continued pre-training of more than the adapters.
  • Continued pre-training on billions of tokens. At that scale full fine-tuning across several GPUs, or a multi-node cluster, is typical.
  • When a prompt would do. If a well-written system prompt with three examples gets you 90% there, try that first. Where the line falls between these options is covered in training vs fine-tuning vs inference.

When renting from Wandering Giants fits

LoRA and QLoRA jobs are short, bursty and single-machine, which suits Wandering Giants Compute: pick an RTX 4090, L40S, A100, H100 or bigger card, choose Root for SSH and Jupyter with CUDA and PyTorch ready, and pay by the minute until you stop. A paused machine keeps your checkpoints for about 3¢ an hour per 50 GB of disk. You can run a sweep across a 4- or 8-GPU machine, one configuration per card. We do not offer multi-node clusters; if your plan has grown into full fine-tuning at 70B scale, a provider with InfiniBand clusters is the better fit.

Frequently asked questions

Is QLoRA worse than LoRA?

Usually only slightly. The QLoRA paper reported results close to 16-bit fine-tuning on its benchmarks, and in practice the gap is small for most instruction-tuning tasks. QLoRA steps are slower because weights are dequantised on the fly, so use 16-bit LoRA when the model fits.

What LoRA rank should I use?

Start with r=16 and lora_alpha=32 on all linear layers. Rank 8 is often enough for style and format changes; rank 32–64 helps when teaching a lot of new material. Higher rank costs little memory but can overfit small datasets.

Can I merge a LoRA adapter into the model?

Yes. PEFT's merge_and_unload adds the adapter's low-rank update into the base weights and returns an ordinary model. Merge onto the 16-bit base, not the 4-bit one, to avoid carrying quantisation error into the final weights.

Does LoRA work for image models too?

Yes. LoRA is widely used to fine-tune Stable Diffusion and FLUX on a subject or style, and the same idea applies: freeze the base, train small low-rank updates to attention layers.

How big is a LoRA adapter file?

Small. An r=16 adapter on all linear layers of an 8B Llama is about 42 million parameters, roughly 84 MB in 16-bit. Compare that with 16 GB for the full model weights.

Can LoRA teach a model new knowledge?

It can, but it is better at teaching behaviour, format and tone than at reliably injecting facts. For answering from documents that change, retrieval usually beats fine-tuning; many teams combine both.

Wandering Giants Compute

Rent the GPU for this, by the minute.

Rent a 24 GB RTX 4090 for an 8B QLoRA run or an 80 GB H100 for 70B, with root access and per-minute billing.

Prepaid credit, billed by the minute, stops itself when credit runs out. Prices in £, $, €, ¥, CA$, A$, CHF and S$; UK prices include VAT.

Keep reading

About this article. Written by the Wandering Giants Compute team, the people who run Wandering Giants Compute. Hardware figures are the manufacturers’ published specifications. Speeds and costs marked as estimates are worked out from those specifications and our current prices, with the method shown; they are not measured benchmarks. Wandering Giants prices are taken live from our price list each time this page is built.

Last reviewed 25 November 2026.