Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 32e87d4

Browse files
sxjsciencezheyuye
andauthored
[Numpy] Benchmark the backbone models + Some fixes + Always use python3 + Fix conversion tool (#1292)
* update update Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Create requirements.txt Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update requirements.txt update Update README.md Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py fix fix Update test_models_bart.py Update test_models_bart.py Update bart.py update Update __init__.py Update electra.py update update Update convert_bert_from_tf_hub.sh update Update unittests.yml fix conversion update fix bert conversion update fix fix Update __init__.py fix bug fix css Update benchmark_utils.py Update benchmark_utils.py update update Update misc.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py no multiprocessing Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py fix bug Update benchmark_utils.py Update benchmark_utils.py try to use mxnet profiler Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py fix update Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py fix Update benchmark_utils.py Update bart.py Update bart.py fix fix Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_gluonnlp.py Update benchmark_gluonnlp.py Update benchmark_gluonnlp.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update README.md * Update benchmark_utils.py * Update benchmark_utils.py * Update requirements.txt * Update benchmark_utils.py * Update benchmark_utils.py * Update benchmark_utils.py * Update benchmark_utils.py * Update benchmark_utils.py * Update benchmark_utils.py * debug * Update benchmark_utils.py * Update benchmark_gluonnlp.py * Update benchmark_gluonnlp.py * Update benchmark_utils.py * Update pretraining_utils.py * Update benchmark_utils.py * update * Update benchmark_utils.py * Update benchmark_utils.py * fix convert * tiny fix * python3 * fix * lower tolerance for albert large and xlarge * Update benchmark_utils.py * fix xlmr * lower tolerance for albert large * update * Update benchmark_utils.py * Update benchmark_utils.py * Update benchmark_utils.py * Update benchmark_utils.py * fix * Squashed commit of the following: commit bd05969 Author: ZheyuYe <[email protected]> Date: Tue Aug 11 23:44:53 2020 +0800 lower tolerance for albert large commit f0f9cd6 Author: ZheyuYe <[email protected]> Date: Tue Aug 11 14:59:06 2020 +0800 fix xlmr commit edd6655 Author: ZheyuYe <[email protected]> Date: Tue Aug 11 14:49:36 2020 +0800 lower tolerance for albert large and xlarge commit d651730 Author: ZheyuYe <[email protected]> Date: Tue Aug 11 14:34:55 2020 +0800 fix commit e097c3b Author: ZheyuYe <[email protected]> Date: Tue Aug 11 14:02:13 2020 +0800 python3 commit d6f3fc4 Author: ZheyuYe <[email protected]> Date: Tue Aug 11 14:00:28 2020 +0800 tiny fix commit 93bd659 Author: ZheyuYe <[email protected]> Date: Tue Aug 11 13:08:34 2020 +0800 fix convert commit 9238d56 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 21:03:13 2020 -0700 Update benchmark_utils.py commit 9bbc581 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 12:58:04 2020 -0700 Update benchmark_utils.py commit b1f5955 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 11:18:43 2020 -0700 update commit a43e65b Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 10:32:55 2020 -0700 Update benchmark_utils.py commit 13db82f Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 10:16:46 2020 -0700 Update pretraining_utils.py commit fdd9df5 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 08:49:17 2020 -0700 Update benchmark_utils.py commit 44f9c8b Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 05:07:45 2020 -0700 Update benchmark_gluonnlp.py commit 45c58b6 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 05:06:05 2020 -0700 Update benchmark_gluonnlp.py commit f0ae933 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 05:04:41 2020 -0700 Update benchmark_utils.py commit 9735edb Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:59:58 2020 -0700 debug commit d9daf58 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:57:17 2020 -0700 Update benchmark_utils.py commit 9e0f631 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:56:52 2020 -0700 Update benchmark_utils.py commit 37f224f Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:56:06 2020 -0700 Update benchmark_utils.py commit 1cf5c7b Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:54:34 2020 -0700 Update benchmark_utils.py commit 15272f1 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:49:28 2020 -0700 Update benchmark_utils.py commit 8215df6 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:48:20 2020 -0700 Update benchmark_utils.py commit 1451f03 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:42:21 2020 -0700 Update requirements.txt commit 626739d Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:38:54 2020 -0700 Update benchmark_utils.py commit 1955197 Author: Xingjian Shi <[email protected]> Date: Mon Aug 10 04:31:30 2020 -0700 Update benchmark_utils.py commit 2fd7e3b Author: Xingjian Shi <[email protected]> Date: Thu Aug 6 23:56:49 2020 -0700 update update Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Create requirements.txt Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update requirements.txt update Update README.md Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py Update benchmark_hf.py fix fix Update test_models_bart.py Update test_models_bart.py Update bart.py update Update __init__.py Update electra.py update update Update convert_bert_from_tf_hub.sh update Update unittests.yml fix conversion update fix bert conversion update fix fix Update __init__.py fix bug fix css Update benchmark_utils.py Update benchmark_utils.py update update Update misc.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py no multiprocessing Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py fix bug Update benchmark_utils.py Update benchmark_utils.py try to use mxnet profiler Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py fix update Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py fix Update benchmark_utils.py Update bart.py Update bart.py fix fix Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_gluonnlp.py Update benchmark_gluonnlp.py Update benchmark_gluonnlp.py Update benchmark_utils.py Update benchmark_utils.py Update benchmark_utils.py Update README.md * fix squad * fix typo * Update benchmark_utils.py * Update benchmark_hf.py * Update benchmark_gluonnlp.py * Update benchmark_gluonnlp.py * Update benchmark_gluonnlp.py * Update benchmark_utils.py * Update benchmark_gluonnlp.py * update * Update benchmark_gluonnlp.py * Update benchmark_gluonnlp.py * Update benchmark_gluonnlp.py * Update benchmark_gluonnlp.py * Update README.md * update * Update benchmark_hf.py * Update benchmark_hf.py * Update requirements.txt * Update benchmark_hf.py * Delete conversion_tool_test.yml * Update README.md * Update README.md * Update README.md * move python --> python3 * try to fix test * fix test case * add test cases * Update README.md * update * update logging config * fix logging config Co-authored-by: ZheyuYe <[email protected]>
1 parent 9e268c0 commit 32e87d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2008
-313
lines changed

.github/workflows/unittests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
python -m pip install --user --upgrade pip
3636
python -m pip install --user setuptools pytest pytest-cov contextvars
3737
python -m pip install --upgrade cython
38-
python -m pip install --pre --user "mxnet>=2.0.0b20200716" -f https://dist.mxnet.io/python
38+
python -m pip install --pre --user "mxnet>=2.0.0b20200802" -f https://dist.mxnet.io/python
3939
python -m pip install --user -e .[extras]
4040
- name: Test project
4141
run: |

README.md

+10-13
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,32 @@ First of all, install the latest MXNet. You may use the following commands:
2020

2121
```bash
2222
# Install the version with CUDA 10.0
23-
pip install -U --pre "mxnet-cu100>=2.0.0b20200802" -f https://dist.mxnet.io/python
23+
python3 -m pip install -U --pre "mxnet-cu100>=2.0.0b20200802" -f https://dist.mxnet.io/python
2424

2525
# Install the version with CUDA 10.1
26-
pip install -U --pre "mxnet-cu101>=2.0.0b20200802" -f https://dist.mxnet.io/python
26+
python3 -m pip install -U --pre "mxnet-cu101>=2.0.0b20200802" -f https://dist.mxnet.io/python
2727

2828
# Install the version with CUDA 10.2
29-
pip install -U --pre "mxnet-cu102>=2.0.0b20200802" -f https://dist.mxnet.io/python
29+
python3 -m pip install -U --pre "mxnet-cu102>=2.0.0b20200802" -f https://dist.mxnet.io/python
3030

3131
# Install the cpu-only version
32-
pip install -U --pre "mxnet>=2.0.0b20200802" -f https://dist.mxnet.io/python
32+
python3 -m pip install -U --pre "mxnet>=2.0.0b20200802" -f https://dist.mxnet.io/python
3333
```
3434

3535

36-
To install, use
36+
To install GluonNLP, use
3737

3838
```bash
39-
pip install -U -e .
39+
python3 -m pip install -U -e .
4040

4141
# Also, you may install all the extra requirements via
42-
pip install -U -e .[extras]
43-
44-
# In case you are using zsh, try to use the following command for installing
45-
pip install -U -e ."[extras]"
42+
python3 -m pip install -U -e ."[extras]"
4643
```
4744

4845
If you find that you do not have the permission, you can also install to the user folder:
4946

5047
```bash
51-
pip install -U -e . --user
48+
python3 -m pip install -U -e . --user
5249
```
5350

5451
For Windows users, we recommend to use the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/about).
@@ -68,8 +65,8 @@ nlp_data help
6865
nlp_preprocess help
6966

7067
# Also, you can use `python -m` to access the toolkits
71-
python -m gluonnlp.cli.data help
72-
python -m gluonnlp.cli.preprocess help
68+
python3 -m gluonnlp.cli.data help
69+
python3 -m gluonnlp.cli.preprocess help
7370

7471
```
7572

docs/_static/custom.css

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
}
2121

2222
@media (max-width: 650px) {
23-
.install .option, .install .title {
24-
width: 90%;
25-
}
26-
.install .title {
27-
margin-top: 1em;
23+
.install .option, .install .title {
24+
width: 90%;
25+
}
26+
27+
.install .title {
28+
margin-top: 1em;
29+
}
2830
}

scripts/benchmarks/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Benchmarking the Performance of NLP Backbones
2+
3+
We benchmark the latency and peak memory usage of a single training (forward + backward) and inference (forward-only) step
4+
of the NLP backbones.
5+
For comparison, we also provide the numbers of the models in huggingface.
6+
7+
## Backbones in HuggingFace
8+
9+
We use the [huggingface benchmark](https://github.com/huggingface/transformers/tree/master/examples/benchmarking)
10+
to benchmark the training + inference speed of common workloads in NLP.
11+
12+
```bash
13+
python3 -m pip install -U -r requirements.txt --user
14+
python3 benchmark_hf.py
15+
```
16+
17+
It will generate a list of csv files:
18+
19+
```
20+
├── pytorch_train_fp32.csv
21+
├── pytorch_train_fp16.csv
22+
├── pytorch_infer_fp32.csv
23+
├── pytorch_infer_fp16.csv
24+
├── pytorch_infer_fp32_ts.csv
25+
```
26+
27+
## GluonNLP Backbones based on MXNet-2.0
28+
29+
We profile three options: `NT` layout, `NT` layout with `TN` layout as the compute layout,
30+
and `TN` layout.
31+
32+
```bash
33+
python3 -m pip install -U -r requirements.txt --user
34+
bash benchmark_gluonnlp.sh
35+
```
36+
37+
It will generate csv files with `gluonnlp_` as the prefix
38+
```
39+
├── gluonnlp_train_fp32_NT_NT.csv
40+
├── gluonnlp_train_fp32_NT_TN.csv
41+
├── gluonnlp_train_fp32_TN_TN.csv
42+
├── gluonnlp_infer_fp32_NT_NT.csv
43+
├── gluonnlp_infer_fp32_NT_TN.csv
44+
├── gluonnlp_infer_fp32_TN_TN.csv
45+
```
+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import mxnet as mx
2+
import argparse
3+
import os
4+
import pandas as pd
5+
from benchmark_utils import GluonNLPBackboneBenchmark
6+
import multiprocessing as mp
7+
from multiprocessing import Process
8+
mx.npx.set_np()
9+
10+
11+
MODELS = [
12+
'google_en_uncased_bert_base',
13+
'google_en_uncased_bert_large',
14+
'google_albert_base_v2',
15+
'google_albert_large_v2',
16+
'google_albert_xlarge_v2',
17+
'google_albert_xxlarge_v2',
18+
'google_electra_small',
19+
'google_electra_base',
20+
'google_electra_large',
21+
'google_uncased_mobilebert',
22+
'fairseq_bart_base',
23+
'fairseq_bart_large'
24+
]
25+
26+
# (batch_size, seq_length)
27+
train_workloads =\
28+
[(4, 128),
29+
(8, 128),
30+
(16, 128),
31+
(32, 128),
32+
(1, 512),
33+
(2, 512),
34+
(4, 512),
35+
(8, 512)]
36+
37+
38+
inference_workloads = [
39+
(1, 128),
40+
(1, 384),
41+
(1, 512),
42+
(8, 32),
43+
(8, 128),
44+
(8, 512),
45+
(32, 512),
46+
(256, 128),
47+
(400, 100),
48+
]
49+
50+
51+
def get_parser():
52+
parser = argparse.ArgumentParser(description='Process some integers.')
53+
parser.add_argument('--layout', type=str, default='NT',
54+
help='The layout of the computation')
55+
parser.add_argument('--compute_layout', type=str, default=None,
56+
help='The compute layout of the computation')
57+
parser.add_argument('--mode', type=str, default='train',
58+
choices=['train', 'inference'])
59+
return parser
60+
61+
62+
def run_benchmark(workload, model_name, out_file_name, is_train):
63+
if is_train:
64+
benchmark = GluonNLPBackboneBenchmark(
65+
workloads=workload,
66+
model_names=model_name,
67+
profile_inference=False,
68+
profile_train=True,
69+
to_csv=True,
70+
train_out_csv_file=out_file_name)
71+
benchmark.run()
72+
else:
73+
benchmark = GluonNLPBackboneBenchmark(
74+
workloads=workload,
75+
model_names=model_name,
76+
profile_inference=True,
77+
profile_train=False,
78+
to_csv=True,
79+
inference_out_csv_file=out_file_name)
80+
benchmark.run()
81+
return
82+
83+
84+
if __name__ == '__main__':
85+
mp.set_start_method('spawn')
86+
parser = get_parser()
87+
args = parser.parse_args()
88+
if args.compute_layout is None:
89+
args.compute_layout = args.layout
90+
for layout, compute_layout in [(args.layout, args.compute_layout)]:
91+
if compute_layout != layout:
92+
profile_models = [ele for ele in MODELS if 'bart' not in ele]
93+
else:
94+
profile_models = [ele for ele in MODELS]
95+
if args.mode == 'inference':
96+
out_dir = 'infer_fp32_{}_{}'.format(layout, compute_layout)
97+
df = pd.DataFrame(columns=['model', 'batch_size', 'sequence_length',
98+
'latency', 'memory'])
99+
os.makedirs(out_dir, exist_ok=True)
100+
for model_name in profile_models:
101+
for workload in inference_workloads:
102+
out_path = os.path.join(out_dir, '{}_{}_{}.csv'.format(model_name, workload[0],
103+
workload[1]))
104+
process = Process(
105+
target=run_benchmark,
106+
args=(workload, model_name, out_path, False))
107+
process.start()
108+
process.join()
109+
new_df = pd.read_csv(out_path)
110+
df = df.append(new_df, ignore_index=True)
111+
df.to_csv('gluonnlp_infer_fp32_{}_{}.csv'.format(layout, compute_layout))
112+
elif args.mode == 'train':
113+
out_dir = 'train_fp32_{}_{}'.format(layout, compute_layout)
114+
df = pd.DataFrame(columns=['model', 'batch_size', 'sequence_length',
115+
'latency', 'memory'])
116+
os.makedirs(out_dir, exist_ok=True)
117+
for model_name in profile_models:
118+
for workload in train_workloads:
119+
out_path = os.path.join(out_dir, '{}_{}_{}.csv'.format(model_name, workload[0],
120+
workload[1]))
121+
process = Process(
122+
target=run_benchmark,
123+
args=(workload, model_name, out_path, True))
124+
process.start()
125+
process.join()
126+
new_df = pd.read_csv(out_path)
127+
df = df.append(new_df, ignore_index=True)
128+
df.to_csv('gluonnlp_train_fp32_{}_{}.csv'.format(layout, compute_layout))
129+
else:
130+
raise NotImplementedError
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
for mode in train inference
2+
do
3+
python3 benchmark_gluonnlp.py --layout NT --compute_layout NT --mode $mode
4+
done
5+
6+
for mode in train inference
7+
do
8+
python3 benchmark_gluonnlp.py --layout NT --compute_layout TN --mode $mode
9+
done
10+
11+
for mode in train inference
12+
do
13+
python3 benchmark_gluonnlp.py --layout TN --compute_layout TN --mode $mode
14+
done

0 commit comments

Comments
 (0)