需先自行安装 PyTorch 2.0+,且 Python 版本需 3.9+;预训练适配器需从 AdapterHub 或 HF 额外下载;旧 adapter-transformers 用户需按迁移文档改用新包。
adapters
adapter-hubApache-2.0更新放缓统一封装 LoRA、Adapter 等参数高效微调方法的 PyTorch 库,兼容 Hugging Face Transformers,让大模型微调只需改几行代码。
A Unified Library for Parameter-Efficient and Modular Transfer Learning
pip install -U adaptersREADME 未说明具体显存或 GPU 型号要求,仅要求 PyTorch 2.0+;量化训练(如 Q-LoRA)相关说明见文档与 notebook。
给 Transformers 加装 10+ 种参数高效微调方法的统一库,省去自己实现适配器
统一封装 LoRA、Adapter 等参数高效微调方法的 PyTorch 库,兼容 Hugging Face Transformers,让大模型微调只需改几行代码。
核心能力
- 集成 LoRA、Prefix Tuning、Compacter 等 10+ 种适配器方法
- 通过 adapters.init 把适配器接入现有 Transformers 模型
- 用 AdapterSetup 与 composition 模块组合多个适配器
- 支持 Q-LoRA 等量化训练与 Adapter Task Arithmetics 合并
- 从 AdapterHub 直接加载预训练适配器权重
容易踩的坑
- v1.3.0Adapters v1.3.0最新正式版2026-04-26 · 2026-04-26 19:52 UTC
This version is built for Hugging Face Transformers v4.57.x.
New
Add support for DoRA adapters (@julian-fong via #790):
DoRA (Liu et al., 2024) is an enhanced LoRA variant. See https://docs.adapterhub.ml/methods.html#dora.
More
- Add EAT model interface for LoRA adapter support (@mgustineli via https://github.com/adapter-hub/adapters/pull/832)
Changed
- Upgrade supported Transformers version to v4.57.x (@lenglaender via #814, @calpt via #829)
Fixed
- Fix Prefix Finetuning for Group Query Attention (GQA) (@ha405 via #825)
- Handle NotImplementedError from get_input_embeddings() during init (@mgustineli via https://github.com/adapter-hub/adapters/pull/831)
- Fix LoRAMergedLinear.get_n_heads() shape mismatch with fused QKV + "o" matrix (@mgustineli via https://github.com/adapter-hub/adapters/pull/830)
- Fix path traversal issue for downloading adapter archives (@calpt via #833)
- v1.2.0Adapters v1.2.02025-05-20 · 2025-05-20 19:43 UTC
查看更新说明
Blog post: https://adapterhub.ml/blog/2025/05/adapters-for-any-transformer
This version is built for Hugging Face Transformers v4.51.x.
New
Adapter Model Plugin Interface (@calpt via #738; @lenglaender via #797)
The new adapter model interface makes it easy to plug most adapter features into any new or custom Transformer model. Check out our release blog post for details. Also see https://docs.adapterhub.ml/plugin_interface.html.
Multi-Task composition with MTL-LoRA (@FrLdy via #792)
MTL-LoRA (Yang et al., 2024) is a new adapter composition method leveraging LoRA for multi-task learning. See https://docs.adapterhub.ml/multi_task_methods.html#mtl-lora.
VeRA - parameter-efficient LoRA variant (@julian-fong via #763)
VeRA (Kopiczko et al., 2024) is a LoRA adapter variant that requires even less trainable parameters. See https://docs.adapterhub.ml/methods.html#vera.
New Models (via new interface)
A couple of new models are supported out-of-the-box via the new adapter model plugin interface:
- Gemma 2, Gemma 3
- ModernBERT
- Phi 1, Phi 2
- Qwen 2, Qwen 2.5, Qwen 3
More
- New
init_weights_seedadapter config attribute to initialize adapters with identical weights (@TimoImhof via #786) - Support defining custom forward method args via
ForwardContext(@calpt via #789)
Changed
- Upgrade supported Transformers version (@calpt via #799; @TimoImhof via #805)
- v1.1.1Adapters v1.1.12025-04-12 · 2025-04-12 21:00 UTC
查看更新说明
This version is built for Hugging Face Transformers v4.48.x.
Changes
- Upgrade supported Transformers version to 4.48 (@TimoImhof via #782)
Fixed
- Fix BatchSplit for PrefixTuning (@FrLdy via #750)
- v1.1.0Adapters v1.1.02025-01-28 · 2025-01-28 20:27 UTC
查看更新说明
This version is built for Hugging Face Transformers v4.47.x.
New
Add AdapterPlus adapters (@julian-fong via #746, #775):
AdapterPlus (Steitz & Roth, 2024) is a new bottleneck adapter variant optimized for vision transformers. Check out our notebook for training AdapterPlus adapters for ViT models.
Easy saving, loading and pushing of full adapter compositions to the Hub (@calpt via #771):
The newly added
save_adapter_setup(),load_adapter_setup()andpush_adapter_setup_to_hub()methods allow saving, loading and uploading complex adapter compositions - including AdapterFusion setups - with one line of code. Read our documentation for more.Enabling full gradient checkpointing support with adapters (@lenglaender via #759)
Gradient checkpointing is a technique for enabling fine-tuning in very memory-limited setttings that nicely complements efficient adapters. It is now supported across all integrated adapter methods. Check out our notebook for fine-tuning Llama with gradient checkpointing and adapters.
More
- Custom names for AdapterFusion layers (@calpt via #774): Allows distinguishing multiple fusions on the same adapter by name. See details.
- Allow specifying adapter dtype in AdapterConfig (@killershrimp via #767)
Changed
- Major refactoring of library test suite (@TimoImhof via #740): See tests readme for details.
- Upgrade supported Transformers version (@calpt via #757; @lenglaender via #776)
Fixed
- Fix Mistral flash attention with adapters (@divyanshuaggarwal via #758)
- Fix Bottleneck configs to work with ln_before = True and init_weights = "mam_adapter" (@julian-fong via #761)
- Fix default Lora/ (IA)^3 scaling in forward (@calpt via #770) Note: This restores compatibility with adapter-transformers, but changes logic compared to previous Adapters versions. See #770 for details.
- Fixes for sequence generation & orthogonal projection with ReFT (@calpt via #778)
- Various minor compatibility and warning fixes (@calpt via #780, #787)
- v1.0.1Adapters v1.0.12024-11-02 · 2024-11-02 18:47 UTC
查看更新说明
This version is built for Hugging Face Transformers v4.45.x.
New
- Add example notebook for ReFT training (@julian-fong via #741)
Changes
- Upgrade supported Transformers version (@calpt via #751)
Fixed
- Fix import error for Huggingface-hub version >=0.26.0 & Update Notebooks (@lenglaender via #750)
- Fix output_embeddings get/ set for empty active head (@calpt via #754)
- Fix LoRA parallel composition (@calpt via #752)
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Adapters is an add-on library to HuggingFace's Transformers, integrating 10+ adapter methods into 20+ state-of-the-art Transformer models with minimal coding overhead for training and inference.
Adapters provides a unified interface for efficient fine-tuning and modular transfer learning, supporting a myriad of features like full-precision or quantized training (e.g. Q-LoRA, Q-Bottleneck Adapters, or Q-PrefixTuning), adapter merging via task arithmetics or the composition of multiple adapters via composition blocks, allowing advanced research in parameter-efficient transfer learning for NLP tasks.
Note: The Adapters library has replaced the
adapter-transformerspackage. All previously trained adapters are compatible with the new library. For transitioning, please read: https://docs.adapterhub.ml/transitioning.html.
Installation
adapters currently supports Python 3.9+ and PyTorch 2.0+.
After installing PyTorch, you can install adapters from PyPI ...
pip install -U adapters
... or from source by cloning the repository:
git clone https://github.com/adapter-hub/adapters.git
cd adapters
pip install .
Quick Tour
Load pre-trained adapters:
from adapters import AutoAdapterModel
from transformers import AutoTokenizer
model = AutoAdapterModel.from_pretrained("roberta-base")
tokenizer = AutoTokenizer.from_pretrained("roberta-base")
model.load_adapter("AdapterHub/roberta-base-pf-imdb", source="hf", set_active=True)
print(model(**tokenizer("This works great!", return_tensors="pt")).logits)
Adapt existing model setups:
import adapters
from transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained("t5-base")
adapters.init(model)
model.add_adapter("my_lora_adapter", config="lora")
model.train_adapter("my_lora_adapter")
# Your regular training loop...
Flexibly configure adapters:
from adapters import ConfigUnion, PrefixTuningConfig, ParBnConfig, AutoAdapterModel
model = AutoAdapterModel.from_pretrained("microsoft/deberta-v3-base")
adapter_config = ConfigUnion(
PrefixTuningConfig(prefix_length=20),
ParBnConfig(reduction_factor=4),
)
model.add_adapter("my_adapter", config=adapter_config, set_active=True)
Easily compose adapters in a single model:
from adapters import AdapterSetup, AutoAdapterModel
import adapters.composition as ac
model = AutoAdapterModel.from_pretrained("roberta-base")
qc = model.load_adapter("AdapterHub/roberta-base-pf-trec")
sent = model.load_adapter("AdapterHub/roberta-base-pf-imdb")
with AdapterSetup(ac.Parallel(qc, sent)):
print(model(**tokenizer("What is AdapterHub?", return_tensors="pt")))
Useful Resources
HuggingFace's great documentation on getting started with Transformers can be found here. adapters is fully compatible with Transformers.
To get started with adapters, refer to these locations:
- Colab notebook tutorials, a series notebooks providing an introduction to all the main concepts of (adapter-)transformers and AdapterHub
- https://docs.adapterhub.ml, our documentation on training and using adapters with adapters
- https://adapterhub.ml to explore available pre-trained adapter modules and share your own adapters
- Examples folder of this repository containing HuggingFace's example training scripts, many adapted for training adapters
Implemented Methods
Currently, adapters integrates all architectures and methods listed below:
| Method | Paper(s) | Quick Links |
|---|---|---|
| Bottleneck adapters | Houlsby et al. (2019) Bapna and Firat (2019) Steitz and Roth (2024) | Quickstart, Notebook |
| AdapterFusion | Pfeiffer et al. (2021) | Docs: Training, Notebook |
| MAD-X, Invertible adapters | Pfeiffer et al. (2020) | Notebook |
| AdapterDrop | Rücklé et al. (2021) | Notebook |
| MAD-X 2.0, Embedding training | Pfeiffer et al. (2021) | Docs: Embeddings, Notebook |
| Prefix Tuning | Li and Liang (2021) | Docs |
| Parallel adapters, Mix-and-Match adapters | He et al. (2021) | Docs |
| Compacter | Mahabadi et al. (2021) | Docs |
| LoRA | Hu et al. (2021) | Docs |
| MTL-LoRA | Yang et al., 2024 | Docs |
| (IA)^3 | Liu et al. (2022) | Docs |
| Vera | Kopiczko et al., 2024 | Docs |
| DoRA | Liu et al., 2024 | Docs |
| UniPELT | Mao et al. (2022) | Docs |
| Prompt Tuning | Lester et al. (2021) | Docs |
| QLoRA | Dettmers et al. (2023) | Notebook |
| ReFT | Wu et al. (2024) | Docs |
| Adapter Task Arithmetics | Chronopoulou et al. (2023) Zhang et al. (2023) | Docs, Notebook |
Supported Models
We currently support the PyTorch versions of all models listed on the Model Overview page in our documentation.
Developing & Contributing
To get started with developing on Adapters yourself and learn more about ways to contribute, please see https://docs.adapterhub.ml/contributing.html.
Citation
If you use Adapters in your work, please consider citing our library paper: Adapters: A Unified Library for Parameter-Efficient and Modular Transfer Learning
@inproceedings{poth-etal-2023-adapters,
title = "Adapters: A Unified Library for Parameter-Efficient and Modular Transfer Learning",
author = {Poth, Clifton and
Sterz, Hannah and
Paul, Indraneil and
Purkayastha, Sukannya and
Engl{\"a}nder, Leon and
Imhof, Timo and
Vuli{\'c}, Ivan and
Ruder, Sebastian and
Gurevych, Iryna and
Pfeiffer, Jonas},
booktitle = "Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
month = dec,
year = "2023",
address = "Singapore",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.emnlp-demo.13",
pages = "149--160",
}
Alternatively, for the predecessor adapter-transformers, the Hub infrastructure and adapters uploaded by the AdapterHub team, please consider citing our initial paper: AdapterHub: A Framework for Adapting Transformers
@inproceedings{pfeiffer2020AdapterHub,
title={AdapterHub: A Framework for Adapting Transformers},
author={Pfeiffer, Jonas and
R{\"u}ckl{\'e}, Andreas and
Poth, Clifton and
Kamath, Aishwarya and
Vuli{\'c}, Ivan and
Ruder, Sebastian and
Cho, Kyunghyun and
Gurevych, Iryna},
booktitle={Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations},
pages={46--54},
year={2020}
}