🚀 基于M - FAC微调的BERT - tiny模型
本模型在STS - B数据集上使用了最先进的二阶优化器M - FAC进行微调。如需了解M - FAC的更多详细信息,请查阅NeurIPS 2021论文:https://arxiv.org/pdf/2107.03356.pdf。
🚀 快速开始
本模型使用M - FAC优化器在STS - B数据集上进行微调,相较于默认的Adam优化器,在性能上有显著提升。
✨ 主要特性
- 使用最先进的二阶优化器M - FAC进行微调。
- 在STS - B验证集上取得了优异的成绩。
- 可以通过简单的代码复现实验结果。
📦 安装指南
文档未提及安装步骤,跳过此章节。
💻 使用示例
基础用法
为了与默认的Adam基线进行公平比较,我们在如下框架中微调模型 https://github.com/huggingface/transformers/tree/master/examples/pytorch/text-classification,并将Adam优化器替换为M - FAC。M - FAC优化器使用的超参数如下:
learning rate = 1e-4
number of gradients = 512
dampening = 1e-6
高级用法
可以通过在 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 7 \
--model_name_or_path prajjwal1/bert-tiny \
--task_name stsb \
--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": 512, "damp": 1e-6}'
我们认为通过适度调整超参数 per_device_train_batch_size
、learning_rate
、num_train_epochs
、num_grads
和 damp
,这些结果还可以进一步提升。为了进行公平比较和设置一个稳健的默认配置,我们在所有模型(bert - tiny
、bert - mini
)和所有数据集(SQuAD版本2和GLUE)上使用了相同的超参数。
📚 详细文档
结果
我们分享了5次运行中表现最佳的模型,其在STS - B验证集上的得分如下:
pearson = 80.66
spearman = 81.13
5次运行在STS - B验证集上的均值和标准差如下:
|
Pearson |
Spearman |
Adam |
64.39 ± 5.02 |
66.52 ± 5.67 |
M - FAC |
80.15 ± 0.52 |
80.62 ± 0.43 |
代码链接
我们的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}
}