| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This repository is a fork of the huggingface Parameter-Efficient Fine-Tuning (PEFT) library, containing the official implementation for the paper Robust Adaptation (RoSA). The RoSA-related code can be found in src/peft/tuners/rosa/. Also here, we have integrated this library into MosaicML's llm-foundry, containing the experiments reported in the paper.
pip install git+https://github.com/IST-DASLab/spops.git
pip install -e .
The usage is almost identical to LoRA in the PEFT library, with some extra configuration parameters in RosaConfig + a single line of code adding a RosaScheduler. The required changes are shown in the code block below.
from transformers import AutoModelForSeq2SeqLM
from peft import get_peft_model, TaskType
from peft.tuners.rosa import RosaConfig, RosaScheduler
model_name_or_path = "bigscience/mt0-large"
peft_config = RosaConfig(
task_type=TaskType.SEQ_2_SEQ_LM,
r=8,
lora_alpha=32,
lora_dropout=0.1,
d=0.006, |
spa_num_grads=1, | <---- the new config parameters
grad_acc_mode='mean_squared', |
schedule='wl64' |
)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_or_path)
model = get_peft_model(model, peft_config)
trainer = Trainer(
model=model,
...,
callbacks=[RosaScheduler(model)] | <---- add RosaScheduler as a callback
)
The new config parameters, in line with the paper, are the following ones:
Finally, just add RosaScheduler(model) as a callback to the Trainer. RosaScheduler is also compatible with MosaicML's composer (just add it as an Algorithm). Additionally, you can customize it for any other framework by calling scheduler's _on_step_begin() and _on_step_end() before forward and after backward, respectively.
The schedule argument in RosaConfig determines when each of low-rank and sparse adapters should be active, and when to generate the sparsity masks. The (currently) supported options are discussed below.
Finally, as discussed in the paper, we found it beneficial to warm up with low-rank adapter only (wl64 schedule), generate the masks, and then restart the training with both adapters activated. To do this, we suggest following the steps below, taking advantage of three extra parameters in RosaConfig.
If you plan to use our work in your projects, please consider citing our paper:
@article{nikdan2024rosa,
title={RoSA: Accurate Parameter-Efficient Fine-Tuning via Robust Adaptation},
author={Nikdan, Mahdi and Tabesh, Soroush and Crnčević, Elvir and Alistarh, Dan},
journal={arXiv preprint arXiv:2401.04679},
year={2024}
}
| Back | FazBrowse Home | New Git URL |