Juan Pablo García
All writing
Explainer5 steps · scroll to play

How fine-tuning with LoRA works

Fine-tuning adapts a pretrained model to your task. LoRA does it by freezing the original weights and training two small matrices beside them.

  1. 1

    Start from a pretrained model

    A language model is mostly large weight matrices. This one, W, has 4096 × 4096 entries, about 16.8 million numbers, and it already knows language.

  2. 2

    Full fine-tuning changes everything

    Classic fine-tuning updates every weight. The optimizer also keeps extra state per weight, so memory and cost grow with the whole model.

  3. 3

    Freeze W, add two thin matrices

    LoRA leaves W untouched and adds B (4096 × 8) and A (8 × 4096). Their product has W's shape but only 65,536 trainable numbers. B starts at zero, so training begins exactly at the pretrained model.

  4. 4

    Train only A and B

    Gradients flow to A and B alone. The change B·A can only express a few directions, its rank, which is usually enough for a new task.

  5. 5

    Merge or swap

    Add B·A into W for zero extra cost when serving, or keep adapters separate and swap them per task on one base model.

Start from a pretrained model

A language model is mostly large weight matrices. This one, W, has 4096 × 4096 entries, about 16.8 million numbers, and it already knows language.

Full fine-tuning changes everything

Classic fine-tuning updates every weight. The optimizer also keeps extra state per weight, so memory and cost grow with the whole model.

Freeze W, add two thin matrices

LoRA leaves W untouched and adds B (4096 × 8) and A (8 × 4096). Their product has W's shape but only 65,536 trainable numbers. B starts at zero, so training begins exactly at the pretrained model.

Train only A and B

Gradients flow to A and B alone. The change B·A can only express a few directions, its rank, which is usually enough for a new task.

Merge or swap

Add B·A into W for zero extra cost when serving, or keep adapters separate and swap them per task on one base model.

In short

  • LoRA trains well under 1% of the parameters, so gradients and optimizer state shrink and it fits on smaller GPUs. The frozen weights still have to fit; QLoRA stores them in 4 bits.
  • The rank (8 here) sets how much the adapter can change. Higher rank, more capacity and more memory.
  • QLoRA goes further by storing the frozen base in 4-bit, so even larger models fit on one GPU.
  • Try prompting first, then measure. On a structured-extraction task, a larger model prompted with 10 examples beat a LoRA-tuned 1.5B model at 100 labeled examples (55% vs 32% exact records); at 2,000 the fine-tuned model was 2 points behind, within noise, while reading 29× fewer input tokens. Write-up: “When does LoRA fine-tuning beat a good prompt?”
  • It works because the weight change needed to adapt a large model appears to have low rank: Hu et al.'s hypothesis, motivated by the low intrinsic dimension Aghajanyan et al. (2021) measured.

References

  1. Hu et al. (2021). LoRA: Low-Rank Adaptation of Large Language Models. ICLR 2022.
  2. Dettmers et al. (2023). QLoRA: Efficient Finetuning of Quantized LLMs. NeurIPS.
  3. Aghajanyan et al. (2021). Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning. ACL.
  4. García (2026). lora-vs-prompting: learning curve, predictions and code.

Share

Keep reading

All writing

Want to work together?