🚀 基於M-FAC微調的BERT-mini模型
本模型使用最先進的二階優化器M-FAC在SQuAD 2.0數據集上進行了微調。
有關M-FAC的更多詳細信息,請查閱NeurIPS 2021的論文:https://arxiv.org/pdf/2107.03356.pdf。
🚀 快速開始
✨ 微調設置
為了與默認的Adam基線進行公平比較,我們在如下框架中微調模型:https://github.com/huggingface/transformers/tree/master/examples/pytorch/question-answering,並將Adam優化器替換為M-FAC。
M-FAC優化器使用的超參數如下:
learning rate = 1e-4
number of gradients = 1024
dampening = 1e-6
📈 結果
我們分享了5次運行中表現最佳的模型,其在SQuAD 2.0驗證集上的得分如下:
exact_match = 58.38
f1 = 61.65
在SQuAD 2.0驗證集上5次運行的均值和標準差如下:
|
精確匹配率 |
F1值 |
Adam |
54.80 ± 0.47 |
58.13 ± 0.31 |
M-FAC |
58.02 ± 0.39 |
61.35 ± 0.24 |
可以通過在https://github.com/huggingface/transformers/blob/master/examples/pytorch/question-answering/run_qa.py中添加M-FAC優化器代碼,並運行以下bash腳本來複現結果:
CUDA_VISIBLE_DEVICES=0 python run_qa.py \
--seed 8276 \
--model_name_or_path prajjwal1/bert-mini \
--dataset_name squad_v2 \
--version_2_with_negative \
--do_train \
--do_eval \
--per_device_train_batch_size 12 \
--learning_rate 1e-4 \
--num_train_epochs 2 \
--max_seq_length 384 \
--doc_stride 128 \
--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.0和GLUE)上使用了相同的超參數。
📚 相關資源
我們的M-FAC代碼可在以下鏈接找到:https://github.com/IST-DASLab/M-FAC。
關於如何在任何倉庫中集成和使用M-FAC的分步教程可在以下鏈接找到: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}
}