Parameter-Efficient Fine-Tuning (PEFT): LoRA to IA3
How LoRA, QLoRA, DoRA, prefix tuning, prompt tuning and IA3 work, from their original papers and the Hugging Face PEFT docs, with a minimal LoRA example.
Parameter-efficient fine-tuning (PEFT) adapts a pretrained language model to a new task by training a small set of new or selected parameters while the original weights stay frozen. The payoff is lower memory during training and tiny task-specific checkpoints, so one base model can serve many tasks. This guide explains the main methods (LoRA, QLoRA, DoRA, prefix tuning, prompt tuning and IA3) from their original papers, then shows how the Hugging Face PEFT library exposes them. For an end-to-end workflow (building a dataset, evaluating, serving), see our guide to fine-tuning domain-specific AI agents; this page stays on the methods themselves.
Why full fine-tuning gets expensive
Full fine-tuning updates every weight, so each task produces a complete copy of the model. The LoRA paper uses GPT-3 175B to make the point: running a separate fine-tuned instance per task, each with all 175B parameters, is in the authors’ words “prohibitively expensive”. The prefix-tuning paper makes the same storage argument, since every task needs its own full copy.
PEFT methods sidestep this by leaving the base model untouched and learning something small on top of it. The Hugging Face PEFT library describes itself as a framework for adding trainable parameters at chosen places in a base model; what separates one method from another is where those parameters live and how they combine with the frozen weights.
The methods at a glance
| Method | What gets trained | Primary paper |
|---|---|---|
| LoRA | Pairs of low-rank matrices added to chosen weight matrices | Hu et al., arXiv:2106.09685 |
| QLoRA | LoRA adapters on top of a frozen 4-bit base model | Dettmers et al., arXiv:2305.14314 |
| DoRA | A magnitude vector plus LoRA for the direction of each weight | Liu et al., arXiv:2402.09353 |
| Prefix tuning | Continuous vectors prepended at every layer | Li and Liang, arXiv:2101.00190 |
| Prompt tuning | Soft prompt embeddings added to the input only | Lester et al., arXiv:2104.08691 |
| IA3 | Vectors that rescale keys, values and feed-forward activations | Liu et al., arXiv:2205.05638 |
LoRA
Low-Rank Adaptation freezes the pretrained weights and adds a pair of small trainable matrices alongside selected layers in each Transformer block. Their product represents the weight update, and because the inner dimension (the rank r) is small, the number of trainable values stays low. Against GPT-3 175B fine-tuned with Adam, the paper reports LoRA cutting trainable parameters by 10,000 times and GPU memory needs by 3 times, while matching or beating full fine-tuning on RoBERTa, DeBERTa, GPT-2 and GPT-3. Unlike adapter layers, it adds no inference latency, because the update can be folded into the original weights.
In PEFT, the key LoraConfig options are:
r: the rank. A larger rank means more trainable parameters and more capacity.lora_alpha: the scaling factor. The original scaling islora_alpha / r; settinguse_rslora=Trueswitches tolora_alpha / sqrt(r)(rank-stabilized LoRA).target_modules: which layers get adapters. Passing"all-linear"targets every linear layer except the output layer.init_lora_weights: by default A is initialized with Kaiming-uniform and B with zeros, so the adapter starts as a no-op. Other options include"gaussian","pissa","eva"and"loftq".modules_to_save,biasandlora_dropoutfor extra trainable layers, bias handling and dropout.
The docs note that PEFT’s default places adapters on the query and value projections of each attention block.
QLoRA
QLoRA keeps the base model frozen in 4-bit precision and backpropagates through it into LoRA adapters. The paper reports that this brings fine-tuning of a 65B model within reach of one 48GB GPU while keeping the task performance of 16-bit fine-tuning. It adds three memory techniques: the 4-bit NormalFloat (NF4) data type, designed for normally distributed weights; double quantization, which also quantizes the quantization constants; and paged optimizers to absorb memory spikes.
In PEFT the recipe is a bitsandbytes config (load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_use_double_quant=True), then prepare_model_for_kbit_training(), then a normal LoraConfig. The docs suggest target_modules="all-linear" to match the paper, which applied adapters to all linear layers, and point to LoftQ initialization as a way to reduce quantization error. For background on the quantization side, see our LLM quantization and compression guide.
DoRA
DoRA starts from an analysis of how full fine-tuning and LoRA differ, then splits each pretrained weight into a magnitude and a direction. The direction is updated with LoRA and the magnitude gets its own learnable parameter. The authors report it consistently outperforms LoRA when fine-tuning LLaMA, LLaVA and VL-BART, with no extra inference cost.
In PEFT it is one flag: LoraConfig(use_dora=True, ...). The config reference says DoRA tends to help most at low ranks, currently supports linear and Conv2D layers, and carries more overhead than plain LoRA during training, so merging the weights before inference is recommended.
Prefix tuning and prompt tuning
Both methods keep the whole model frozen and learn continuous “virtual tokens” instead of changing weights.
Prefix tuning targets generation tasks. It learns a task-specific prefix that later tokens attend to, and the original experiments used GPT-2 for table-to-text and BART for summarization. The authors found it comparable to fine-tuning with full data, better in low-data settings, and better at extrapolating to unseen topics. The PEFT guide notes that the prefix is inserted at every layer and trained through a separate feed-forward network that is thrown away afterwards, because optimizing the prefix directly was unstable.
Prompt tuning is a simpler version: learned soft prompt embeddings are added to the input only. Lester et al. showed with T5 that it gets more competitive as models grow, and that once models pass billions of parameters it matches full model tuning. It also transferred to new domains more robustly than full tuning.
In PEFT, PrefixTuningConfig(task_type="CAUSAL_LM", num_virtual_tokens=20) sets up prefix tuning. PromptTuningConfig takes num_virtual_tokens and can initialize the prompt from text with prompt_tuning_init=PromptTuningInit.TEXT and prompt_tuning_init_text. The library also includes P-tuning and multitask prompt tuning.
IA3
IA3 (Infused Adapter by Inhibiting and Amplifying Inner Activations) comes from a paper comparing few-shot in-context learning with PEFT. Rather than learning matrices, it learns vectors that scale the keys and values in attention and the intermediate activation of the feed-forward block. The paper reports stronger results than in-context learning at far lower compute, while adding very few new parameters.
PEFT’s IA3Config needs target_modules and feedforward_modules; for autoregressive models the docs recommend k_proj, v_proj and down_proj, with down_proj listed as the feed-forward module. IA3 adapters can be merged into the base model, so they add no inference latency. The docs suggest LoRA instead when you want its wider set of variants such as DoRA and QLoRA.
A minimal LoRA run with the PEFT library
This is the core of the PEFT quicktour, trimmed: build a config, wrap the model, check trainable parameters, save the adapter.
from transformers import AutoModelForCausalLM
from peft import LoraConfig, TaskType, get_peft_model
peft_config = LoraConfig(target_modules=["q_proj"], task_type=TaskType.CAUSAL_LM,
inference_mode=False, r=8, lora_alpha=32, lora_dropout=0.1)
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B")
peft_model = get_peft_model(model, peft_config)
peft_model.print_trainable_parameters()
# train with the Transformers Trainer, Accelerate or a plain PyTorch loop, then:
peft_model.save_pretrained("output_dir")
For this config the quicktour reports 524,288 trainable parameters out of 1,236,338,688. Note that get_peft_model() modifies the base model in place, and that "q_proj" matches every layer whose name ends in it. save_pretrained() writes only the adapter: the quicktour’s OPT-350m LoRA example is two files, with the weights at 6.3MB. To load an adapter for inference, use AutoPeftModelForCausalLM.from_pretrained() or PeftModel.from_pretrained(base_model, path).
Merging and switching adapters
Adapters stay separate from the base model until you choose otherwise. PEFT gives you a few options:
- Merge for deployment:
merge_and_unload()folds LoRA weights into the base model and returns a standalone model. It does not modify in place, so assign the result. Usemerge_adapter()andunmerge_adapter()if you need to reverse it. - Several adapters on one model:
add_adapter()orload_adapter()adds named adapters, andset_adapter()chooses the active one. - Combine adapters:
add_weighted_adapter()merges LoRA adapters with methods such as linear, SVD, TIES and DARE (set viacombination_typeanddensity). For IA3 it does a linear merge, and the docs recommend weights that sum to 1.0.
There are limits. On a quantized base model, unmerging is not exact because merging re-quantizes the weights. LoRA adapters trained on AQLM-quantized models must be kept separate, because they cannot be merged.
Choosing a method
Use LoRA as the default. It has the most tooling and variants. Switch to QLoRA when the base model is too large for your GPU memory in 16-bit. Try DoRA when plain LoRA at low rank falls short of full fine-tuning. Prompt and prefix tuning keep the model completely untouched and store very little per task, but the prompt tuning paper shows their results depend on model scale. IA3 produces the smallest adapters. None of these change how the model is aligned to human preferences. That is a separate training stage, covered in our RLHF explainer. For tooling around training and serving, browse the LLM infrastructure hub.
Written by AI Agents Directory
Editorial team
Facts in this guide are checked against official documentation and repositories, which are linked in the article.