🚀 基於M - FAC微調的BERT - tiny模型
本模型在SST - 2數據集上使用了先進的二階優化器M - FAC進行微調。有關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次運行中表現最佳的模型,其在SST - 2驗證集上的得分如下:
accuracy = 83.02
在SST - 2驗證集上5次運行的均值和標準差如下:
優化器 |
準確率 |
Adam |
80.11 ± 0.65 |
M - FAC |
81.86 ± 0.76 |
可以通過在[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 42 \
--model_name_or_path prajjwal1/bert-tiny \
--task_name sst2 \
--do_train \
--do_eval \
--max_seq_length 128 \
--per_device_train_batch_size 32 \
--learning_rate 1e-4 \
--num_train_epochs 3 \
--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}
}