Bookmarks

PEFT — parameter-efficient fine-tuning

A family of methods for fine-tuning a large model by training only a small number of parameters, often added to it, while keeping the original weights frozen.

Also: PEFT, PEFT methods, PEFT library

checked 18 Nov

All terms

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

MethodWhat is trained
LoRA, QLoRAa pair of small matrices alongside selected layers; QLoRA works on top of a quantised base model
Adapterssmall layers inserted inside the model’s blocks
Prompt tuning, prefix tuningtrainable vectors added to the input or to attention; the weights themselves do not change
IA3vectors 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.

python
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.0424

In 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 pages

Verified 18 Nov

Not to be confused with

what it is mixed up with and how it differs

  • fine-tuning

    Full fine-tuning changes all the weights, whereas PEFT changes only a small part; the rest are frozen.

  • LoRALoRA method

    LoRA is one PEFT method, but not the only one: there are also adapters, prompt tuning and others.

In depth in the references

where the topic is covered in detail

Appears in the references