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