-
Notifications
You must be signed in to change notification settings - Fork 25.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DeeBERT (entropy-based early exiting for *BERT) #5477
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4a52859
Add readme of deebert
ji-xin 82a6c44
Add deebert code
ji-xin 8af3c00
Add test for deebert
ji-xin f5d859d
Update DeeBert (README, class names, function refactoring); remove re…
ji-xin 808b63d
Format update
ji-xin f9a6cb8
Update test
ji-xin f44de41
Update readme and model init methods
ji-xin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# DeeBERT: Early Exiting for *BERT | ||
|
||
This is the code base for the paper [DeeBERT: Dynamic Early Exiting for Accelerating BERT Inference](https://www.aclweb.org/anthology/2020.acl-main.204/), modified from its [original code base](https://github.com/castorini/deebert). | ||
|
||
The original code base also has information for downloading sample models that we have trained in advance. | ||
|
||
## Usage | ||
|
||
There are three scripts in the folder which can be run directly. | ||
|
||
In each script, there are several things to modify before running: | ||
|
||
* `PATH_TO_DATA`: path to the GLUE dataset. | ||
* `--output_dir`: path for saving fine-tuned models. Default: `./saved_models`. | ||
* `--plot_data_dir`: path for saving evaluation results. Default: `./results`. Results are printed to stdout and also saved to `npy` files in this directory to facilitate plotting figures and further analyses. | ||
* `MODEL_TYPE`: bert or roberta | ||
* `MODEL_SIZE`: base or large | ||
* `DATASET`: SST-2, MRPC, RTE, QNLI, QQP, or MNLI | ||
|
||
#### train_deebert.sh | ||
|
||
This is for fine-tuning DeeBERT models. | ||
|
||
#### eval_deebert.sh | ||
|
||
This is for evaluating each exit layer for fine-tuned DeeBERT models. | ||
|
||
#### entropy_eval.sh | ||
|
||
This is for evaluating fine-tuned DeeBERT models, given a number of different early exit entropy thresholds. | ||
|
||
|
||
|
||
## Citation | ||
|
||
Please cite our paper if you find the resource useful: | ||
``` | ||
@inproceedings{xin-etal-2020-deebert, | ||
title = "{D}ee{BERT}: Dynamic Early Exiting for Accelerating {BERT} Inference", | ||
author = "Xin, Ji and | ||
Tang, Raphael and | ||
Lee, Jaejun and | ||
Yu, Yaoliang and | ||
Lin, Jimmy", | ||
booktitle = "Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics", | ||
month = jul, | ||
year = "2020", | ||
address = "Online", | ||
publisher = "Association for Computational Linguistics", | ||
url = "https://www.aclweb.org/anthology/2020.acl-main.204", | ||
pages = "2246--2251", | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
export CUDA_VISIBLE_DEVICES=0 | ||
|
||
PATH_TO_DATA=/h/xinji/projects/GLUE | ||
|
||
MODEL_TYPE=bert # bert or roberta | ||
MODEL_SIZE=base # base or large | ||
DATASET=MRPC # SST-2, MRPC, RTE, QNLI, QQP, or MNLI | ||
|
||
MODEL_NAME=${MODEL_TYPE}-${MODEL_SIZE} | ||
if [ $MODEL_TYPE = 'bert' ] | ||
then | ||
MODEL_NAME=${MODEL_NAME}-uncased | ||
fi | ||
|
||
ENTROPIES="0 0.1 0.2 0.3 0.4 0.5 0.6 0.7" | ||
|
||
for ENTROPY in $ENTROPIES; do | ||
python -u run_glue_deebert.py \ | ||
--model_type $MODEL_TYPE \ | ||
--model_name_or_path ./saved_models/${MODEL_TYPE}-${MODEL_SIZE}/$DATASET/two_stage \ | ||
--task_name $DATASET \ | ||
--do_eval \ | ||
--do_lower_case \ | ||
--data_dir $PATH_TO_DATA/$DATASET \ | ||
--output_dir ./saved_models/${MODEL_TYPE}-${MODEL_SIZE}/$DATASET/two_stage \ | ||
--plot_data_dir ./results/ \ | ||
--max_seq_length 128 \ | ||
--early_exit_entropy $ENTROPY \ | ||
--eval_highway \ | ||
--overwrite_cache \ | ||
--per_gpu_eval_batch_size=1 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
export CUDA_VISIBLE_DEVICES=0 | ||
|
||
PATH_TO_DATA=/h/xinji/projects/GLUE | ||
|
||
MODEL_TYPE=bert # bert or roberta | ||
MODEL_SIZE=base # base or large | ||
DATASET=MRPC # SST-2, MRPC, RTE, QNLI, QQP, or MNLI | ||
|
||
MODEL_NAME=${MODEL_TYPE}-${MODEL_SIZE} | ||
if [ $MODEL_TYPE = 'bert' ] | ||
then | ||
MODEL_NAME=${MODEL_NAME}-uncased | ||
fi | ||
|
||
|
||
python -u run_glue_deebert.py \ | ||
--model_type $MODEL_TYPE \ | ||
--model_name_or_path ./saved_models/${MODEL_TYPE}-${MODEL_SIZE}/$DATASET/two_stage \ | ||
--task_name $DATASET \ | ||
--do_eval \ | ||
--do_lower_case \ | ||
--data_dir $PATH_TO_DATA/$DATASET \ | ||
--output_dir ./saved_models/${MODEL_TYPE}-${MODEL_SIZE}/$DATASET/two_stage \ | ||
--plot_data_dir ./results/ \ | ||
--max_seq_length 128 \ | ||
--eval_each_highway \ | ||
--eval_highway \ | ||
--overwrite_cache \ | ||
--per_gpu_eval_batch_size=1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to elaborate a little on what variable is what in these scripts?