Analytics Legends logoAI & Analytics Legends Sign inSign up
Concept card

LoRA + QLoRA — Parameter-Efficient Fine-Tuning at Production Scale

LoRA + QLoRA — Parameter-Efficient Fine-Tuning at Production Scale — AI & Analytics Legends section illustration for the SAP AI & Analytics knowledge base (concepts, studies, Academy)

As of 2026-11-14

What is LoRA + QLoRA?

LoRA freezes the base model and trains small rank-r matrices added to its linear layers: at r=16 a 4096×4096 matrix trains 131,072 parameters instead of 16,777,216 (128× fewer), and Llama 3.3 70B with all seven linear projections adapted trains 207 million parameters, 0.29 % of the model. QLoRA stores the frozen base in 4-bit NF4, which is how a 65B model fine-tuned on a single 48 GB GPU in the original paper.

What it is

LoRA (Low-Rank Adaptation) and its quantised variant QLoRA adapt a large language model to a domain or a behaviour without retraining its weights. LoRA freezes every base weight and adds, next to each adapted linear layer, a pair of small trainable matrices whose product is a low-rank update. The original paper reports, for GPT-3 175B, 10,000 times fewer trainable parameters, training memory cut from 1.2 TB to 350 GB, and no additional inference latency once the update is merged (LoRA). QLoRA goes further by holding the frozen base in 4-bit precision, which brought fine-tuning of a 65B model from more than 780 GB of GPU memory to under 48 GB, a single GPU (QLoRA).

Why it matters

  • The arithmetic is exact: at r=16 a 4096×4096 matrix trains 131,072 parameters instead of 16,777,216 (128× fewer), and Llama 3.3 70B with all seven linear projections adapted trains 207,093,760 parameters, 0.29 % of the model.
  • QLoRA's 4-bit NF4 base fine-tuned a 65B model on a single 48 GB GPU in the original paper (45.0 GB measured at batch 1, sequence 512); a 70B model sits at the edge of a 48 GB L40S and fits comfortably on an 80 GB H100 SXM.
  • Adapting only q, k, v and o leaves the MLP unadapted, and on Llama 3.3 70B the MLP holds 82 % of each layer's linear weights; QLoRA found adapters on all linear layers were needed to match full fine-tuning.

Key points

  • Mechanism: freeze W, learn B (d×r) and A (r×k), compute W + (α/r)·BA; B starts at zero so training starts from the base. LoRA paper on GPT-3 175B: 10,000× fewer trainable parameters, training memory 1.2 TB → 350 GB, no added inference latency once merged.
  • QLoRA = 4-bit NF4 frozen base + double quantisation (constants 0.5 → 0.127 bit per parameter) + paged optimizers; 65B fine-tuning went from >780 GB to <48 GB, and NF4 with double quantisation fully recovered 16-bit LoRA's 5-shot MMLU accuracy.
  • Target all linear layers: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj (PEFT: target_modules="all-linear"). QLoRA could not match full fine-tuning with the query-and-value default; on Llama 3.3 70B the MLP holds 82 % of each layer's linear weights.
  • Rank is secondary once coverage is right: in QLoRA's experiments r did not affect final performance when all layers were adapted. Start at r=16 and raise it only if evaluation shows under-fitting.
  • α and learning rate are coupled (with Adam, tuning α ≈ tuning the learning rate); α=2r is a convention, not a rule — QLoRA used r=64, α=16. QLoRA's learning rates: 2e-4 (7B, 13B), 1e-4 (33B, 65B), versus 2e-5 for Stanford Alpaca's full fine-tune.
  • Data quality beats volume: in QLoRA a 9,000-sample dataset (OASST1) outperformed a 450,000-sample FLAN v2 subsample on chatbot performance. Curate before you scale.
  • Serving: `model.merge_and_unload()` returns a standalone merged model with the base's latency; `merge_adapter()` merges in place and keeps the adapter for `unmerge_adapter()`; vLLM serves adapters per request via `LoRARequest` — set `max_lora_rank` to the largest adapter rank.
  • LoRA versus alternatives: LoRA for stable behaviour (format, tone, vocabulary, narrow classification); retrieval grounding for facts that change; full fine-tuning only when the model's knowledge itself must change.
  • SAP: customer LoRA runs as a training workflow on SAP AI Core; check the GPU instance types (SAP Note 3660109) before promising 70B; SAP's documentation forbids using SAP AI Core or the generative AI hub to generate synthetic training data without an approved, documented exception.
  • EU AI Act: if an adapted model is part of an Annex III high-risk system, the obligations of Arts. 9-49 (risk management, data governance, technical documentation, logging) apply from 2 December 2027 under Regulation (EU) 2026/1744 — keep dataset card, evaluation and delta against base per adapter now.

Terms used on this page

LoRA
Low-Rank Adaptation: freezes the base weights W and trains B (d×r) and A (r×k) so the effective weight is W + (α/r)·BA; on GPT-3 175B it cut trainable parameters 10,000× with no added inference latency once merged (Hu et al., 2021).
QLoRA
LoRA trained on a base held in 4-bit NF4 with double quantisation and paged optimizers; it fine-tuned a 65B model on a single 48 GB GPU while recovering 16-bit LoRA's MMLU accuracy (Dettmers et al., 2023, arXiv:2305.14314).
NF4 (NormalFloat 4)
A 4-bit data type that the QLoRA paper shows to be information-theoretically optimal for normally distributed weights; it stores each frozen weight in 4 bits instead of 16, and in the paper it outperformed 4-bit FP4.
Adapter hot-swap
Serving pattern in which one base model stays in GPU memory and the LoRA adapter is chosen per request or per tenant; vLLM implements it with LoRARequest and describes the overhead as minimal.
Rank r
Inner dimension of B (d×r) and A (r×k); r=16 on a 4096×4096 matrix gives 16 × (4096 + 4096) = 131,072 trainable parameters versus 16,777,216, a 128× reduction.
Alpha (LoRA scaling)
Constant in W + (α/r)·BA that scales the update; with Adam, tuning α is roughly the same as tuning the learning rate; α=2r is a common starting convention, QLoRA used r=64 with α=16.
PEFT (Parameter-Efficient Fine-Tuning)
Family of methods — LoRA, QLoRA, DoRA, prefix tuning, adapter layers — that adapt a pre-trained model by training a small fraction of parameters; also the name of Hugging Face's library implementing them.
Merge adapter
Adds the BA update permanently into W; in Hugging Face PEFT, `model.merge_and_unload()` returns a standalone merged model, while `merge_adapter()` merges in place and keeps the adapter so `unmerge_adapter()` can restore the base.

Sources

  1. arXiv: LoRA — Low-Rank Adaptation of Large Language Models (Hu et al., 2021)
  2. arXiv: QLoRA — Efficient Finetuning of Quantized LLMs (Dettmers et al., 2023)
  3. Hugging Face PEFT documentation — LoRA developer guide (merge_and_unload, merge_adapter, all-linear)
  4. vLLM documentation — LoRA adapters (LoRARequest, max_lora_rank, dynamic loading)
  5. Llama 3.3 70B Instruct config.json (ungated mirror of Meta's release): hidden 8,192, 80 layers, 8 KV heads, MLP 28,672
  6. NVIDIA H100 Tensor Core GPU — specifications (H100 SXM 80 GB, H100 NVL 94 GB)
  7. NVIDIA L40S — specifications (48 GB GDDR6)
  8. arXiv: DoRA — Weight-Decomposed Low-Rank Adaptation (Liu et al., 2024)
  9. arXiv: Parameter-Efficient Transfer Learning for NLP — adapter tuning (Houlsby et al., 2019)
  10. arXiv: Prefix-Tuning — Optimizing Continuous Prompts for Generation (Li & Liang, 2021)
  11. Stanford Alpaca repository — full fine-tuning recipe (learning rate 2e-5)
  12. SAP AI Core documentation — What Is SAP AI Core? (synthetic training data restriction)
  13. SAP AI Core documentation — Train Your Model (training workflows, resource groups, own Docker images)
  14. SAP AI Core documentation — Choose an Instance (resource plans, instance types, SAP Note 3660109)
  15. SAP AI Core documentation — Service Plans (standard vs extended)
  16. SAP AI Core documentation — What's New (SAP-RPT-TS, SAP-RPT-Decisions)
  17. SAP News — SAP Business AI release highlights Q2 2026 (SAP Domain Models, Early Adopter Care)
  18. EUR-Lex — Regulation (EU) 2024/1689 (AI Act), Arts. 9-49 and Annex III; application dates amended by Regulation (EU) 2026/1744
  19. NIST AI Risk Management Framework 1.0 — model lifecycle governance

Full card with the Consultant plan — €19.90/month. What the full card adds: the full decision framework · the SAP vs Snowflake / Databricks / Fabric comparison · the common pitfalls and their fix · the cheat sheet · the architecture schemas · the code blocks · the facts worth quoting.

Open in the app →

Open missions

SAP analytics jobs and contracts · freelance SAP contracts.