huggingface/peft
Python/PyTorch adapters for fine-tuning large models without updating base weights
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
PEFT is a Python/PyTorch library that adapts an existing model rather than replacing its training or inference runtime. For LoRA, get_peft_model takes a loaded base model and a method-specific configuration, attaches trainable low-rank parameters to selected modules, and leaves the base weights frozen. save_pretrained writes the adapter artifact; PeftModel.from_pretrained attaches it to the corresponding base model for inference. The model still exposes generation through generate.
Method configuration and module selection are the main extension points. Transformers supports adapter lifecycle operations directly, Diffusers integrates adapter management for diffusion pipelines, and Accelerate supports distributed training and inference. The requirements list includes torch, transformers, accelerate, safetensors, and bitsandbytes. The repository separates source, examples, method comparisons, and tests into src/, examples/, method_comparison/, and tests/.
Key Capabilities & Differentiators
PEFT covers LoRA, soft prompts, and IA3, with examples spanning Qwen language generation, Whisper speech recognition, and Stable Diffusion. In the Qwen2.5-3B-Instruct example, LoRA with rank 16 and alpha 32 trains 0.1193% of model parameters. In the A100 80 GB training comparison, T0-3B uses 14.4 GB of GPU memory with PyTorch LoRA versus 47.14 GB for full fine-tuning. The corresponding LoRA checkpoint is 19 MB versus 11 GB for the full model.
Quantized workflows include Llama-2-7B QLoRA with TRL on a 16 GB GPU and Whisper large-v2 with LoRA and 8-bit quantization. For Stable Diffusion v1.4, the comparison reports 27.5 GB of GPU memory for full fine-tuning, 15.5 GB for LoRA, and 8.12 GB for LoRA with gradient checkpointing, with an 8.8 MB adapter checkpoint. These figures describe individual training setups, not inference requirements.
Trade-offs & Limitations
Compared with full fine-tuning, PEFT reduces trainable state and per-task storage but limits how the pretrained model can change. The T0-3B LoRA example scores 0.863 on the reported task. The table does not include a matched full-fine-tuned T0-3B result, so it cannot establish quality parity. Offloading also shifts memory demand rather than eliminating it: for mt0-xxl, PyTorch LoRA uses 56 GB GPU and 3 GB CPU memory, versus 22 GB GPU and 52 GB CPU with DeepSpeed CPU offload.
Transformers' adapter API is sufficient for routine loading and switching, but it does not expose all native PEFT features, such as merging. Separate adapters preserve switching and base-model reuse; merging a supported adapter is an option when deploying a fixed variant. Neither a small checkpoint nor a low trainable-parameter count implies faster generation. PEFT supplies model-side adaptation, not a serving endpoint or scheduler.
Hardware & Deployment Guide
Install with pip install peft and run it inside the Python model process. The Transformers inference path loads the base model and tokenizer, attaches a local adapter with PeftModel.from_pretrained, then calls generate. For offline use, stage the dependencies, base weights, tokenizer files, and adapter locally. For GPU deployment, validate PyTorch against the accelerator environment and check the quantization backend if used. Test peak memory with the intended sequence length, batch size, and inference concurrency rather than sizing from the adapter checkpoint.
Release v0.22.0 adds Partial Connection Adaptation (PaCA). For distributed checkpointing, v0.21.3 gathers only adapter weights when saving a DTensor tensor-parallel model, avoiding a gather of the entire sharded model. Release v0.21.2 fixes an encoder-decoder compatibility issue with Transformers 5.18.0 and later. Pin and test the version pair for the target architecture, including an adapter save-and-reload check before rollout.
add_adapter, load_adapter, and set_adapter; PEFT directly exposes merging for supported adapters.Teams adapting a shared base model to multiple tasks under a training-memory or checkpoint-storage budget, then loading the resulting adapters in a Hugging Face workflow.
Your evaluation shows that you need full weight updates, you must deploy a standalone model without access to the base and cannot merge the chosen adapter, or you expect a turnkey inference server.
Quick Start & Installation
pip install peftComparison vs. Top LLMs & Inference Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| peft ★ | 21.9k | +32 | Python | Apache-2.0 | Python/PyTorch adapters for fine-tuning large models without updating base weigh |
| LlamaFactory | 76.4k | +86 | Python | Apache-2.0 | A unified Python framework for LLM and VLM fine-tuning with pluggable inference |
| axolotl | 12.8k | +15 | Python | Apache-2.0 | YAML-driven GPU trainer for LLM and multimodal post-training |
| minimind | 75.4k | +3.1k | Python | Apache-2.0 | Native PyTorch dense and MoE models for end-to-end LLM training on local GPUs |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/huggingface/peft.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about peft
How do I train, reload, and switch adapters?
get_peft_model with a configuration such as LoraConfig to prepare the base model for training, then save the adapter with save_pretrained. At inference time, load the matching base model and attach the adapter with PeftModel.from_pretrained. Transformers also exposes add_adapter, load_adapter, and set_adapter; use PEFT directly if you need merging for a supported adapter.Does a small adapter checkpoint mean I need little VRAM?
Can we use PEFT commercially and host it ourselves?
When should I choose PEFT over full fine-tuning or the Transformers adapter API?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy