Home

Awesome

AdaMix (Mixture-of-Adaptations)

This is the implementation of the paper AdaMix: Mixture-of-Adaptations for Parameter-efficient Model Tuning.

Quick links

Overview

Training

<img src="./figures/MixAdapter.png" width="650"/>

Inference

<img src="./figures/training_inference.png" width="450"/>

Adapting to the GLUE Benchmark

Our experiments on the GLUE benchmark are run on 16 NVIDIA Tesla V100 GPU. The results may vary due to different GPU models, drivers, CUDA SDK versions, floating-point precisions, and random seeds.

Main Results (BERT-base)

<img src="./figures/bert_base.png" width="750"/>

Main Results (RoBERTa-large)

<img src="./figures/roberta_large.png" width="750"/>

Comparision between Averaging Weights and Random Single Adapter

<img src="./figures/violin_plot.png" width="950"/>

Download AdaMix checkpoints

We release all copies of Adapter weights for users' Adapter aggregation study.

DatasetBERT base 110M <br>RoBERTa large 355M <br>
MNLI8.5 MB11.7 MB
SST28.5 MB11.7 MB
MRPC8.5 MB11.7 MB
CoLA8.5 MB11.7 MB
QNLI8.5 MB11.7 MB
QQP8.5 MB11.7 MB
RTE8.5 MB11.7 MB
STSB8.5 MB11.7 MB

Steps to reproduce our results

Create and activate conda env

conda env create -f environment.yml

Install the pre-requisites

pip install -e .

We also provide the shell scripts for bert-base and roberta-large.

Quick start

export num_gpus=1
export PYTHONHASHSEED=0
task_name=mnli
model=roberta-large
export output_dir="./models/${model}/${task_name}"
python -m torch.distributed.launch --nproc_per_node=$num_gpus \
examples/text-classification/run_glue.py \
--model_name_or_path $model \
--task_name $task_name \
--do_train \
--do_eval \
--max_seq_length 128 \
--per_device_train_batch_size 64 \
--per_device_eval_batch_size 32 \
--learning_rate 3e-4 \
--num_train_epochs 20 \
--output_dir $output_dir/model \
--overwrite_output_dir \
--logging_steps 1000 \
--logging_dir $output_dir/log \
--evaluation_strategy epoch \
--save_strategy epoch \
--warmup_ratio 0.06 \
--apply_expert_soup \
--adapter_size 16 \
--num_experts 4 \
--seed 0 \
--inference_level 3 \
--weight_decay 0.1 \
--sharing_up 1 \
--sharing_down 0 \
--use_consistency_loss 1

Most arguments are inherited from transformers and are easy to understand. We further explain some of the AdaMix's arguments:

Evaluate the checkpoints

Create checkpoints directory and download checkpoints of corresponding tasks under the directory. Use MNLI as an example. Use your checkpoint path in expert_soup_path argument.

export num_gpus=1
export PYTHONHASHSEED=0
task_name=mnli
model=roberta-large
export output_dir="./models/${model}/${task_name}"
python -m torch.distributed.launch --nproc_per_node=$num_gpus \
examples/text-classification/run_glue.py \
--model_name_or_path $model \
--task_name $task_name \
--do_eval \
--expert_soup_path ./checkpoints/pytorch_model_${task_name}_expert_soup.bin \
--max_seq_length 128 \
--per_device_train_batch_size 64 \
--per_device_eval_batch_size 32 \
--learning_rate 3e-4 \
--num_train_epochs 20 \
--output_dir $output_dir/model \
--overwrite_output_dir \
--logging_steps 1000 \
--logging_dir $output_dir/log \
--evaluation_strategy epoch \
--save_strategy epoch \
--warmup_ratio 0.06 \
--apply_expert_soup \
--adapter_size 16 \
--num_experts 4 \
--seed 0 \
--inference_level 3 \
--weight_decay 0.1 \
--sharing_up 1 \
--sharing_down 0 \
--use_consistency_loss 1

Notes and Acknowledgments

The implementation is based on https://github.com/huggingface/transformers <br> We also used some code from: https://github.com/microsoft/LoRA

Contact Information

For personal communication related to this package, please contact Yaqing Wang (wang5075@purdue.edu), Sahaj Agarwal (sahagar@microsoft.com), Subhabrata (Subho) Mukherjee (submukhe@microsoft.com) or Xiaodong Liu (xiaodl@microsoft.com).

How do I cite AdaMix?

@article{wang2022adamix,
  title={AdaMix: Mixture-of-Adaptations for Parameter-efficient Model Tuning},
  author={Wang, Yaqing and Agarwal, Sahaj and Mukherjee, Subhabrata and Liu, Xiaodong and Gao, Jing and Awadallah, Ahmed Hassan and Gao, Jianfeng},
  journal={arXiv preprint arXiv:2205.12410},
  year={2022}
}