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}
}