Skip to content

Commit cc45329

Browse files
changwangssyiliu30
authored andcommitted
add examples for GPTJ (#162)
Signed-off-by: Wang, Chang1 <[email protected]> Signed-off-by: yiliu30 <[email protected]>
1 parent 32e7615 commit cc45329

File tree

9 files changed

+894
-0
lines changed

9 files changed

+894
-0
lines changed

.azure-pipelines/scripts/codeScan/pyspelling/lpot_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ Goyal
696696
gpg
697697
GPG
698698
gpt
699+
GPTJ
699700
gpu
700701
gpus
701702
GPUs

examples/.config/model_params_pytorch.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,15 @@
531531
"batch_size": 64,
532532
"new_benchmark": false
533533
},
534+
"gpt_j_wikitext":{
535+
"model_src_dir": "nlp/huggingface_models/language-modeling/quantization/ptq_static/fx",
536+
"dataset_location": "",
537+
"input_model": "/tf_dataset2/models/pytorch/gpt-j-6B",
538+
"yaml": "conf.yaml",
539+
"strategy": "basic",
540+
"batch_size": 8,
541+
"new_benchmark": false
542+
},
534543
"xlm-roberta-base_MRPC": {
535544
"model_src_dir": "nlp/huggingface_models/text-classification/quantization/ptq_static/eager",
536545
"dataset_location": "",

examples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,12 @@ Intel® Neural Compressor validated examples with multiple compression technique
519519
<td>Post-Training Dynamic Quantization</td>
520520
<td><a href="./pytorch/nlp/huggingface_models/summarization/quantization/ptq_dynamic/eager">eager</a></td>
521521
</tr>
522+
<tr>
523+
<td>GPTJ</td>
524+
<td>Natural Language Processing</td>
525+
<td>Post-Training Static Quantization</td>
526+
<td><a href="./pytorch/nlp/huggingface_models/language-modeling/quantization/ptq_static/fx">fx</a></td>
527+
</tr>
522528
</tbody>
523529
</table>
524530

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Step-by-Step
2+
============
3+
4+
This document is used to list steps of reproducing PyTorch BERT tuning zoo result.
5+
6+
# Prerequisite
7+
8+
## 1. Installation
9+
10+
The dependent packages are all in requirements, please install as following.
11+
12+
```
13+
pip install -r requirements.txt
14+
```
15+
16+
## 2. Run
17+
18+
If the automatic download from modelhub fails, you can download [EleutherAI/gpt-j-6B](https://huggingface.co/EleutherAI/gpt-j-6B?text=My+name+is+Clara+and+I+am) offline.
19+
20+
```shell
21+
22+
python run_clm.py \
23+
--model_name_or_path EleutherAI/gpt-j-6B \
24+
--dataset_name wikitext\
25+
--dataset_config_name wikitext-2-raw-v1 \
26+
--do_train \
27+
--do_eval \
28+
--tune \
29+
--output_dir /path/to/checkpoint/dir
30+
```
31+
32+
33+
## 3. Command
34+
35+
```
36+
bash run_tuning.sh --topology=gpt_j_wikitext
37+
bash run_benchmark.sh --topology=gpt_j_wikitext --mode=performance --int8=true
38+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright (c) 2021 Intel Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
version: 1.0
17+
18+
model: # mandatory. used to specify model specific information.
19+
name: bert
20+
framework: pytorch_fx # mandatory. possible values are tensorflow, mxnet, pytorch, pytorch_ipex, onnxrt_integerops and onnxrt_qlinearops.
21+
22+
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
23+
approach: post_training_static_quant
24+
25+
tuning:
26+
accuracy_criterion:
27+
relative: 0.5 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%.
28+
higher_is_better: False
29+
exit_policy:
30+
max_trials: 600
31+
random_seed: 9527 # optional. random seed for deterministic tuning.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sentencepiece != 0.1.92
2+
protobuf
3+
evaluate
4+
datasets
5+
transformers >= 4.22.0
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
set -x
3+
4+
function main {
5+
6+
init_params "$@"
7+
run_benchmark
8+
9+
}
10+
11+
# init params
12+
function init_params {
13+
iters=100
14+
batch_size=16
15+
tuned_checkpoint=saved_results
16+
max_eval_samples=`expr ${iters} \* ${batch_size}`
17+
echo ${max_eval_samples}
18+
for var in "$@"
19+
do
20+
case $var in
21+
--topology=*)
22+
topology=$(echo $var |cut -f2 -d=)
23+
;;
24+
--dataset_location=*)
25+
dataset_location=$(echo $var |cut -f2 -d=)
26+
;;
27+
--input_model=*)
28+
input_model=$(echo $var |cut -f2 -d=)
29+
;;
30+
--mode=*)
31+
mode=$(echo $var |cut -f2 -d=)
32+
;;
33+
--batch_size=*)
34+
batch_size=$(echo $var |cut -f2 -d=)
35+
;;
36+
--iters=*)
37+
iters=$(echo ${var} |cut -f2 -d=)
38+
;;
39+
--int8=*)
40+
int8=$(echo ${var} |cut -f2 -d=)
41+
;;
42+
--config=*)
43+
tuned_checkpoint=$(echo $var |cut -f2 -d=)
44+
;;
45+
*)
46+
echo "Error: No such parameter: ${var}"
47+
exit 1
48+
;;
49+
esac
50+
done
51+
52+
}
53+
54+
55+
# run_benchmark
56+
function run_benchmark {
57+
extra_cmd=''
58+
59+
if [[ ${mode} == "accuracy" ]]; then
60+
mode_cmd=" --accuracy_only "
61+
elif [[ ${mode} == "benchmark" ]]; then
62+
mode_cmd=" --benchmark "
63+
extra_cmd=$extra_cmd" --max_eval_samples ${max_eval_samples}"
64+
else
65+
echo "Error: No such mode: ${mode}"
66+
exit 1
67+
fi
68+
69+
if [ "${topology}" = "gpt_j_wikitext" ]; then
70+
TASK_NAME='wikitext'
71+
model_name_or_path=$input_model
72+
extra_cmd='--dataset_config_name=wikitext-2-raw-v1'
73+
fi
74+
75+
if [[ ${int8} == "true" ]]; then
76+
extra_cmd=$extra_cmd" --int8"
77+
fi
78+
echo $extra_cmd
79+
80+
python -u run_clm.py \
81+
--model_name_or_path ${model_name_or_path} \
82+
--dataset_name ${TASK_NAME} \
83+
--do_eval \
84+
--per_device_eval_batch_size ${batch_size} \
85+
--output_dir ${tuned_checkpoint} \
86+
${mode_cmd} \
87+
${extra_cmd}
88+
89+
}
90+
91+
main "$@"

0 commit comments

Comments
 (0)