Part 1 of 15 in LLM fine-tuning techniques

LoRA (Low-Rank Adaptation) fine-tunes a large language model by freezing all of its original weights and training two small matrices next to selected layers. Microsoft researchers introduced it in June 2021 and reported that on GPT-3 175B it cut trainable parameters by 10,000 times and GPU memory by 3 times, while matching or beating full fine-tuning (Hu et al., 2021).

10,000x
Fewer trainable parameters than full fine-tuning on GPT-3 175B
LoRA paper, abstract
1.2TB → 350GB
Training VRAM on GPT-3 175B
LoRA paper, Sec. 4.2
350GB → 35MB
Checkpoint size per task (r=4, Wq and Wv)
LoRA paper, Sec. 4.2

What is LoRA?

LoRA is a parameter-efficient fine-tuning (PEFT) method that keeps the pretrained weights frozen and "injects trainable rank decomposition matrices into each layer of the Transformer architecture", in the words of its paper. Only those small matrices are trained and saved, so one base model can serve many tasks, each with its own tiny LoRA file (Hu et al., 2021, abstract).

The problem it targets is storage and memory. Full fine-tuning produces a new model "as many parameters as in the original model" for every task; for GPT-3 that is 175 billion parameters per copy (LoRA paper, Sec. 1). LoRA's answer rests on a hypothesis from the paper: the change in weights during adaptation has a low "intrinsic rank", so it can be written as the product of two thin matrices (Sec. 4.1).

How does LoRA work?

For a frozen weight matrix W0 of size d × k, LoRA learns an update ΔW = BA, where B is d × r, A is r × k, and the rank r is much smaller than d or k. The forward pass becomes h = W0x + BAx (Equation 3). A starts as random Gaussian values and B starts at zero, so the model's output is unchanged when training begins (LoRA paper, Sec. 4.1).

Diagram of LoRA: the input x flows through the frozen pretrained weight W0 and, in parallel, through trainable matrices A (r x k, Gaussian init) and B (d x r, zero init); the low-rank path is scaled by alpha over r and added to W0x to give h

Step by step, per adapted layer:

  1. Freeze W0. It gets no gradient, so the optimizer keeps no state for it. The paper says this is where the memory saving comes from: "we do not need to store the optimizer states for the frozen parameters" (Sec. 4.2).
  2. Add A and B. Both multiply the same input x as W0; their output is added to W0x.
  3. Scale the update by α/r, where α is a constant. The paper sets α to the first r it tries and does not tune it, because with Adam, tuning α is "roughly the same as tuning the learning rate" (Sec. 4.1).
  4. Train only A and B on the task data.
  5. Merge for deployment. Compute W = W0 + BA once and serve it like a normal model. The paper notes this means "we do not introduce any additional latency during inference" (Sec. 4.1). To switch tasks, subtract BA and add another task's B′A′.

Worked example: parameters for one 4096 × 4096 layer at r = 8

A 4096 × 4096 projection, a common size for attention weights in 7B-class models, has 4096 × 4096 = 16,777,216 weights. With LoRA at r = 8:

ShapeParameters
A8 × 409632,768
B4096 × 832,768
LoRA total65,536
Full matrix W04096 × 409616,777,216

65,536 ÷ 16,777,216 = 0.39% of that layer's weights, or 256 times fewer. The general formula is r × (d + k). This is our arithmetic from the paper's shapes (Sec. 4.1); real savings across a model depend on how many layers you adapt.

Which weights should LoRA adapt?

The original paper only adapted attention weights and froze the MLP blocks "for simplicity and parameter-efficiency" (Sec. 4.2). With a fixed budget of 18M parameters on GPT-3 175B, adapting both Wq and Wv at r = 4 gave the best result overall: 73.7% on WikiSQL and 91.3% on MultiNLI, versus 70.4% and 91.0% for Wq alone at r = 8 (LoRA paper, Table 5).

Later work changed that default. The QLoRA paper found that applying LoRA only to query and value projections did not reproduce full fine-tuning for large models, and that "LoRA on all linear transformer block layers are required to match full finetuning performance" (Dettmers et al., 2023, Sec. 4). See QLoRA.

How small can the rank be?

Very small, in the paper's tests. On GPT-3 175B with Wq and Wv adapted, r = 1 scored 73.4% on WikiSQL and 91.3% on MultiNLI; r = 64 scored 73.5% and 91.4% (LoRA paper, Table 6). The authors add a caveat in a footnote: they "do not expect a small r to work for every task or dataset", giving the example of a task in a different language from pretraining (Sec. 7.2).

When was LoRA introduced, and by whom?

LoRA was introduced in "LoRA: Low-Rank Adaptation of Large Language Models" by Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang and Weizhu Chen of Microsoft. It was posted to arXiv on June 17, 2021 (v2 on October 16, 2021) and presented at ICLR 2022 (arXiv 2106.09685; ICLR 2022).

The authors released the loralib package and checkpoints for RoBERTa, DeBERTa and GPT-2 at github.com/microsoft/LoRA (paper abstract).

What results did the LoRA paper report?

On GPT-3 175B, LoRA with 4.7M trainable parameters matched or beat full fine-tuning (175,255.8M parameters) on all three tasks tested. All numbers below are from Table 4 of the paper; the paper gives run-to-run spreads of about ±0.5% on WikiSQL and ±0.1% on MNLI-m.

Method (GPT-3 175B)Trainable paramsWikiSQL acc.MNLI-m acc.SAMSum R1/R2/RL
Full fine-tuning175,255.8M73.889.552.0/28.0/44.5
BitFit14.2M71.391.051.3/27.4/43.5
Adapter (AdapterH)40.1M73.291.553.2/29.0/45.1
LoRA4.7M73.491.753.8/29.8/45.9
LoRA37.7M74.091.653.4/29.2/45.1

Other reported results:

  • GLUE, RoBERTa-large: LoRA with 0.8M trainable parameters averaged 89.0, against 88.9 for full fine-tuning with 355M (Table 2).
  • GLUE, DeBERTa XXL (1.5B): LoRA with 4.7M parameters averaged 91.3, against 91.1 for full fine-tuning (Table 2).
  • Training speed: a 25% speedup on GPT-3 175B, 43.1 tokens/s per V100 versus 32.5 for full fine-tuning (Sec. 4.2, footnote 5).
  • Storage: 100 task-specific models need about 354GB with LoRA instead of 35TB as full copies (Sec. 4.2, footnote 4).

What later research found

A 2024 study, "LoRA Learns Less and Forgets Less" (Biderman et al.), reported that in code and math, with about 100K instruction pairs and 20B tokens of continued pretraining, LoRA "substantially underperforms full finetuning", while it better preserves the base model's skills outside the target domain. It also measured that full fine-tuning learns weight changes with a rank 10 to 100 times higher than typical LoRA settings (Biderman et al., 2024, abstract). The original paper's tests were on NLU, NL-to-SQL, summarization and NLG benchmarks.

How is LoRA different from adapters, QLoRA and BitFit?

All four freeze most of the model, but they differ in what they train and what inference costs. LoRA's low-rank update can be merged into the weights, so it adds no inference latency, while adapter layers add extra sequential computation; the LoRA paper measured up to 30.3% higher latency for adapters on GPT-2 medium at batch size 1 (LoRA paper, Table 1).

What is trainedBase model during trainingExtra inference latency
LoRALow-rank matrices A, B beside chosen weights16-bit, frozenNone after merging (Sec. 4.1)
QLoRALoRA matrices4-bit NF4, frozenSame adapters as LoRA
Adapter TuningNew bottleneck layers inserted in each blockFrozenYes: 20.7% to 30.3% at batch 1, seq. length 128 (LoRA paper, Table 1)
BitFitExisting bias terms onlyFrozen except biasesNone (no new layers)

Prompt-based methods are a separate family. The LoRA paper says prefix tuning "reserving a part of the sequence length for adaptation necessarily reduces the sequence length available" for the task (Sec. 3). See Prefix Tuning and Prompt Tuning.

Which libraries support LoRA?

Hugging Face PEFT implements LoRA through LoraConfig and get_peft_model(), and documents it as "the most common" low-rank adapter method (PEFT methods overview). Hugging Face TRL's SFTTrainer accepts a peft_config=LoraConfig(...) argument to train LoRA adapters directly (TRL SFT Trainer docs).

  • Hugging Face PEFT (docs for v0.22.0, checked Dec. 4, 2026): LoraConfig with r (default 8), lora_alpha (default 8), target_modules, lora_dropout, bias ("none", "all" or "lora_only"), task_type, and options such as use_dora.
  • Hugging Face TRL (v1.19.0): SFTTrainer(..., peft_config=LoraConfig()).
  • AdapterHub adapters also lists LoRA among its methods.
  • microsoft/LoRA: the authors' original loralib package.

How do you use LoRA in code?

This follows the PEFT quicktour and LoRA reference. Class and argument names were checked against the PEFT v0.22.0 docs on Dec. 4, 2026.

from transformers import AutoModelForCausalLM
from peft import LoraConfig, TaskType, get_peft_model

model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B")

config = LoraConfig(
    r=8,                                  # rank of A and B
    lora_alpha=16,                        # update is scaled by lora_alpha / r
    target_modules=["q_proj", "v_proj"],  # W_q and W_v, as in the paper's Sec. 7.1
    lora_dropout=0.05,
    bias="none",
    task_type=TaskType.CAUSAL_LM,
)
model = get_peft_model(model, config)
model.print_trainable_parameters()        # shows trainable vs total parameters

# ... train with transformers.Trainer or trl.SFTTrainer ...

model.save_pretrained("my-lora-adapter")  # saves only the adapter weights
merged = model.merge_and_unload()         # folds BA into W0 for plain inference

PEFT's docs note that merge_and_unload() "is not in-place", so assign its return value (LoRA reference). To follow the QLoRA paper's all-layers finding, pass target_modules="all-linear", which PEFT documents as selecting "all linear/Conv1D modules" except the output layer.

Common pitfalls

  • Adapting too few layers on large models. QLoRA's authors could not match full fine-tuning on LLaMA 7B with LoRA on query and value only; all linear layers were needed (QLoRA paper, Sec. 4, Figure 2).
  • Expecting full fine-tuning results on far-from-pretraining domains. The LoRA paper warns small ranks may not suffice for every task (Sec. 7.2, footnote 6); Biderman et al. measured large gaps in code and math (2024).
  • Training biases and then disabling the adapter. PEFT's docs warn that with bias="all" or "lora_only", "disabling the adapter will not reproduce the base model's output" (LoRA reference).
  • Mixing tasks in one batch after merging. The paper lists this as a limitation: once A and B are merged into W, inputs for different tasks cannot share one forward pass (Sec. 4.2).
  • Forgetting the merge returns a new model. merge_and_unload() is not in-place (PEFT docs).

FAQ

Is LoRA better than full fine-tuning?

In the original paper, LoRA matched or beat full fine-tuning on GPT-3 175B for WikiSQL, MNLI and SAMSum (Table 4) and on GLUE with RoBERTa and DeBERTa (Table 2). A 2024 study found LoRA "substantially underperforms" full fine-tuning in code and math but forgets less of the base model's other skills (Biderman et al.).

What rank should I use for LoRA?

The paper found r = 1 already competitive on GPT-3 175B when adapting Wq and Wv (Table 6), but warns small ranks will not work for every task (Sec. 7.2). PEFT's default is r=8 (PEFT docs). The QLoRA paper used r = 64 (Appendix B.2).

Does LoRA slow down inference?

No, if you merge the weights. The paper computes W = W0 + BA before deployment, which it says adds no latency "by construction" (Sec. 4.1). In PEFT that is merge_and_unload().

How much memory does LoRA save?

On GPT-3 175B the paper reports training VRAM falling from 1.2TB to 350GB, and the per-task checkpoint shrinking from 350GB to 35MB with r = 4 on Wq and Wv (Sec. 4.2). The saving comes from not storing optimizer states for frozen weights.

What does lora_alpha do?

It scales the low-rank update by α/r. The paper says that with Adam, tuning α is roughly the same as tuning the learning rate, so it fixed α instead of tuning it (Sec. 4.1). In PEFT the argument is lora_alpha, default 8.

Can LoRA be combined with quantization?

Yes. QLoRA trains LoRA adapters on top of a frozen 4-bit base model, and PEFT documents LoRA support for bitsandbytes, GPTQ, AQLM, HQQ and other quantized models (PEFT quantization guide).

Which layers does LoRA modify?

Whatever target_modules lists. The original paper adapted only attention weights (Sec. 4.2) and found Wq plus Wv best for a fixed budget (Table 5). QLoRA later reported all linear layers were needed to match full fine-tuning on LLaMA (Sec. 4).

Sources

  • Hu, E. J., Shen, Y., Wallis, P., Allen-Zhu, Z., Li, Y., Wang, S., Wang, L., Chen, W. "LoRA: Low-Rank Adaptation of Large Language Models." arXiv, June 17, 2021 (v2 Oct. 16, 2021); ICLR 2022. arXiv 2106.09685. Read Dec. 4, 2026.
  • ICLR 2022 poster page for LoRA. iclr.cc. Checked Dec. 4, 2026.
  • Hugging Face PEFT docs, v0.22.0: LoRA reference, Quicktour, Methods overview, Quantization guide. Checked Dec. 4, 2026.
  • Hugging Face TRL docs, v1.19.0: SFT Trainer. Checked Dec. 4, 2026.
  • AdapterHub docs: Methods. Checked Dec. 4, 2026.
  • Dettmers, T., Pagnoni, A., Holtzman, A., Zettlemoyer, L. "QLoRA: Efficient Finetuning of Quantized LLMs." arXiv, May 23, 2023. arXiv 2305.14314. Read Dec. 4, 2026.
  • Biderman, D., et al. "LoRA Learns Less and Forgets Less." arXiv, May 15, 2024; TMLR 2024. arXiv 2405.09673. Abstract read Dec. 4, 2026.

Series: ← Prev: Overview · All 15 techniques · Next: QLoRA →

  • #llm-fine-tuning
  • #lora
  • #peft
  • #low-rank-adaptation
  • #hugging-face