Full fine-tuning of a large model requires storing gradients and optimiser state for every weight, and produces yet another copy of the model. PEFT trains only a small set of added or selected parameters: it needs less memory, and the result is stored as a separate small file.
Types of methods
| Method | What is trained |
|---|---|
| LoRA, QLoRA | a pair of small matrices alongside selected layers; QLoRA works on top of a quantised base model |
| Adapters | small layers inserted inside the model’s blocks |
| Prompt tuning, prefix tuning | trainable vectors added to the input or to attention; the weights themselves do not change |
| IA3 | vectors that scale the activations inside attention and fully connected layers |
The PEFT library
The name is also used for a Hugging Face library. It wraps a model from Transformers, swaps in trainable layers in place of selected ones, and is integrated with Transformers, Diffusers and Accelerate. The method is set by a configuration, and print_trainable_parameters() shows the share of trainable weights.
from peft import LoraConfig, TaskType, get_peft_model config = LoraConfig(target_modules=["q_proj"], task_type=TaskType.CAUSAL_LM, r=8, lora_alpha=32, lora_dropout=0.1)peft_model = get_peft_model(model, config)peft_model.print_trainable_parameters()# trainable params: 524,288 || all params: 1,236,338,688 || trainable%: 0.0424In the documentation example, about 0.04% of parameters are trained. Several adapters can be kept on one base model and switched between for different tasks.
Sources
the term is written from these pagesVerified 18 Nov