LoRA and Parameter-Efficient Fine-Tuning

Fine-tune open-weight models on a single GPU with LoRA, QLoRA and the Hugging Face ecosystem.

Advanced · about 8 hours · difficulty 4/5

Learn first: Preparing Fine-Tuning Datasets, Running Open-Weight Models Locally

Updating every weight of a multi-billion parameter model needs huge GPU memory. Parameter-efficient fine-tuning (PEFT) trains a small number of extra parameters instead, making fine-tuning practical on one consumer or cloud GPU.

How LoRA works

LoRA (Low-Rank Adaptation) freezes the base model and adds small low-rank matrices to selected layers, usually the attention projections. Only those matrices are trained. The result is an adapter of a few megabytes to a few hundred megabytes that you load on top of the base model or merge into it.

  • Rank (r): the size of the adapter. Higher rank means more capacity and more memory.
  • Alpha: a scaling factor for the adapter's contribution.
  • Target modules: which layers get adapters.

QLoRA

QLoRA loads the frozen base model in 4-bit precision and trains LoRA adapters on top, cutting memory further so mid-sized models fit on a single GPU.

Tooling

  • Hugging Face Transformers, PEFT and TRL (with its SFTTrainer and DPO trainer) are the standard stack.
  • Unsloth and Axolotl wrap these with faster kernels and config-driven training.
  • Free notebook GPUs are enough to learn on small models.

After training

Evaluate against the base model on your held-out set, merge or serve the adapter (vLLM and others can serve many LoRA adapters on one base model), and export to formats like GGUF for local runtimes if needed.

Good enough to move on

You can fine-tune a small open-weight model with QLoRA in a notebook, evaluate it, and load the adapter for inference.

Key concepts

  • Full fine-tuning vs PEFT
  • LoRA rank, alpha and targets
  • QLoRA and 4-bit loading
  • Transformers, PEFT and TRL
  • Unsloth / Axolotl
  • Merging and serving adapters
  • Exporting to GGUF

Mini project

Use QLoRA on a free notebook GPU to fine-tune a small open model to convert plain English into SQL for your own schema, and compare accuracy with the base model on 50 held-out questions.

Check yourself

Why can a LoRA adapter be only a few megabytes when the base model is many gigabytes?

Free resources