AI Guides · 7 min read

What Is LoRA Fine-Tuning? How Low-Rank Adapters Work

LoRA fine-tuning freezes pretrained weights and trains small low-rank adapters. See how it differs from full fine-tuning and RAG, and where QLoRA fits.

Two slim glowing adapter strips attaching to a large frozen lattice core, on a dark background, with no text or logos

LoRA (Low-Rank Adaptation) fine-tuning is a parameter-efficient method that freezes a pretrained model’s weights and injects small trainable rank-decomposition matrices into existing layers. Because the original weights stay untouched, LoRA trains far fewer parameters than full fine-tuning and lets teams merge or swap lightweight adapters without duplicating the whole model.

Why is full fine-tuning expensive to train and deploy?

Full fine-tuning updates every parameter in a pretrained model and outputs a full-size checkpoint for each downstream task. Training all weights across a multi-billion-parameter model demands large GPU memory pools to store weights, gradients, and optimizer states simultaneously.

Deployment storage multiplies that overhead. In their October 2021 paper (arXiv:2106.09685), Microsoft researchers led by Edward Hu wrote that “deploying independent instances of fine-tuned models, each with 175B parameters, is prohibitively expensive.” Supporting many downstream tasks with full fine-tuning requires storing and serving a separate 175B-parameter copy for each one. Selecting a foundation model already involves major compute trade-offs, as covered in our guide on how to choose an AI model, and LoRA avoids multiplying that footprint for each task.

How does LoRA work under the hood?

LoRA freezes a Transformer’s pretrained weights and learns a low-rank update represented by two smaller matrices. As the Hu et al. ICLR 2022 publication states, the method “freezes the pre-trained model weights and injects trainable rank decomposition matrices into each layer of the Transformer architecture, greatly reducing the number of trainable parameters for downstream tasks.”

The low-rank decomposition (W0 + BA)

In Section 4.1 of the paper, a pretrained weight matrix W0 of size d × k keeps its original values while its update is constrained to ΔW = BA, where B is d × r, A is r × k, and rank r ≪ min(d, k). During training, W0 receives no gradient updates and only A and B train, changing the forward pass to h = W0 x + BAx.

The paper initializes A with random Gaussian values and B to zero so ΔW = BA starts at zero, then scales ΔWx by α / r. In its standard experimental setup, LoRA targets the query and value attention matrices (Wq and Wv), yielding |Θ| = 2 × L̂_LoRA × d_model × r trainable parameters, where L̂_LoRA counts the adapted weight matrices.

What the 2021 paper reported on GPT-3 175B

In the arXiv:2106.09685 abstract (v2 dated October 16, 2021), the authors reported: “Compared to GPT-3 175B fine-tuned with Adam, LoRA can reduce the number of trainable parameters by 10,000 times and the GPU memory requirement by 3 times.” Trainable |Θ| in that setup “can be as small as 0.01% of |Φ0|,” where |Φ0| is the full model parameter count.

Those ratios reflect historical 2021 measurements on GPT-3 175B with Adam and will vary across 2026 architectures and optimizers. Within its tested benchmarks, the paper also reported: “LoRA performs on-par or better than fine-tuning in model quality on RoBERTa, DeBERTa, GPT-2, and GPT-3, despite having fewer trainable parameters, a higher training throughput, and, unlike adapters, no additional inference latency.”

Merging adapters vs. swapping them at inference

LoRA avoids extra inference latency because BA shares the shape of W0. After training, you can merge W = W0 + BA into a single weight matrix with zero added network depth, or keep adapters separate so one frozen base model serves multiple portable task adapters. Microsoft’s reference code is published in the official LoRA repository.

How Hugging Face PEFT defines and configures LoRA

Hugging Face PEFT implements LoRA by wrapping a frozen base model with small low-rank update matrices. Its PEFT LoRA conceptual guide (checked November 2026) explains that LoRA works by “represent[ing] the weight updates with two smaller matrices (called update matrices) through low-rank decomposition,” while “The original weight matrix remains frozen.”

PEFT cites five practical benefits: drastically fewer trainable parameters, multiple lightweight portable LoRA models sharing one frozen base, compatibility with other PEFT methods, zero added inference latency once merged, and strong task quality. On quality, Hugging Face states: “Performance of models fine-tuned using LoRA is comparable to the performance of fully fine-tuned models.”

Although LoRA can target any weight subset, PEFT notes that “for simplicity and further parameter efficiency, in Transformer models LoRA is typically applied to attention blocks only.” Trainable parameter count depends mainly on rank r and original matrix shapes, with lower r reducing parameters. Developers configure LoraConfig and get_peft_model() using fields such as r, target_modules, lora_alpha (scaling matching lora_alpha / r), bias, and modules_to_save, then call merge_and_unload for standalone deployment or keep a PeftModel to unmerge, swap, or combine adapters.

What is QLoRA and how does it reduce memory further?

QLoRA cuts fine-tuning memory by backpropagating gradients through a frozen 4-bit quantized base model into 16-bit LoRA adapters. Introduced by Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, and Luke Zettlemoyer in May 2023 (arXiv:2305.14314), “QLoRA backpropagates gradients through a frozen, 4-bit quantized pretrained language model into Low Rank Adapters (LoRA).”

In Section 3 of the paper, QLoRA separates storage from compute: base weights remain frozen in 4-bit (usually NF4), get dequantized to BFloat16 (BF16) during layer operations for 16-bit matrix multiplication, and send weight-gradient updates only to BF16 LoRA adapters. Three techniques named in the abstract drive those savings:

  1. 4-bit NormalFloat (NF4): A 4-bit data type “that is information theoretically optimal for normally distributed weights.”
  2. Double Quantization: Quantizing the quantization constants “to reduce the average memory footprint by quantizing the quantization constants.”
  3. Paged Optimizers: Memory paging “to manage memory spikes.”

The 2023 paper reported that QLoRA “reduces memory usage enough to finetune a 65B parameter model on a single 48GB GPU while preserving full 16-bit finetuning task performance,” compared with their statement that “regular 16-bit finetuning of a LLaMA 65B parameter model requires more than 780 GB of GPU memory.” Those figures reflect the 2023 LLaMA 65B study under its specific setup. Hugging Face’s bitsandbytes documentation covers this 4-bit workflow; see our guide on what quantization in AI is for the broader 4-bit and 8-bit landscape.

LoRA vs. full fine-tuning vs. RAG: when to use each

LoRA, full fine-tuning, QLoRA, and retrieval-augmented generation (RAG) address distinct goals across weight adaptation, GPU memory, and dynamic facts.

Method Base weights Trainable or updated state Per-task artifact Best fit
Full fine-tuning Updated All pretrained parameters Full model copy Maximum flexibility when hardware budget fits
LoRA Frozen Low-rank matrices A and B Small adapter weights Behavior, style, or format on shared base
QLoRA Frozen (4-bit NF4) BF16 LoRA adapters Small adapter weights Adapting large models on tighter GPU memory
RAG Frozen External search index Indexed chunks Fresh, private, or rapidly changing facts

Full fine-tuning fits projects that already have the compute and storage for full checkpoints and want every layer trainable. The LoRA paper notes that high rank across all matrices approaches full fine-tuning expressiveness, though LoRA is not guaranteed to match full training on every 2026 model. When your goal is producing a smaller standalone model, model distillation takes a different path from adapters.

LoRA and QLoRA fit teams shaping tone, output format, or task behavior without duplicating base weights per task, though adapters are a poor way to store large, fast-changing document collections. RAG, explained in what RAG is, leaves weights untouched and retrieves passages from an external index at query time so facts update without retraining. Consistent with our RAG vs. fine-tuning guide, production systems often combine RAG for live documents with LoRA for consistent response behavior.

FAQ

Frequently asked questions below summarize practical trade-offs around LoRA latency, QLoRA precision, RAG, and adapter configuration.

Does LoRA slow down inference compared to the base model?

LoRA adds no inference latency when adapter matrices are merged back into the base model via W = W0 + BA. Once merged, the resulting model has the exact same layer depth and compute path as the original checkpoint. Keeping unmerged adapters in a PeftModel lets one base model swap tasks at runtime, while merging removes adapter overhead.

What is the difference between LoRA and QLoRA?

LoRA leaves the frozen pretrained base model in its standard training precision, such as 16-bit, and trains small low-rank matrices on top. QLoRA stores frozen base weights in 4-bit precision, usually 4-bit NormalFloat (NF4), uses Double Quantization and Paged Optimizers to curb memory spikes, and updates BF16 LoRA adapters after dequantizing weights during computation.

Can LoRA replace RAG for custom company knowledge?

LoRA is a poor substitute for RAG when answering questions from large or frequently changing document collections. Because LoRA stores adaptations inside model weights instead of a live searchable index, updating facts requires another training run. RAG keeps weights frozen, fetches current passages at query time, and pairs well with LoRA when you also need custom formatting.

Which layers does LoRA usually target in a Transformer?

LoRA can adapt any subset of linear weight matrices, though common setups focus on Transformer attention layers. In the original Microsoft paper, the authors applied LoRA to the query and value projection matrices (Wq and Wv) for simplicity. Hugging Face PEFT likewise notes that LoRA is typically applied to attention blocks for efficiency and simplicity.

What does rank r control in LoRA fine-tuning?

In LoRA fine-tuning, rank r controls the inner dimension of the two trainable matrices A and B, where r is much smaller than the base matrix dimensions. Lower r yields fewer trainable parameters and smaller adapter files, whereas higher r increases adapter capacity. In Hugging Face PEFT, parameter count depends mainly on r and matrix shapes.

Sources

The definitions, formulas, and historical benchmarks in this guide come from the primary papers and official documentation below.

Written by

Chunyu Cai

Chunyu Cai is the CEO of Lotook, LLC and an entrepreneur who writes about AI models, agents, and how they change everyday work. Chunyu holds a master's degree from Imperial College London.