# Repository Briefing: huggingface/peft
> Source: https://repoforai.com/repo/huggingface/peft (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/huggingface/peft
- **Official Docs / Website**: https://huggingface.co/docs/peft
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: Apache-2.0
- **Engineering Health**: A+ (97/100 · Maintenance 35/35 · Adoption 22/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v0.22.0 (2026-11-19) — https://github.com/huggingface/peft/releases
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: GPU
- **Momentum**: 21,946 ★ total (+4 24h / +32 7d) · 2,706 forks
- **Topics**: `adapter`, `diffusion`, `fine-tuning`, `llm`, `lora`, `parameter-efficient-learning`, `peft`, `python`, `pytorch`, `transformers`
- **When to Use**: Best for: 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. Skip if: 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.

## Overview
```text
### Architecture & 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.
```

## Key Capabilities
```text
- Training scope: The Qwen2.5-3B-Instruct LoRA example trains 0.1193% of model parameters with rank 16 and alpha 32.
- Training memory: T0-3B uses 14.4 GB of GPU memory with PyTorch LoRA versus 47.14 GB with full fine-tuning in the A100 80 GB comparison.
- Checkpointing: The T0-3B LoRA checkpoint is 19 MB versus 11 GB for the full model; inference still requires the base weights.
- Adapter lifecycle: Transformers supports `add_adapter`, `load_adapter`, and `set_adapter`; PEFT directly exposes merging for supported adapters.
- Quantized training: A Llama-2-7B QLoRA example uses TRL on a 16 GB GPU; that figure applies to the example, not to all 7B workloads.
- Release changes: v0.22.0 adds PaCA, while v0.21.3 limits DTensor tensor-parallel save-time gathering to adapter weights.
```

## Quick Start / Clone
```bash
pip install peft
```
