This Github respository contains the pre-trained models of MA-BERT models mentioned in the paper MA-BERT: Towards Matrix Arithmetic-only BERT Inference by Eliminating Complex Non-linear Functions. In particular, three pretrained checkpoints are released under the Pretrained Checkpoint section:
- MA-BERT
- MA-BERT (Shared Softmax)
- MA-DistilBERT
In MA-BERT, we proposed four correlated techniques that include:
- Approximating softmax with a two-layer neural network
- Replacing GELU with ReLU
- Fusing normalization layers with adjacent linear layers
- Leveraging knowledge transfer from baseline models
Through these techniques, we were able to eliminate the major non-linear functions in BERT and obtain MA-BERT with only matrix arithmetic and trivial ReLU operations. Our experimental results show that MA-BERT achieves a more efficient inference with comparable accuracy on many downstream tasks compared to the baseline BERT models.
To load MA-BERT and MA-BERT (Shared Softmax):
- Download the
ma-bert
folder and its pretrained checkpoint - Move the folder to the BERT folder in the transformers library:
transformers/models/bert
- Execute the code in loading_example.ipynb
To load MA-DistilBERT:
- Download the
ma-distilbert
folder and its pretrained checkpoint - Move the folder to the DistilBERT folder in the transformers library:
transformers/models/distilbert
- Execute the code in loading_example.ipynb
The following contains the links to our pretrained checkpoints:
Model |
---|
MA-BERT |
MA-BERT (Shared Softmax) |
MA-DistilBERT |
The GLUE benchmark and the IMDb sentiment classification task were used to evaluate MA-BERT.
- val_glue.py
- Example python script for finetuning MA-BERT on GLUE tasks
- val_imdb.py
- Example python script for finetuning MA-BERT on the IMDb sentiment classification task
The following are the required command line arguments:
@inproceedings{
ming2023mabert,
title={{MA}-{BERT}: Towards Matrix Arithmetic-only {BERT} Inference by Eliminating Complex Non-linear Functions},
author={Neo Wei Ming and Zhehui Wang and Cheng Liu and Rick Siow Mong Goh and Tao Luo},
booktitle={International Conference on Learning Representations},
year={2023},
url={https://openreview.net/forum?id=HtAfbHa7LAL}
}