Adapters是 HuggingFace Transformers 的附加库,将 10 多种适配器方法集成到 20 多种最先进的 Transformer 模型中,同时将训练和推理的编码开销降至最低。
适配器提供了用于高效微调和模块化迁移学习的统一接口,支持多种功能,例如全精度或量化训练(例如 Q-LoRA、Q-Bottleneck Adapters 或 Q-PrefixTuning)、通过任务算术进行适配器合并或通过组合块组合多个适配器,允许对 NLP 任务的参数高效迁移学习进行高级研究。
注意:适配器库已取代
adapter-transformers
包。所有之前训练过的适配器都与新库兼容。如需转换,请阅读:https://docs.adapterhub.ml/transitioning.html。
adapters
当前支持Python 3.8+和PyTorch 1.10+ 。安装 PyTorch 后,您可以从 PyPI 安装adapters
...
pip install -U adapters
...或通过克隆存储库从源代码:
git clone https://github.com/adapter-hub/adapters.git
cd adapters
pip install .
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 )
了解更多
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...
了解更多
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 )
了解更多
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" )))
了解更多
可以在此处找到 HuggingFace 有关Transformer入门的精彩文档。 adapters
与Transformers完全兼容。
要开始使用适配器,请参阅以下位置:
目前,适配器集成了以下列出的所有架构和方法:
方法 | 文件) | 快速链接 |
---|---|---|
瓶颈适配器 | 霍尔斯比等人。 (2019) 巴普纳与菲拉特 (2019) | 快速入门,笔记本 |
适配器融合 | 菲佛等人。 (2021) | 文档:培训、笔记本 |
MAD-X, 可反转适配器 | 菲佛等人。 (2020) | 笔记本 |
适配器掉落 | 吕克莱等人。 (2021) | 笔记本 |
MAD-X 2.0, 嵌入训练 | 菲佛等人。 (2021) | 文档:嵌入、笔记本 |
前缀调优 | 李和梁 (2021) | 文档 |
并行适配器, 混合搭配适配器 | 他等人。 (2021) | 文档 |
压实机 | 马哈巴迪等人。 (2021) | 文档 |
洛拉 | 胡等人。 (2021) | 文档 |
(IA)^3 | 刘等人。 (2022) | 文档 |
尤尼佩尔特 | 毛等人。 (2022) | 文档 |
及时调整 | 莱斯特等人。 (2021) | 文档 |
QLoRA | 德特默斯等人。 (2023) | 笔记本 |
重新FT | 吴等人。 (2024) | 文档 |
适配器任务算法 | 克罗诺普卢等人。 (2023) 张等人。 (2023) | 文档、笔记本 |
目前,我们支持文档中模型概述页面上列出的所有模型的 PyTorch 版本。
要开始自己开发适配器并了解有关贡献方式的更多信息,请参阅 https://docs.adapterhub.ml/contributing.html。
如果您在工作中使用适配器,请考虑引用我们的图书馆论文:适配器:参数高效和模块化迁移学习的统一库
@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",
}
或者,对于前身的adapter-transformers
,由 AdapterHub 团队上传的 Hub 基础设施和适配器,请考虑引用我们的初始论文: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}
}