🚀 基於M - FAC微調的BERT - tiny模型
本模型使用了最先進的二階優化器M - FAC在QNLI數據集上進行了微調。
有關M - FAC的更多詳細信息,請查看NeurIPS 2021的論文:https://arxiv.org/pdf/2107.03356.pdf。
🚀 快速開始
微調設置
為了與默認的Adam基線進行公平比較,我們在如下框架中微調模型:[https://github.com/huggingface/transformers/tree/master/examples/pytorch/text - classification](https://github.com/huggingface/transformers/tree/master/examples/pytorch/text - classification),並將Adam優化器替換為M - FAC。
M - FAC優化器使用的超參數如下:
learning rate = 1e-4
number of gradients = 1024
dampening = 1e-6
結果
我們分享了5次運行中表現最佳的模型,其在QNLI驗證集上的得分如下:
accuracy = 81.54
在QNLI驗證集上5次運行的均值和標準差如下:
優化器 |
準確率 |
Adam |
77.85 ± 0.15 |
M - FAC |
81.17 ± 0.43 |
通過在[https://github.com/huggingface/transformers/blob/master/examples/pytorch/text - classification/run_glue.py](https://github.com/huggingface/transformers/blob/master/examples/pytorch/text - classification/run_glue.py)中添加M - FAC優化器代碼,並運行以下bash腳本,可以復現這些結果:
CUDA_VISIBLE_DEVICES=0 python run_glue.py \
--seed 8276 \
--model_name_or_path prajjwal1/bert-tiny \
--task_name qnli \
--do_train \
--do_eval \
--max_seq_length 128 \
--per_device_train_batch_size 32 \
--learning_rate 1e-4 \
--num_train_epochs 5 \
--output_dir out_dir/ \
--optim MFAC \
--optim_args '{"lr": 1e-4, "num_grads": 1024, "damp": 1e-6}'
我們認為,通過適度調整超參數per_device_train_batch_size
、learning_rate
、num_train_epochs
、num_grads
和damp
,這些結果還有提升空間。為了進行公平比較並設置一個穩健的默認配置,我們在所有模型(bert - tiny
、bert - mini
)和所有數據集(SQuAD版本2和GLUE)上使用了相同的超參數。
我們的M - FAC代碼可在此處找到:[https://github.com/IST - DASLab/M - FAC](https://github.com/IST - DASLab/M - FAC)。
關於如何將M - FAC集成到任何倉庫並使用的分步教程可在此處找到:[https://github.com/IST - DASLab/M - FAC/tree/master/tutorials](https://github.com/IST - DASLab/M - FAC/tree/master/tutorials)。
📚 引用信息
@article{frantar2021m,
title={M-FAC: Efficient Matrix-Free Approximations of Second-Order Information},
author={Frantar, Elias and Kurtic, Eldar and Alistarh, Dan},
journal={Advances in Neural Information Processing Systems},
volume={35},
year={2021}
}