Skip to content

Commit 61c72eb

Browse files
authored
update IPEX example QA to high version transformers (#1131)
1 parent 3fcf2f7 commit 61c72eb

File tree

9 files changed

+1693
-923
lines changed

9 files changed

+1693
-923
lines changed

examples/.config/model_params_pytorch.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@
6464
"new_benchmark": false
6565
},
6666
"bert_large_ipex":{
67+
"model_src_dir": "nlp/huggingface_models/question-answering/quantization/ptq_static/ipex",
68+
"dataset_location": "",
69+
"input_model": "",
70+
"yaml": "conf.yaml",
71+
"strategy": "basic",
72+
"batchsize": 8,
73+
"new_benchmark": false
74+
},
75+
"bert_large_1_10_ipex":{
6776
"model_src_dir": "nlp/huggingface_models/question-answering/quantization/ptq_static/ipex",
6877
"dataset_location": "/tf_dataset/pytorch/squad/dev-v1.1.json",
6978
"input_model": "/tf_dataset/pytorch/bert_large_ipex",

examples/pytorch/nlp/huggingface_models/question-answering/quantization/ptq_static/ipex/README.md

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,55 @@ Follow [link](https://github.com/intel-innersource/frameworks.ai.models.intel-mo
2323

2424
> Note: Intel® Extension for PyTorch* has PyTorch version requirement. Please check more detailed information via the URL below.
2525
26-
- Install transformers and set tag to v3.0.2
26+
27+
## Run
28+
If IPEX version higher than 1.12, please install transformers 4.19.0. We can use the model from huggingface model hub and squad dataset from datasets package, run script `run_qa.py` with command as following.
29+
30+
- Install transformers
31+
```
32+
pip install transformers == 4.19.0
33+
```
34+
- Command
35+
```
36+
python run_qa.py
37+
--model_name_or_path bert-large-uncased-whole-word-masking-finetuned-squad \
38+
--dataset_name squad \
39+
--do_eval \
40+
--max_seq_length 384 \
41+
--doc_stride 128 \
42+
--no_cuda \
43+
--tune \
44+
--output_dir ./savedresult
45+
46+
```
47+
48+
49+
```
50+
bash run_tuning.sh --topology="bert_large_ipex"
51+
```
52+
```
53+
bash run_benchmark.sh --topology="bert_large_ipex" --mode=benchmark
54+
```
55+
56+
If IPEX verison is 1.10 or 1.11, please install transformers 3.0.2, prepare model, dataset and run script `run_qa_1_10.py` command as following.
57+
- install transformers
58+
```
59+
pip install transformers == 3.0.2
2760
```
28-
git clone https://github.com/huggingface/transformers.git
29-
cd transformers
30-
git checkout v3.0.2
31-
pip install -e ./
32-
cd ../
33-
```
3461

3562
- Download dataset
3663
Please following this [link](https://github.com/huggingface/transformers/tree/v3.0.2/examples/question-answering) to get dev-v1.1.json
3764

38-
- Downliad fine-tuned model
65+
- Download fine-tuned model
3966
```
4067
mkdir bert_squad_model
4168
wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-uncased-whole-word-masking-finetuned-squad-config.json -O bert_squad_model/config.json
4269
wget https://cdn.huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad-pytorch_model.bin -O bert_squad_model/pytorch_model.bin
4370
```
4471

45-
46-
## Run
72+
- Command
4773
```
48-
python run_qa.py
74+
python run_qa_1_10.py
4975
--model_type bert
5076
--model_name_or_path ./bert_squad_model/ #finetuned model
5177
--do_lower_case
@@ -61,10 +87,11 @@ Follow [link](https://github.com/intel-innersource/frameworks.ai.models.intel-mo
6187
--int8_fp32
6288
```
6389

64-
## Quick start
6590
```
66-
bash run_tuning.sh --dataset_location=/path/to/dataset --input_model=/path/to/model
91+
bash run_tuning.sh --topology="bert_large_1_10_ipex" --dataset_location=/path/to/dataset --input_model=/path/to/model
6792
```
6893
```
69-
bash run_benchmark.sh --dataset_location=/path/to/dataset --input_model=/path/to/model --mode=benchmark
94+
bash run_benchmark.sh --topology="bert_large_1_10_ipex" --dataset_location=/path/to/dataset --input_model=/path/to/model --mode=benchmark
7095
```
96+
97+
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
accelerate
22
datasets >= 1.8.0
3-
transformers == 3.0.2
3+
transformers == 4.19.0
44
tensorboard

examples/pytorch/nlp/huggingface_models/question-answering/quantization/ptq_static/ipex/run_benchmark.sh

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,35 @@ function run_benchmark {
6565
extra_cmd=$extra_cmd" --int8"
6666
fi
6767
echo $extra_cmd
68-
69-
python run_qa.py \
70-
--model_type bert \
71-
--model_name_or_path $input_model \
72-
--do_lower_case \
73-
--predict_file $dataset_location \
74-
--tokenizer_name $tokenizer_name \
75-
--do_eval \
76-
--max_seq_length 384 \
77-
--doc_stride 128 \
78-
--no_cuda \
79-
--output_dir $tuned_checkpoint \
80-
$mode_cmd \
81-
${extra_cmd}
68+
if [[ "${topology}" == "bert_large_ipex" ]]; then
69+
model_name_or_path="bert-large-uncased-whole-word-masking-finetuned-squad"
70+
python run_qa.py \
71+
--model_name_or_path $model_name_or_path \
72+
--dataset_name squad \
73+
--do_eval \
74+
--max_seq_length 384 \
75+
--no_cuda \
76+
--output_dir $tuned_checkpoint \
77+
$mode_cmd \
78+
${extra_cmd}
79+
fi
80+
if [[ "${topology}" == "bert_large_1_10_ipex" ]]; then
81+
pip install transformers==3.0.2
82+
python run_qa_1_10.py \
83+
--model_type bert \
84+
--model_name_or_path $input_model \
85+
--do_lower_case \
86+
--predict_file $dataset_location \
87+
--tokenizer_name $tokenizer_name \
88+
--do_eval \
89+
--max_seq_length 384 \
90+
--doc_stride 128 \
91+
--no_cuda \
92+
--output_dir $tuned_checkpoint \
93+
$mode_cmd \
94+
${extra_cmd}
95+
fi
8296
}
8397

84-
main "$@"
98+
99+
main "$@"

0 commit comments

Comments
 (0)