🚀 基于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}
}