š¤ PEFT library release enables parameter-efficient fine-tuning of billionāscale models
TL;DR
Hugging Face released the š¤ PEFT library, allowing parameterāefficient fineātuning (PEFT) of large language models with only a few megabytes of trainable weights, making it feasible to adapt billionāscale models on consumerāgrade GPUs.
Motivation: why PEFT matters
PEFT methods train a small set of additional parameters while freezing the bulk of a pretrained model. This reduces both compute and storage costs, avoids catastrophic forgetting, and often outperforms full fineātuning in lowādata regimes. The approach works across modalities (text, vision, audio) and enables a single base model to serve many downstream tasks via tiny adapter checkpoints.
Supported PEFT techniques
The š¤ PEFT library currently implements four widelyācited methods:
- LoRA ā LowāRank Adaptation of Large Language Models (Hu et al., 2021).
- Prefix Tuning ā PāTuning v2, which prepends learnable vectors to each transformer layer.
- Prompt Tuning ā Scales promptābased adaptation across tasks.
- PāTuning ā Directly optimizes continuous prompts for GPTāstyle models.
Additional methods are planned for future releases.
Representative use cases
- Fineātuning a 3āÆBāparameter T0 model on a laptop GPU (11āÆGB RAM) using LoRA and š¤ Accelerateās DeepSpeed integration. The example script
peft_lora_seq2seq_accelerate_ds_zero3_offload.pyruns in GoogleĀ Colab. - INT8 LoRA tuning of OPTā6.7B in Colab via the
bitsandbyteslibrary, demonstrating that 8ābit quantization plus PEFT fits within modest GPU memory. - Stable Diffusion DreamBooth on consumer GPUs (RTXāÆ2080āÆTi, RTXāÆ3080) using LoRA, with a public Gradio demo that runs on a T4 (16āÆGB) instance.
These examples illustrate that models previously requiring dozens of GB of VRAM can now be adapted on hardware accessible to most practitioners.
Quick start: fineātuning bigscience/mt0-large with LoRA
from transformers import AutoModelForSeq2SeqLM
from peft import get_peft_model, LoraConfig, TaskType
model_name = "bigscience/mt0-large"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
peft_cfg = LoraConfig(
task_type=TaskType.SEQ_2_SEQ_LM,
inference_mode=False,
r=8,
lora_alpha=32,
lora_dropout=0.1,
)
model = get_peft_model(model, peft_cfg)
model.print_trainable_parameters()
# ā trainable params: 2,359,296 | all params: 1,231,940,608 | trainableāÆ%: 0.19
The remainder of the training loop is unchanged. After training, only the adapter files are saved:
model.save_pretrained("output_dir") # creates adapter_config.json + adapter_model.bin (~19āÆMB)
To load for inference:
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from peft import PeftModel, PeftConfig
peft_id = "smangrul/twitter_complaints_bigscience_T0_3B_LORA_SEQ_2_SEQ_LM"
cfg = PeftConfig.from_pretrained(peft_id)
base = AutoModelForSeq2SeqLM.from_pretrained(cfg.base_model_name_or_path)
model = PeftModel.from_pretrained(base, peft_id)
tokenizer = AutoTokenizer.from_pretrained(cfg.base_model_name_or_path)
model.eval().to("cuda")
inputs = tokenizer("Tweet text : @HondaCustSvc ...", return_tensors="pt")
with torch.no_grad():
out = model.generate(inputs["input_ids"].to("cuda"), max_new_tokens=10)
print(tokenizer.decode(out[0], skip_special_tokens=True))
# ā "complaint"
The adapter checkpoint is only a few megabytes, yet it yields performance comparable to full fineātuning.
Future directions
Hugging Face plans to add more PEFT variants such as IA³ and bottleneck adapters. Upcoming use cases include INT8 training of whisper-large in Colab and applying PEFT to RLHF components (policy and ranker models). Community contributions are encouraged via the GitHub repository.
Conclusion
š¤ PEFT democratizes the adaptation of billionāscale models by drastically lowering the hardware, compute, and storage barriers while preserving accuracy. The libraryās seamless integration with š¤ Transformers and š¤ Accelerate makes it straightforward to plug PEFT into existing pipelines and to share lightweight adapters across tasks.
Sources
Related
- Project
- Dispatch
- Dispatch
- Dispatch
- Dispatch