September 17, 2026
Scaling Inference

LoRA and QLoRA Fine-Tuning: A 12-Step Practical Tutorial

LoRA and QLoRA Fine-Tuning A 12-Step Practical Tutorial

LoRA freezes the pre-trained weights and trains small rank decomposition matrices injected into each Transformer layer. QLoRA adds 4-bit quantization of the frozen base, cutting memory far enough to fine-tune a 65B model on one 48GB GPU. Both produce adapters measured in megabytes, not gigabytes.

  • 10,000xFewer trainable parameters than Adam full fine-tuning on GPT-3 175B
  • 3xLower GPU memory requirement reported in the original LoRA paper
  • 65BParameter model QLoRA fine-tunes on a single 48GB GPU
  • 99.3%Of ChatGPT’s level reached by Guanaco on the Vicuna benchmark
  • 24hSingle-GPU fine-tuning time behind that Guanaco result

The common assumption is that LoRA is the cheap approximation and full fine-tuning is the real thing. The original paper says otherwise. Hu et al. report LoRA performing “on-par or better than fine-tuning in model quality” on RoBERTa, DeBERTa, GPT-2 and GPT-3, while training up to 10,000 times fewer parameters.

If your LoRA run underperforms, the method is rarely the reason. What follows is the twelve-step sequence, the arithmetic behind rank and alpha, and a diagnostic tree for when it goes wrong.

What do you need before you start?

PrerequisiteWhy it mattersTime
A task with a clear evalWithout a metric you cannot distinguish adaptation from memorisation2-4 hours
200-2,000 curated examplesQLoRA’s headline results came from small high-quality sets, not volume1-3 days
Held-out test splitAdapters overfit quickly and quietly30 minutes
Sufficient VRAMLoRA cuts memory around 3x versus Adam full fine-tuning; QLoRA cuts far more
A prompted baseline numberPrompting often wins outright; you need to know what you are beating2 hours

The baseline is the step teams skip, and it is the one that most often makes the whole project unnecessary.

How does LoRA actually work?

It exploits a property the authors call rank-deficiency in language model adaptation.

Instead of updating a weight matrix directly, LoRA holds it frozen and learns two small matrices whose product approximates the update. Rank r controls their size. Because the base never moves, one model can serve many adapters.

Figure 1 — Where the trainable parameters live

FROZENPre-trained weights WBillions of parameters. Never updated. Shared across every adapter you train.
+
TRAINABLEMatrix AShape d x r. Rank r is the dial you set.
x
TRAINABLEMatrix BShape r x d. Together a few megabytes.
At inference: A x B can be merged back into W, so a merged adapter adds zero additional latency — the property that separates LoRA from adapter layers.

Why this is cheap: gradients are only computed for A and B. The optimizer state, which dominates memory in full fine-tuning, shrinks in proportion.

What does QLoRA add on top?

Three memory innovations, all documented in Dettmers et al. (arXiv:2305.14314, May 2023).

  • 4-bit NormalFloat (NF4) — a data type the authors describe as information theoretically optimal for normally distributed weights.
  • Double quantization — quantizing the quantization constants themselves to shave the average memory footprint further.
  • Paged optimizers — absorbing the memory spikes that would otherwise crash a long run.

Gradients backpropagate through the frozen 4-bit base into the LoRA adapters. The paper reports this preserves full 16-bit fine-tuning task performance.

The resulting Guanaco models reached 99.3% of ChatGPT’s performance level on the Vicuna benchmark after 24 hours of fine-tuning on a single GPU. That result came from a study in which the authors fine-tuned more than 1,000 models across 8 instruction datasets.

The twelve steps

Figure 2 — The three phases, and where projects die

STEPS 1-4Decide whether to tune at allEval, baseline, behaviour-vs-knowledge check, base model choiceMost projects should stop here
STEPS 5-8Configure the runRank, alpha, target modules, quantizationCheapest phase to get wrong
STEPS 9-12Train, verify, shipFew epochs, held-out loss, verification, merge decisionWhere overfitting hides

The ordering is deliberate: every step in phase one is cheap and can cancel the project. Nothing in phase two or three can rescue a task that never needed fine-tuning.

Steps 1-4: decide whether to fine-tune at all

  1. Write the eval first. Twenty to fifty examples with expected outputs. It goes wrong when the eval is written after training, because you will unconsciously fit it to whatever you got.
  2. Measure the prompted baseline. Run the base model with a strong prompt against that eval. Fine-tuning must beat this materially to justify its cost.
  3. Confirm it is a behaviour problem, not a knowledge problem. Fine-tuning teaches form, tone and task shape. It is a poor way to inject facts; retrieval handles that far better.
  4. Pick the smallest viable base model. Adapter quality tracks base quality, but a 7B model you can iterate on beats a 70B run you cannot.

Steps 5-8: configure the run

  1. Choose rank r. Start at 8 or 16. Higher rank adds capacity and memory. It goes wrong when teams raise rank to fix a run whose real problem is data.
  2. Set alpha. A common convention is alpha equal to rank, or twice the rank. Alpha scales the update, so changing it changes the effective learning rate.
  3. Select target modules. The original work targets attention projections. Extending to MLP layers raises capacity and cost. Add modules one group at a time.
  4. Enable NF4 with double quantization if memory is the binding constraint. Skip quantization when it is not, since it buys memory at some quality risk.

Steps 9-12: train, verify, ship

  1. Train for very few epochs. Small high-quality sets overfit fast. Two to three epochs is often already past optimal.
  2. Watch held-out loss, not training loss. Training loss falling while eval loss rises is the signature of memorisation.
  3. Verify against the step 1 eval and the step 2 baseline. This is how you know it worked, and it is the only comparison that matters.
  4. Merge or serve separately. Merging removes inference overhead. Keeping adapters separate lets one base serve many tasks.

How should you actually choose rank and alpha?

Rank is a capacity dial, not a quality dial. That distinction is where most tuning time gets wasted.

RankFitsRisk
4-8Tone, format, output style, single narrow taskUnderfits genuinely complex behaviour
16-32Domain adaptation, structured output conformanceThe usual sweet spot; little downside
64+Multi-task adapters, large diverse datasetsOverfitting and catastrophic forgetting rise sharply

Alpha is easier than the discourse suggests. Because the update is scaled by alpha divided by rank, changing rank while holding alpha fixed silently changes your effective learning rate.

Keep the ratio constant when you sweep rank. Otherwise you are running two experiments at once and cannot attribute the result to either.

How do you know it actually worked?

Three checks, run in this order.

  1. Regression check. Run general-capability prompts unrelated to your task. A tuned adapter that has degraded general reasoning is a bad trade you would otherwise discover in production.
  2. Held-out win rate. Compare adapter output against baseline output on unseen examples.
  3. Memorisation probe. Feed a training example with its ending removed. Verbatim completion means you memorised rather than generalised.

Watch for this

The QLoRA authors found that current chatbot benchmarks are not trustworthy for accurately evaluating chatbot performance. Treat any single benchmark number, including your own, as one weak signal rather than a verdict. Your own held-out eval on real task data beats a public leaderboard every time.

What goes wrong, and how do you diagnose it?

SymptomLikely causeFix
Loss barely movesLearning rate too low, or alpha scaling the update to near zeroRaise LR an order of magnitude; check the alpha-to-rank ratio
Output repeats itselfOvertrained on a small setCut epochs; widen data variety
Strong on train, weak on held-outMemorisationFewer epochs, lower rank, more diverse examples
Out-of-memory mid-runOptimizer state spikesEnable paged optimizers; cut sequence length before batch size
General reasoning degradedAdapter overwriting broad behaviourLower rank; narrow target modules; reduce LR
Quantized run worse than 16-bitQuantization compounding an already-marginal setupReproduce in 16-bit first, then quantize

Figure 3 — Diagnostic tree for a disappointing run

Held-out performance is poor. What are the two loss curves doing?
Train down, eval up
Overfitting.Cut epochs first. Then lower rank. Then add data variety. In that order.
Both flat
Nothing is learning.Check the alpha-to-rank ratio, then the learning rate, then confirm target modules are actually attached.
Both down, but model dumber
Catastrophic forgetting.Narrow target modules to attention only, lower LR, reduce rank.
Both down, eval good
Run the memorisation probe.Good curves still hide verbatim recall on small datasets.

Read the curves before touching config. Almost every wasted tuning day starts with someone changing rank before looking at which of these four states they are actually in.

When should you not fine-tune at all?

Four situations, and they cover more real projects than most teams expect.

  • The requirement is factual accuracy. Retrieval grounds answers in sources you control and updates instantly. An adapter bakes facts in at training time and goes stale.
  • The requirement changes weekly. Every change means a retrain and a re-verification cycle. A prompt change is a deploy.
  • You have fewer than roughly 100 examples. Below that, few-shot prompting usually matches or beats an adapter, without the overfitting risk.
  • Nobody has written the eval. Without it you cannot tell success from regression, and you will ship on vibes.

What do experienced practitioners do differently?

They treat data curation as the actual work and the training config as a formality.

The QLoRA authors fine-tuned more than 1,000 models across 8 instruction datasets and multiple model families, and their conclusion points the same way: small, high-quality datasets produced state-of-the-art results, even with smaller models than the previous best.

Two more habits worth stealing. They keep one adapter per task rather than training a single adapter to do several things, because narrow adapters are easier to evaluate and cheaper to retrain. And they version adapters against a pinned base model, since an adapter trained on one base is not portable to another.

A short glossary

Rank (r)
The inner dimension of the two trainable matrices, controlling how much capacity the adapter has.
Alpha
A scaling factor applied to the low-rank update. Because scaling is alpha over rank, the two must be tuned together.
NF4
4-bit NormalFloat, QLoRA’s data type, described by its authors as information theoretically optimal for normally distributed weights.
Double quantization
Quantizing the quantization constants themselves to reduce average memory footprint further.
Paged optimizer
An optimizer that pages state between GPU and CPU memory to survive transient allocation spikes.
Catastrophic forgetting
Loss of previously held general capability as a model is adapted too aggressively to a narrow task.

Where this is heading

This is judgment rather than established fact: the gap between adapter tuning and full fine-tuning will keep narrowing until full fine-tuning becomes a niche operation performed mainly by base model builders.

The economics already point there. An adapter is megabytes, merges without latency cost, and can be swapped per request. Once serving infrastructure treats adapters as routine rather than exotic, keeping many small specialised adapters over one strong base becomes the obvious default.

The counter-argument deserves a hearing. Full fine-tuning still wins where a model must genuinely change its distribution rather than its behaviour, and low-rank updates are by construction a constrained approximation. If your task needs the model to become something different rather than to act differently, that constraint binds. I think that describes a shrinking minority of production work, but it is not nothing.

Key takeaways

  • LoRA freezes base weights and trains injected rank decomposition matrices, cutting trainable parameters by up to 10,000 times versus Adam full fine-tuning on GPT-3 175B.
  • The original paper reports LoRA matching or beating full fine-tuning on RoBERTa, DeBERTa, GPT-2 and GPT-3.
  • LoRA adds no inference latency, because adapters merge back into the base weights.
  • QLoRA’s NF4 quantization, double quantization and paged optimizers together fit 65B fine-tuning onto a single 48GB GPU.
  • Guanaco reached 99.3% of ChatGPT’s Vicuna benchmark level after 24 hours on one GPU.
  • Hold the alpha-to-rank ratio constant when sweeping rank, or you are unknowingly changing the learning rate too.
  • Always measure a prompted baseline first; it frequently makes fine-tuning unnecessary.

Frequently asked questions

What rank should I use for LoRA?

Start at 8 or 16 and only raise it if held-out performance is capacity-limited rather than data-limited. Higher rank adds trainable parameters and memory. Most disappointing runs are fixed by better or more varied training examples, not by a larger rank value.

Is QLoRA worse than LoRA in quality?

The QLoRA paper reports that 4-bit NormalFloat quantization preserves full 16-bit fine-tuning task performance, so the intended answer is no. In practice quantization narrows margins, so reproduce a marginal setup in 16-bit before blaming quantization for a weak result.

How much data do I need to fine-tune with LoRA?

Less than most teams assume. The QLoRA authors found that fine-tuning on a small, high-quality dataset produced state-of-the-art results. A few hundred carefully curated examples usually beats tens of thousands of scraped ones for behaviour and format adaptation.

Can LoRA teach a model new facts?

Badly. Fine-tuning is effective at shaping tone, format and task behaviour, and inefficient at storing knowledge. For factual grounding, retrieval is the better tool, and the two combine well: retrieval supplies the facts while an adapter shapes how they are presented.

Do I need to merge the adapter before serving?

Only if you want zero inference overhead from a single model. Merging folds the low-rank update into the base weights permanently. Keeping the adapter separate costs a little at inference but lets one base model serve many task-specific adapters swapped at request time.

Why did my fine-tuned model get worse at everything else?

Catastrophic forgetting from too much adaptation pressure. Lower the rank, narrow the target modules to attention projections only, reduce the learning rate, and cut epochs. Then re-run a general-capability regression check against the base model to confirm the trade is acceptable.

What does alpha do in LoRA?

Alpha scales the low-rank update before it is added to the frozen weights, with the effective scale being alpha divided by rank. Raising alpha strengthens the adapter’s influence, which behaves much like raising the learning rate. Keep the ratio fixed when you change rank.

Can I use one LoRA adapter with a different base model?

No. The learned matrices are tied to the exact weights and layer shapes they were trained against. Moving an adapter to a different base, or even a different quantization of the same base, produces unpredictable output. Pin the base model version alongside every adapter you ship.

References

    Rafael Ortega
    Rafael holds a B.Eng. in Mechatronics from Tecnológico de Monterrey and an M.S. in Robotics from Carnegie Mellon. He cut his teeth building perception pipelines for mobile robots in cluttered warehouses, tuning sensor fusion and debugging time-sync issues the hard way. Later, as an edge-AI consultant, he helped factories deploy real-time models on modest hardware, balancing accuracy with latency and power budgets. His writing brings that shop-floor pragmatism to topics like robotics safety, MLOps for embedded devices, and responsible automation. Expect diagrams, honest trade-offs, and “we tried this and it failed—here’s why” energy. Rafael mentors robotics clubs, contributes to open-source tooling for dataset versioning, and speaks about the human implications of automation for line operators. When he’s offline, he roasts coffee, calibrates a temperamental 3D printer, and logs trail-running miles with friends who tolerate his sensor jokes.

      Leave a Reply

      Your email address will not be published. Required fields are marked *