Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Wang, Chang1 <chang1.wang@intel.com>
- Loading branch information
1 parent
0346c53
commit 01899d6
Showing
9 changed files
with
894 additions
and
0 deletions.
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 |
---|---|---|
|
@@ -696,6 +696,7 @@ Goyal | |
gpg | ||
GPG | ||
gpt | ||
GPTJ | ||
gpu | ||
gpus | ||
GPUs | ||
|
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
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
38 changes: 38 additions & 0 deletions
38
...h/nlp/huggingface_models/language-modeling/quantization/ptq_static/fx/README.md
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,38 @@ | ||
Step-by-Step | ||
============ | ||
|
||
This document is used to list steps of reproducing PyTorch BERT tuning zoo result. | ||
|
||
# Prerequisite | ||
|
||
## 1. Installation | ||
|
||
The dependent packages are all in requirements, please install as following. | ||
|
||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## 2. Run | ||
|
||
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. | ||
|
||
```shell | ||
|
||
python run_clm.py \ | ||
--model_name_or_path EleutherAI/gpt-j-6B \ | ||
--dataset_name wikitext\ | ||
--dataset_config_name wikitext-2-raw-v1 \ | ||
--do_train \ | ||
--do_eval \ | ||
--tune \ | ||
--output_dir /path/to/checkpoint/dir | ||
``` | ||
|
||
|
||
## 3. Command | ||
|
||
``` | ||
bash run_tuning.sh --topology=gpt_j_wikitext | ||
bash run_benchmark.sh --topology=gpt_j_wikitext --mode=performance --int8=true | ||
``` |
31 changes: 31 additions & 0 deletions
31
...les/pytorch/nlp/huggingface_models/language-modeling/quantization/ptq_static/fx/conf.yaml
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,31 @@ | ||
# | ||
# Copyright (c) 2021 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
version: 1.0 | ||
|
||
model: # mandatory. used to specify model specific information. | ||
name: bert | ||
framework: pytorch_fx # mandatory. possible values are tensorflow, mxnet, pytorch, pytorch_ipex, onnxrt_integerops and onnxrt_qlinearops. | ||
|
||
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space. | ||
approach: post_training_static_quant | ||
|
||
tuning: | ||
accuracy_criterion: | ||
relative: 0.5 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%. | ||
higher_is_better: False | ||
exit_policy: | ||
max_trials: 600 | ||
random_seed: 9527 # optional. random seed for deterministic tuning. |
5 changes: 5 additions & 0 deletions
5
...orch/nlp/huggingface_models/language-modeling/quantization/ptq_static/fx/requirements.txt
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,5 @@ | ||
sentencepiece != 0.1.92 | ||
protobuf | ||
evaluate | ||
datasets | ||
transformers >= 4.22.0 |
91 changes: 91 additions & 0 deletions
91
...orch/nlp/huggingface_models/language-modeling/quantization/ptq_static/fx/run_benchmark.sh
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,91 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
function main { | ||
|
||
init_params "$@" | ||
run_benchmark | ||
|
||
} | ||
|
||
# init params | ||
function init_params { | ||
iters=100 | ||
batch_size=16 | ||
tuned_checkpoint=saved_results | ||
max_eval_samples=`expr ${iters} \* ${batch_size}` | ||
echo ${max_eval_samples} | ||
for var in "$@" | ||
do | ||
case $var in | ||
--topology=*) | ||
topology=$(echo $var |cut -f2 -d=) | ||
;; | ||
--dataset_location=*) | ||
dataset_location=$(echo $var |cut -f2 -d=) | ||
;; | ||
--input_model=*) | ||
input_model=$(echo $var |cut -f2 -d=) | ||
;; | ||
--mode=*) | ||
mode=$(echo $var |cut -f2 -d=) | ||
;; | ||
--batch_size=*) | ||
batch_size=$(echo $var |cut -f2 -d=) | ||
;; | ||
--iters=*) | ||
iters=$(echo ${var} |cut -f2 -d=) | ||
;; | ||
--int8=*) | ||
int8=$(echo ${var} |cut -f2 -d=) | ||
;; | ||
--config=*) | ||
tuned_checkpoint=$(echo $var |cut -f2 -d=) | ||
;; | ||
*) | ||
echo "Error: No such parameter: ${var}" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
} | ||
|
||
|
||
# run_benchmark | ||
function run_benchmark { | ||
extra_cmd='' | ||
|
||
if [[ ${mode} == "accuracy" ]]; then | ||
mode_cmd=" --accuracy_only " | ||
elif [[ ${mode} == "benchmark" ]]; then | ||
mode_cmd=" --benchmark " | ||
extra_cmd=$extra_cmd" --max_eval_samples ${max_eval_samples}" | ||
else | ||
echo "Error: No such mode: ${mode}" | ||
exit 1 | ||
fi | ||
|
||
if [ "${topology}" = "gpt_j_wikitext" ]; then | ||
TASK_NAME='wikitext' | ||
model_name_or_path=$input_model | ||
extra_cmd='--dataset_config_name=wikitext-2-raw-v1' | ||
fi | ||
|
||
if [[ ${int8} == "true" ]]; then | ||
extra_cmd=$extra_cmd" --int8" | ||
fi | ||
echo $extra_cmd | ||
|
||
python -u run_clm.py \ | ||
--model_name_or_path ${model_name_or_path} \ | ||
--dataset_name ${TASK_NAME} \ | ||
--do_eval \ | ||
--per_device_eval_batch_size ${batch_size} \ | ||
--output_dir ${tuned_checkpoint} \ | ||
${mode_cmd} \ | ||
${extra_cmd} | ||
|
||
} | ||
|
||
main "$@" |
Oops, something went wrong.