Views
No views yet
Language models only really need to use an exponential fraction of their neurons for individual inferences. As proof, we present UltraFastBERT, a BERT variant that uses 0.3% of its neurons during inference while performing on par with similar BERT models. UltraFastBERT selectively engages just 12 out of 4095 neurons for each layer inference. This is achieved by replacing feedforward networks with fast feedforward networks (FFFs). While no truly efficient implementation currently exists to unlock the full acceleration potential of conditional neural execution, we provide high-level CPU code achieving 78x speedup over the optimized baseline feedforward implementation, and a PyTorch implementation delivering 40x speedup over the equivalent batched feedforward inference. We publish our training code, benchmarking setup, and model weights.
cramming project installed. If, by accident, you use the original cramming repository code instead of the one provided in the /training folder of this project, you will be warned by transformers that there are some extra weights (FFF weight) and that some weights are missing (the FF weights expected by the original crammedBERT).cd ./trainingpip install .minimal_example.py1import cramming
2from transformers import AutoModelForMaskedLM, AutoTokenizer
3
4tokenizer = AutoTokenizer.from_pretrained("pbelcak/UltraFastBERT-1x11-long")
5model = AutoModelForMaskedLM.from_pretrained("pbelcak/UltraFastBERT-1x11-long")
6
7text = "Replace me by any text you'd like."
8encoded_input = tokenizer(text, return_tensors='pt')
9output = model(**encoded_input)python minimal_example.py.| Task | MNLI-(m-mm) | QQP | QNLI | SST-2 | STS-B | MRPC | RTE | Average |
|---|---|---|---|---|---|---|---|---|
| Score | 81.3 | 87.6 | 89.7 | 89.9 | 86.4 | 87.5 | 60.7 | 83.0 |
1@article{belcak2023exponential,
2 title = {Exponentially {{Faster}} {{Language}} {{Modelling}}},
3 author = {Belcak, Peter and Wattenhofer, Roger},
4 year = {2023},
5 month = nov,
6 eprint = {2311.10770},
7 eprinttype = {arxiv},
8 primaryclass = {cs},
9 publisher = {{arXiv}},
10 url = {https://arxiv.org/pdf/2311.10770},
11 urldate = {2023-11-21},
12 archiveprefix = {arXiv},
13 keywords = {Computer Science - Computation and Language,Computer Science - Machine Learning},
14 journal = {arxiv:2311.10770[cs]}
15}