← All news

News / Learn / Fine-tuning

What is LoRA?

You'll be able to explain what LoRA does, when it helps, and how it cuts the cost of adapting a large model.

LoRA stands for low-rank adaptation. It teaches a large model a new skill without changing most of its weights. Instead, it adds a small set of extra weights that sit next to the original ones and learn the change.

Training a full copy of a large model is slow and costly, and it needs a lot of memory. LoRA lets a small team customize a model on modest hardware. You can also keep one base model and swap in different small adapters for different customers or tasks.

A model's weights are large grids of numbers. Full fine-tuning updates every number. LoRA freezes the original weights and leaves them alone.

For each layer it chooses, LoRA adds two small matrices. Their product has the same shape as the layer it changes, but it is built from far fewer numbers. This is the low-rank part: the change is forced into a narrow form. Only these small matrices are trained.

During training, the base model runs as normal and the adapter output is added on top. Training updates only the adapter, so memory use and compute drop sharply. The adapter is usually a few megabytes to a few hundred megabytes, depending on settings.

At inference time, the adapter can be merged into the base weights, or kept separate and loaded on demand. Keeping it separate lets one base model serve many adapters.

A minimal setup with the Hugging Face peft library. The model name is a placeholder. You pass in any causal language model you have access to.

from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM

base = AutoModelForCausalLM.from_pretrained("your-base-model")

config = LoraConfig(
    r=8,              # rank: size of the small matrices
    lora_alpha=16,    # scaling applied to the adapter output
    target_modules=["q_proj", "v_proj"],
    lora_dropout=0.05,
    task_type="CAUSAL_LM",
)

model = get_peft_model(base, config)
model.print_trainable_parameters()  # shows the small trainable share
# Train as usual. Save only the adapter:
model.save_pretrained("my-adapter")

A short sketch to show the idea. Check the official docs of the tool you use.

  • Assuming LoRA fixes bad data Adapters learn from examples. Noisy, inconsistent, or wrong examples produce a model that is confidently wrong. Clean the dataset first.
  • Picking a rank without testing Rank controls adapter capacity. Too low can underfit, too high wastes compute and can overfit. Compare a few values on a held-out eval set.
  • Expecting new facts to stick Fine-tuning is better at shaping style, format, and behavior than at storing facts. For up-to-date or large knowledge, retrieval usually works better.
  • Skipping a baseline Measure the base model on your task before training. Without that number you cannot tell whether the adapter helped.

Learn about quantized LoRA, which runs fine-tuning on a compressed base model. Also study how target modules affect results, and how to merge or serve multiple adapters in production.

Does LoRA change the original model?

No. The base weights stay frozen. The trained adapter is a separate set of weights that you can load or remove.

Is LoRA the same as fine-tuning?

LoRA is one way to fine-tune. Full fine-tuning updates all weights. LoRA updates only a small added set.

Do I need a lot of GPU memory?

Usually much less than full fine-tuning. Memory need still depends on model size, batch size, and sequence length.

Can I use LoRA for images?

Yes. The same idea is applied to diffusion models and vision models, though the target layers differ.

How big is a LoRA adapter?

It is typically a small fraction of the base model. The exact size depends on rank and which layers you adapt.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.