PEFT
huggingface / peft
参数高效微调的标准库:LoRA、IA3、Prefix Tuning 等适配器,接 Transformers 与 Accelerate。The standard parameter-efficient fine-tuning library: LoRA, IA3, prefix tuning and other adapters, wired into Transformers and Accelerate.
为什么选Why choose it
- 只训练少量参数,显存与存储成本远低于全参微调。Trains only a small number of parameters, far below full fine-tuning in memory and storage cost.
- 适配器可以按任务切换,同一基座服务多个场景。Adapters can be swapped per task, so one base model serves several use cases.
- 与 Transformers、Accelerate、bitsandbytes 兼容,生态成熟。Compatible with Transformers, Accelerate and bitsandbytes, with a mature ecosystem.
不适合Not for
需要改变模型知识边界或做大规模继续预训练,单靠适配器不够。Changing the model’s knowledge boundary or doing large-scale continued pretraining is not enough with adapters alone.
只想要端到端训练脚本与数据配方,应搭配 TRL 或 LLaMA-Factory。If you want end-to-end training scripts and data recipes, pair it with TRL or LLaMA-Factory.
最小上手Minimum setup
- 先确认基座结构与目标模块,选 LoRA 的 rank、alpha 与 dropout。Confirm the base architecture and target modules; choose LoRA rank, alpha and dropout.
- 用 PEFT 的官方示例接上 Transformers Trainer,跑通一次小样本训练。Use the official PEFT example with the Transformers Trainer to complete a small-sample run.
- 保存 adapter 而不是整模型;上线时确认推理端能加载同一适配器。Save the adapter rather than the full model; confirm the inference stack can load the same adapter.
依赖与成本Dependencies and cost
Python + PyTorch;显存取决于基座、序列长度与是否 4bit 量化;推理端需支持 PEFT 适配器。Python + PyTorch; VRAM depends on the base model, sequence length and 4-bit quantisation; the inference stack must support PEFT adapters.
许可与使用边界License and usage boundaries
代码 Apache-2.0;基座模型与数据集许可各自独立。Code is Apache-2.0; base models and datasets carry separate licences.
开源不等于可商用:GPL / AGPL 有传染性;代码许可、模型许可、生成内容许可要分开看。上线前读仓库 LICENSE 与模型卡,必要时让法务确认。Open source is not automatically commercial-use friendly: GPL / AGPL are copyleft; code, model and output licenses are separate. Read the LICENSE and model card before launch, and involve legal when needed.
替代与相邻Alternatives and neighbors
- TRL — 生产可用Production,Hugging Face 的强化学习与对齐训练库:SFT、DPO、PPO、GRPO、奖励模型都能接。Hugging Face's RL and alignment training library: SFT, DPO, PPO, GRPO and reward models.
- torchtune — 规模 / 性能Scale / performance,PyTorch 原生的微调配方库:可读的训练循环、FSDP、激活检查点与常用后训练配方。A PyTorch-native fine-tuning recipe library: readable training loops, FSDP, activation checkpointing and common post-training recipes.
下一步Next steps
- 打开 GitHub,先读 README、LICENSE、最近 release 与 issue。Open GitHub and read the README, LICENSE, latest release and issues first.
- 按“部署依赖 / 显存 / 数据 / 网络 / 权限”列一张上手清单。Make an onboarding checklist for deployment dependencies, VRAM, data, network and permissions.
- 用一个小样本跑通,再决定是否进生产;不要直接上生产数据。Run a small sample first, then decide on production; never start with production data.
GitHub 仓库 ↗GitHub repository ↗ 文档 ↗Docs ↗ 加入对比Add to compare