GithubHelp home page GithubHelp logo

test-mass-forker-org-1 / adamix Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/adamix

0.0 0.0 0.0 9.97 MB

This is the implementation of the paper AdaMix: Mixture-of-Adapter for Parameter-efficient Tuning of Large Language Models(https://arxiv.org/abs/2205.12410).

License: Apache License 2.0

Shell 0.24% Python 93.90% Makefile 0.02% Jupyter Notebook 5.78% Dockerfile 0.06% Jsonnet 0.01%

adamix's Introduction

AdaMix (Mixture-of-Adapter)

This is the implementation of the paper AdaMix: Mixture-of-Adapter for Parameter-efficient Tuning of Large Language Models.

Quick links

Overview

Training

Inference

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)

Main Results (RoBERTa-large)

Comparision between Averaging Weights and Random Single Adapter

Download AdaMix checkpoints

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

Dataset BERT base 110M
RoBERTa large 355M
MNLI 8.5 MB 11.7 MB
SST2 8.5 MB 11.7 MB
MRPC 8.5 MB 11.7 MB
CoLA 8.5 MB 11.7 MB
QNLI 8.5 MB 11.7 MB
QQP 8.5 MB 11.7 MB
RTE 8.5 MB 11.7 MB
STSB 8.5 MB 11.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:

  • inference_level: There are two suggested modes

    • 1: Random Routing
    • 3: Averaging the weights of Adapters for routing (used in AdaMix)
  • num_experts: Number of Adapters in AdaMix

  • use_consistency_loss: Two modes.

    • 0: No consistency loss
    • 1: Use consistency loss
  • sharing_up: There are two modes. (sharing_down is same)

    • 0: No weight sharing
    • 1: Sharing Project-up layer weights in Adapter

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
We also used some code from: https://github.com/microsoft/LoRA

Contact Information

For personal communication related to this package, please contact Yaqing Wang ([email protected]), Subhabrata (Subho) Mukherjee ([email protected]) or Xiaodong Liu ([email protected]).

How do I cite AdaMix?

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

adamix's People

Contributors

microsoftopensource avatar subhomj avatar yaqingwang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.